mFluid.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. class Fluid
  34. {
  35. protected:
  36. F32 mAnimationProgress; //a time value between 0 and 1
  37. S32 mAnimationLength; //Length of the currently playing animation in milliseconds.
  38. EasingFunction mEasingFunction;
  39. public:
  40. Fluid();
  41. ~Fluid();
  42. inline S32 getAnimationLength() { return mAnimationLength; }
  43. inline void setAnimationLength(S32 time) { mAnimationLength = time; }
  44. inline EasingFunction getEasingFunction() { return mEasingFunction; }
  45. inline void setEasingFunction(EasingFunction ease) { mEasingFunction = ease; }
  46. void setEasingFunction(const char* label);
  47. const char* getEasingFunctionDescription(const EasingFunction ease);
  48. virtual void startFluidAnimation(); //starts an animation.
  49. inline void stopFluidAnimation() { mAnimationProgress = 1.0f; }
  50. inline bool isAnimating() { return mAnimationProgress < 1.0f; }
  51. F32 getProgress(const S32 time); //Returns the progress to the target with 0 as starting and 1 as the target.
  52. inline U8 processValue(const F32 progress, const U8 start, const U8 target) { return start + (U8)mRound((target - start) * progress); };
  53. inline S32 processValue(const F32 progress, const S32 start, const S32 target) { return start + (S32)mRound((target - start) * progress); };
  54. inline F32 processValue(const F32 progress, const F32 start, const F32 target) { return start + ((target - start) * progress); };
  55. };
  56. class FluidColorI : public ColorI, public Fluid
  57. {
  58. protected:
  59. U8 redStart;
  60. U8 greenStart;
  61. U8 blueStart;
  62. U8 alphaStart;
  63. U8 redTarget;
  64. U8 greenTarget;
  65. U8 blueTarget;
  66. U8 alphaTarget;
  67. public:
  68. virtual void startFluidAnimation(const ColorI &color);
  69. virtual bool processTick(); //Returns true if we should continue to processTicks
  70. void set(const ColorI& in_rCopy);
  71. };
  72. #endif // _MFLUID_H_