mFluid.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MFLUID_H_
  23. #define _MFLUID_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _MMATHFN_H_
  28. #include "math/mMathFn.h"
  29. #endif
  30. #ifndef _COLOR_H_
  31. #include "graphics/gColor.h"
  32. #endif
  33. DefineConsoleType(TypeFluidColorI)
  34. class Fluid
  35. {
  36. protected:
  37. F32 mAnimationProgress; //a time value between 0 and 1
  38. S32 mAnimationLength; //Length of the currently playing animation in milliseconds.
  39. EasingFunction mEasingFunction;
  40. public:
  41. Fluid();
  42. ~Fluid();
  43. inline S32 getAnimationLength() { return mAnimationLength; }
  44. inline void setAnimationLength(S32 time) { mAnimationLength = time; }
  45. inline EasingFunction getEasingFunction() { return mEasingFunction; }
  46. inline void setEasingFunction(EasingFunction ease) { mEasingFunction = ease; }
  47. void setEasingFunction(const char* label);
  48. const char* getEasingFunctionDescription(const EasingFunction ease);
  49. virtual void startFluidAnimation(); //starts an animation.
  50. inline void stopFluidAnimation() { mAnimationProgress = 1.0f; }
  51. inline bool isAnimating() { return mAnimationProgress < 1.0f; }
  52. F32 getProgress(const S32 time); //Returns the progress to the target with 0 as starting and 1 as the target.
  53. inline U8 processValue(const F32 progress, const U8 start, const U8 target) { return start + (U8)mRound((target - start) * progress); };
  54. inline S32 processValue(const F32 progress, const S32 start, const S32 target) { return start + (S32)mRound((target - start) * progress); };
  55. inline F32 processValue(const F32 progress, const F32 start, const F32 target) { return start + ((target - start) * progress); };
  56. };
  57. class FluidColorI : public ColorI, public Fluid
  58. {
  59. protected:
  60. U8 redStart;
  61. U8 greenStart;
  62. U8 blueStart;
  63. U8 alphaStart;
  64. U8 redTarget;
  65. U8 greenTarget;
  66. U8 blueTarget;
  67. U8 alphaTarget;
  68. public:
  69. FluidColorI() { }
  70. FluidColorI(ColorI &color);
  71. FluidColorI(const U8 in_r,
  72. const U8 in_g,
  73. const U8 in_b,
  74. const U8 in_a = U8(255)) : ColorI(in_r, in_g, in_b, in_a) { };
  75. virtual void startFluidAnimation(const ColorI &color);
  76. virtual bool processTick(); //Returns true if we should continue to processTicks
  77. void set(const ColorI& in_rCopy);
  78. void set(U8 red, U8 green, U8 blue, U8 alpha = 255);
  79. };
  80. #endif // _MFLUID_H_