CFadeAnimation.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "../../lib/GameConstants.h"
  12. #ifdef IN
  13. #undef IN
  14. #endif
  15. #ifdef OUT
  16. #undef OUT
  17. #endif
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. class JsonNode;
  20. class Rect;
  21. class Point;
  22. VCMI_LIB_NAMESPACE_END
  23. struct SDL_Surface;
  24. struct SDL_Color;
  25. class CDefFile;
  26. class ColorFilter;
  27. const float DEFAULT_DELTA = 0.05f;
  28. class CFadeAnimation
  29. {
  30. public:
  31. enum class EMode
  32. {
  33. NONE, IN, OUT
  34. };
  35. private:
  36. float delta;
  37. SDL_Surface * fadingSurface;
  38. bool fading;
  39. float fadingCounter;
  40. bool shouldFreeSurface;
  41. float initialCounter() const;
  42. bool isFinished() const;
  43. public:
  44. EMode fadingMode;
  45. CFadeAnimation();
  46. ~CFadeAnimation();
  47. void init(EMode mode, SDL_Surface * sourceSurface, bool freeSurfaceAtEnd = false, float animDelta = DEFAULT_DELTA);
  48. void update();
  49. void draw(SDL_Surface * targetSurface, const Point & targetPoint);
  50. bool isFading() const { return fading; }
  51. };