CFadeAnimation.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * CFadeAnimation.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #ifdef IN
  12. #undef IN
  13. #endif
  14. #ifdef OUT
  15. #undef OUT
  16. #endif
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class Point;
  19. VCMI_LIB_NAMESPACE_END
  20. struct SDL_Surface;
  21. const float DEFAULT_DELTA = 0.05f;
  22. class CFadeAnimation
  23. {
  24. public:
  25. enum class EMode
  26. {
  27. NONE, IN, OUT
  28. };
  29. private:
  30. float delta;
  31. SDL_Surface * fadingSurface;
  32. bool fading;
  33. float fadingCounter;
  34. bool shouldFreeSurface;
  35. float initialCounter() const;
  36. bool isFinished() const;
  37. public:
  38. EMode fadingMode;
  39. CFadeAnimation();
  40. ~CFadeAnimation();
  41. void init(EMode mode, SDL_Surface * sourceSurface, bool freeSurfaceAtEnd = false, float animDelta = DEFAULT_DELTA);
  42. void update();
  43. void draw(SDL_Surface * targetSurface, const Point & targetPoint);
  44. bool isFading() const { return fading; }
  45. };