Animation.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef Animation_H
  2. #define Animation_H
  3. #include "Critical.h"
  4. #include "Drawing.h"
  5. namespace Framework
  6. {
  7. class Image; //! Image.h
  8. class LTDBFile; //! FileSystem.h
  9. class InitFile; //! InitFile.h
  10. class Border; //! Border.h
  11. //! Contains all images of a video animation
  12. class Animation2DData : public virtual ReferenceCounter
  13. {
  14. private:
  15. Image** bilder;
  16. int imageCount;
  17. int fps;
  18. bool repeat;
  19. bool transparent;
  20. ReadWriteLock rwLock;
  21. public:
  22. //! Constructor
  23. DLLEXPORT Animation2DData();
  24. //! Destructor
  25. DLLEXPORT ~Animation2DData();
  26. //! returns a lock for reading the animation data.
  27. DLLEXPORT Lock& readLock();
  28. //! returns a lock for writing the animation data.
  29. DLLEXPORT Lock& writeLock();
  30. //! Loads all images from an InitFile. The values 'fps',
  31. //! 'repeat' (true, false), 'transparent' (true, false) are also
  32. //! interpreted. The images must be in the correct order in the file.
  33. //! The name of the values does not matter, the value is the path to
  34. //! the ltdb file with /imagename appended. Example: fps=30
  35. //! x=a.ltdb\aaaa.jpg
  36. //! y=a.ltdb\aaab.jpg
  37. //! \param datei The already loaded InitFile
  38. DLLEXPORT void loadAnimation(InitFile* datei);
  39. //! Loads all images from an LTDB file in the order they are stored.
  40. //! \param datei The LTDB file
  41. DLLEXPORT void loadAnimation(LTDBFile* datei);
  42. //! Sets the frames per second of the video animation
  43. //! \param fps The number of frames per second
  44. DLLEXPORT void setFPS(int fps);
  45. //! Sets whether the animation repeats when it reaches the end
  46. //! \param wh 1 if the animation should repeat
  47. DLLEXPORT void setWiederhohlend(bool wh);
  48. //! Sets whether alpha blending should be used when drawing the images
  49. //! \param trp 1 if alpha blending should be used
  50. DLLEXPORT void setTransparent(bool trp);
  51. //! Deletes all images from the animation and resets all values to
  52. //! their defaults
  53. DLLEXPORT void reset();
  54. //! Returns a specific image of the animation
  55. //! \param i The index of the image
  56. DLLEXPORT Image* getImage(int i) const;
  57. //! Returns a specific image of the animation without increasing the
  58. //! reference counter
  59. //! \param i The index of the image
  60. DLLEXPORT Image* zImage(int i) const;
  61. //! Returns the number of images in the animation
  62. DLLEXPORT int getImageCount() const;
  63. //! Returns the number of frames per second
  64. DLLEXPORT int getFPS() const;
  65. //! Returns whether the animation repeats when it reaches the last
  66. //! image
  67. DLLEXPORT bool isRepeating() const;
  68. //! Returns whether alpha blending is used when drawing the images
  69. DLLEXPORT bool isTransparent() const;
  70. };
  71. //! A drawing that renders a video animation
  72. class Animation2D : public Drawable
  73. {
  74. private:
  75. Animation2DData* data;
  76. int now;
  77. double compensation;
  78. unsigned char alpha;
  79. unsigned char maxAlpha;
  80. bool border;
  81. Border* ram;
  82. int aps;
  83. bool visible;
  84. public:
  85. //! Constructor
  86. DLLEXPORT Animation2D();
  87. //! Destructor
  88. DLLEXPORT virtual ~Animation2D();
  89. //! Sets whether a border should be drawn around the animation
  90. //! \param ram 1 if a border should be drawn
  91. DLLEXPORT void setBorder(bool ram);
  92. //! Sets a pointer to the used border
  93. //! \param ram The border
  94. DLLEXPORT void setBorderZ(Border* ram);
  95. //! Sets the width of the border
  96. //! \param br The width in pixels
  97. DLLEXPORT void setBorderWidth(int br);
  98. //! Sets the color of the border
  99. //! \param fc The color in A8R8G8B8 format
  100. DLLEXPORT void setBorderColor(int fc);
  101. //! Sets the animation to be displayed
  102. //! \param data The animation data
  103. DLLEXPORT void setAnimationDataZ(Animation2DData* data);
  104. //! Sets the transparency of the entire animation
  105. //! \param alpha The transparency
  106. DLLEXPORT void setAlphaMaske(unsigned char alpha);
  107. //! Sets the speed at which the animation fades in and out
  108. //! \param aps Alpha per second
  109. DLLEXPORT void setAPS(int aps);
  110. //! Sets the visibility of the animation
  111. //! \param visible 1 if the animation should be shown, 0 if it should
  112. //! be hidden
  113. DLLEXPORT void setVisible(bool visible);
  114. //! Processes the time that has passed since the last call of this
  115. //! function
  116. //! \param zeit The elapsed time in seconds
  117. DLLEXPORT bool tick(double zeit) override;
  118. //! Draws the animation into a specific image
  119. //! \param zRObj The image to draw into
  120. DLLEXPORT void render(Image& zRObj) override;
  121. //! Returns the animation data
  122. DLLEXPORT Animation2DData* getAnimationData() const;
  123. //! Returns the animation data without increasing the reference counter
  124. DLLEXPORT Animation2DData* zAnimationData() const;
  125. //! Returns whether the animation is visible
  126. DLLEXPORT bool isVisible() const;
  127. //! Returns the index of the currently displayed image
  128. DLLEXPORT int getJetzt() const;
  129. //! Returns the transparency of the animation
  130. DLLEXPORT unsigned char getAlphaMaske() const;
  131. //! Returns whether a border is drawn around the animation
  132. DLLEXPORT bool hasBorder() const;
  133. //! Returns the border of the animation
  134. DLLEXPORT Border* getBorder() const;
  135. //! Returns the border of the animation without increasing the
  136. //! reference counter
  137. DLLEXPORT Border* zBorder() const;
  138. //! Returns the width of the border in pixels
  139. DLLEXPORT int getBorderWidth() const;
  140. //! Returns the color of the border in A8R8G8B8 format
  141. DLLEXPORT int getBorderColor() const;
  142. //! Copies the animation so that it can be modified without
  143. //! affecting the original
  144. DLLEXPORT Drawable* duplicate() const override;
  145. };
  146. } // namespace Framework
  147. #endif