animate.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: animate.h
  3. // Purpose: interface of wxAnimation* classes
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Supported animation types.
  9. */
  10. enum wxAnimationType
  11. {
  12. wxANIMATION_TYPE_INVALID,
  13. /** represents an animated GIF file. */
  14. wxANIMATION_TYPE_GIF,
  15. /** represents an ANI file. */
  16. wxANIMATION_TYPE_ANI,
  17. /** autodetect the filetype. */
  18. wxANIMATION_TYPE_ANY
  19. };
  20. #define wxAC_NO_AUTORESIZE (0x0010)
  21. #define wxAC_DEFAULT_STYLE (wxBORDER_NONE)
  22. /**
  23. @class wxAnimationCtrl
  24. This is a static control which displays an animation.
  25. wxAnimationCtrl API is as simple as possible and won't give you full control
  26. on the animation; if you need it then use wxMediaCtrl.
  27. This control is useful to display a (small) animation while doing a long task
  28. (e.g. a "throbber").
  29. It is only available if @c wxUSE_ANIMATIONCTRL is set to 1 (the default).
  30. @beginStyleTable
  31. @style{wxAC_DEFAULT_STYLE}
  32. The default style: wxBORDER_NONE.
  33. @style{wxAC_NO_AUTORESIZE}
  34. By default, the control will adjust its size to exactly fit to the
  35. size of the animation when SetAnimation is called. If this style
  36. flag is given, the control will not change its size
  37. @endStyleTable
  38. @library{wxadv}
  39. @category{ctrl}
  40. @nativeimpl{wxgtk,wxmsw}
  41. @appearance{animationctrl}
  42. @see wxAnimation, @sample{animate}
  43. */
  44. class wxAnimationCtrl : public wxControl
  45. {
  46. public:
  47. /**
  48. Initializes the object and calls Create() with
  49. all the parameters.
  50. */
  51. wxAnimationCtrl(wxWindow* parent, wxWindowID id,
  52. const wxAnimation& anim = wxNullAnimation,
  53. const wxPoint& pos = wxDefaultPosition,
  54. const wxSize& size = wxDefaultSize,
  55. long style = wxAC_DEFAULT_STYLE,
  56. const wxString& name = wxAnimationCtrlNameStr);
  57. /**
  58. Creates the control with the given @a anim animation.
  59. After control creation you must explicitly call Play() to start to play
  60. the animation. Until that function won't be called, the first frame
  61. of the animation is displayed.
  62. @param parent
  63. Parent window, must be non-@NULL.
  64. @param id
  65. The identifier for the control.
  66. @param anim
  67. The initial animation shown in the control.
  68. @param pos
  69. Initial position.
  70. @param size
  71. Initial size.
  72. @param style
  73. The window style, see wxAC_* flags.
  74. @param name
  75. Control name.
  76. @return @true if the control was successfully created or @false if
  77. creation failed.
  78. */
  79. bool Create(wxWindow* parent, wxWindowID id,
  80. const wxAnimation& anim = wxNullAnimation,
  81. const wxPoint& pos = wxDefaultPosition,
  82. const wxSize& size = wxDefaultSize,
  83. long style = wxAC_DEFAULT_STYLE,
  84. const wxString& name = wxAnimationCtrlNameStr);
  85. /**
  86. Returns the animation associated with this control.
  87. */
  88. virtual wxAnimation GetAnimation() const;
  89. /**
  90. Returns the inactive bitmap shown in this control when the;
  91. see SetInactiveBitmap() for more info.
  92. */
  93. wxBitmap GetInactiveBitmap() const;
  94. /**
  95. Returns @true if the animation is being played.
  96. */
  97. virtual bool IsPlaying() const;
  98. /**
  99. Loads the animation from the given file and calls SetAnimation().
  100. See wxAnimation::LoadFile for more info.
  101. */
  102. virtual bool LoadFile(const wxString& file,
  103. wxAnimationType animType = wxANIMATION_TYPE_ANY);
  104. /**
  105. Loads the animation from the given stream and calls SetAnimation().
  106. See wxAnimation::Load() for more info.
  107. */
  108. virtual bool Load(wxInputStream& file,
  109. wxAnimationType animType = wxANIMATION_TYPE_ANY);
  110. /**
  111. Starts playing the animation.
  112. The animation is always played in loop mode (unless the last frame of the
  113. animation has an infinite delay time) and always start from the first frame
  114. even if you @ref Stop "stopped" it while some other frame was displayed.
  115. */
  116. virtual bool Play();
  117. /**
  118. Sets the animation to play in this control.
  119. If the previous animation is being played, it's @ref Stop() stopped.
  120. Until Play() isn't called, a static image, the first frame of the given
  121. animation or the background colour will be shown
  122. (see SetInactiveBitmap() for more info).
  123. */
  124. virtual void SetAnimation(const wxAnimation& anim);
  125. /**
  126. Sets the bitmap to show on the control when it's not playing an animation.
  127. If you set as inactive bitmap ::wxNullBitmap (which is the default), then the
  128. first frame of the animation is instead shown when the control is inactive;
  129. in this case, if there's no valid animation associated with the control
  130. (see SetAnimation()), then the background colour of the window is shown.
  131. If the control is not playing the animation, the given bitmap will be
  132. immediately shown, otherwise it will be shown as soon as Stop() is called.
  133. Note that the inactive bitmap, if smaller than the control's size, will be
  134. centered in the control; if bigger, it will be stretched to fit it.
  135. */
  136. virtual void SetInactiveBitmap(const wxBitmap& bmp);
  137. /**
  138. Stops playing the animation.
  139. The control will show the first frame of the animation, a custom static image or
  140. the window's background colour as specified by the last SetInactiveBitmap() call.
  141. */
  142. virtual void Stop();
  143. };
  144. /**
  145. @class wxAnimation
  146. This class encapsulates the concept of a platform-dependent animation.
  147. An animation is a sequence of frames of the same size.
  148. Sound is not supported by wxAnimation.
  149. Note that on wxGTK wxAnimation is capable of loading the formats supported
  150. by the internally-used @c gdk-pixbuf library (typically this means only
  151. @c wxANIMATION_TYPE_GIF).
  152. On other platforms wxAnimation is always capable of loading both GIF and ANI
  153. formats (i.e. both @c wxANIMATION_TYPE_GIF and @c wxANIMATION_TYPE_ANI).
  154. @library{wxadv}
  155. @category{gdi}
  156. @stdobjects
  157. ::wxNullAnimation
  158. @see wxAnimationCtrl, @sample{animate}
  159. */
  160. class wxAnimation : public wxObject
  161. {
  162. public:
  163. /**
  164. Default ctor.
  165. */
  166. wxAnimation();
  167. /**
  168. Copy ctor.
  169. */
  170. wxAnimation(const wxAnimation& anim);
  171. /**
  172. Loads an animation from a file.
  173. @param name
  174. The name of the file to load.
  175. @param type
  176. See LoadFile() for more info.
  177. */
  178. wxAnimation(const wxString& name,
  179. wxAnimationType type = wxANIMATION_TYPE_ANY);
  180. /**
  181. Destructor.
  182. See @ref overview_refcount_destruct for more info.
  183. */
  184. virtual ~wxAnimation();
  185. /**
  186. Returns the delay for the i-th frame in milliseconds.
  187. If @c -1 is returned the frame is to be displayed forever.
  188. */
  189. virtual int GetDelay(unsigned int i) const;
  190. /**
  191. Returns the i-th frame as a wxImage.
  192. This method is not implemented in the native wxGTK implementation of
  193. this class and always returns an invalid image there.
  194. */
  195. virtual wxImage GetFrame(unsigned int i) const;
  196. /**
  197. Returns the number of frames for this animation.
  198. This method is not implemented in the native wxGTK implementation of
  199. this class and always returns 0 there.
  200. */
  201. virtual unsigned int GetFrameCount() const;
  202. /**
  203. Returns the size of the animation.
  204. */
  205. virtual wxSize GetSize() const;
  206. /**
  207. Returns @true if animation data is present.
  208. */
  209. virtual bool IsOk() const;
  210. /**
  211. Loads an animation from the given stream.
  212. @param stream
  213. The stream to use to load the animation.
  214. Under wxGTK may be any kind of stream; under other platforms
  215. this must be a seekable stream.
  216. @param type
  217. One of the ::wxAnimationType enumeration values.
  218. @return @true if the operation succeeded, @false otherwise.
  219. */
  220. virtual bool Load(wxInputStream& stream,
  221. wxAnimationType type = wxANIMATION_TYPE_ANY);
  222. /**
  223. Loads an animation from a file.
  224. @param name
  225. A filename.
  226. @param type
  227. One of the ::wxAnimationType values; wxANIMATION_TYPE_ANY
  228. means that the function should try to autodetect the filetype.
  229. @return @true if the operation succeeded, @false otherwise.
  230. */
  231. virtual bool LoadFile(const wxString& name,
  232. wxAnimationType type = wxANIMATION_TYPE_ANY);
  233. /**
  234. Assignment operator, using @ref overview_refcount "reference counting".
  235. */
  236. wxAnimation& operator =(const wxAnimation& brush);
  237. };
  238. // ============================================================================
  239. // Global functions/macros
  240. // ============================================================================
  241. /**
  242. An empty animation object.
  243. */
  244. wxAnimation wxNullAnimation;