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