]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/animate/animate.i
Assert correction.
[wxWidgets.git] / wxPython / contrib / animate / animate.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: animate.i
3 // Purpose: Wrappers for the animation classes in wx/contrib
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 4-April-2005
8 // RCS-ID: $Id$
9 // Copyright: (c) 2005 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
14 "Simple animation player classes, including `GIFAnimationCtrl` for displaying
15 animated GIF files
16 "
17 %enddef
18
19 %module(package="wx", docstring=DOCSTRING) animate
20
21
22 %{
23 #include "wx/wxPython/wxPython.h"
24 #include "wx/wxPython/pyclasses.h"
25 #include <wx/animate/animate.h>
26 %}
27
28 //---------------------------------------------------------------------------
29
30 %import core.i
31 %pythoncode { import wx }
32 %pythoncode { __docfilter__ = wx._core.__DocFilter(globals()) }
33
34
35 MAKE_CONST_WXSTRING2(AnimationControlNameStr, wxT("animationControl"));
36 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
37
38 %include _animate_rename.i
39
40 //---------------------------------------------------------------------------
41
42
43 enum wxAnimationDisposal
44 {
45 wxANIM_UNSPECIFIED = -1,
46 wxANIM_DONOTREMOVE = 0,
47 wxANIM_TOBACKGROUND = 1,
48 wxANIM_TOPREVIOUS = 2
49 } ;
50
51
52 /* wxAnimationPlayer
53 * Create an object of this class, and either pass an wxXXXAnimation object in
54 * the constructor, or call SetAnimation. Then call Play(). The wxAnimation
55 * object is only destroyed in the destructor if destroyAnimation is true in
56 * the constructor.
57 */
58
59 class wxAnimationPlayer : public wxObject
60 {
61 public:
62 wxAnimationPlayer(wxAnimationBase *animation = NULL,
63 bool destroyAnimation = false);
64 ~wxAnimationPlayer();
65
66
67 void SetAnimation(wxAnimationBase* animation, bool destroyAnimation = false);
68 wxAnimationBase* GetAnimation() const;
69
70 void SetDestroyAnimation(bool destroyAnimation);
71 bool GetDestroyAnimation() const;
72
73 void SetCurrentFrame(int currentFrame);
74 int GetCurrentFrame() const;
75
76 void SetWindow(wxWindow* window);
77 wxWindow* GetWindow() const;
78
79 void SetPosition(const wxPoint& pos);
80 wxPoint GetPosition() const;
81
82 void SetLooped(bool looped);
83 bool GetLooped() const;
84
85 bool HasAnimation() const;
86
87 bool IsPlaying() const;
88
89 // Specify whether the GIF's background colour is to be shown,
90 // or whether the window background should show through (the default)
91 void UseBackgroundColour(bool useBackground);
92 bool UsingBackgroundColour() const;
93
94 // Set and use a user-specified background colour (valid for transparent
95 // animations only)
96 void SetCustomBackgroundColour(const wxColour& col,
97 bool useCustomBackgroundColour = true);
98
99 bool UsingCustomBackgroundColour() const;
100 const wxColour& GetCustomBackgroundColour() const;
101
102 // Another refinement - suppose we're drawing the animation in a separate
103 // control or window. We may wish to use the background of the parent
104 // window as the background of our animation. This allows us to specify
105 // whether to grab from the parent or from this window.
106 void UseParentBackground(bool useParent);
107 bool UsingParentBackground() const;
108
109
110 // Play
111 virtual bool Play(wxWindow& window, const wxPoint& pos = wxPoint(0, 0), bool looped = true);
112
113 // Build animation (list of wxImages). If not called before Play
114 // is called, Play will call this automatically.
115 virtual bool Build();
116
117 // Stop the animation
118 virtual void Stop();
119
120 // Draw the current view of the animation into this DC.
121 // Call this from your OnPaint, for example.
122 virtual void Draw(wxDC& dc);
123
124
125 virtual int GetFrameCount() const;
126 %newobject GetFrame;
127 virtual wxImage* GetFrame(int i) const; // Creates a new wxImage
128 virtual wxAnimationDisposal GetDisposalMethod(int i) const;
129 virtual wxRect GetFrameRect(int i) const; // Position and size of frame
130 virtual int GetDelay(int i) const; // Delay for this frame
131
132 virtual wxSize GetLogicalScreenSize() const;
133 virtual bool GetBackgroundColour(wxColour& col) const ;
134 virtual bool GetTransparentColour(wxColour& col) const ;
135
136
137 // Play the frame
138 virtual bool PlayFrame(int frame, wxWindow& window, const wxPoint& pos);
139 %Rename(PlayNextFrame,
140 virtual bool, PlayFrame());
141
142 virtual void DrawFrame(int frame, wxDC& dc, const wxPoint& pos);
143 virtual void DrawBackground(wxDC& dc, const wxPoint& pos, const wxColour& colour);
144
145 // Clear the wxImage cache
146 virtual void ClearCache();
147
148 // Save the pertinent area of the window so we can restore
149 // it if drawing transparently
150 void SaveBackground(const wxRect& rect);
151
152 wxBitmap& GetBackingStore();
153
154 };
155
156
157 //---------------------------------------------------------------------------
158
159 /* wxAnimationBase
160 * Base class for animations.
161 * A wxXXXAnimation only stores the animation, providing accessors to
162 * wxAnimationPlayer. Currently an animation is read-only, but we could
163 * extend the API for adding frames programmatically, and perhaps have a
164 * wxMemoryAnimation class that stores its frames in memory, and is able to
165 * save all files with suitable filenames. You could then use e.g. Ulead GIF
166 * Animator to load the image files into a GIF animation.
167 */
168
169 class wxAnimationBase : public wxObject
170 {
171 public:
172 //wxAnimationBase() {}; // It's an ABC
173 ~wxAnimationBase() {};
174
175 //// Accessors. Should be overridden by each derived class.
176
177 virtual int GetFrameCount() const;
178 %newobject GetFrame;
179 virtual wxImage* GetFrame(int i) const;
180 virtual wxAnimationDisposal GetDisposalMethod(int i) const;
181 virtual wxRect GetFrameRect(int i) const; // Position and size of frame
182 virtual int GetDelay(int i) const; // Delay for this frame
183
184 virtual wxSize GetLogicalScreenSize() const;
185 virtual bool GetBackgroundColour(wxColour& col) const;
186 virtual bool GetTransparentColour(wxColour& col) const;
187
188 // Is the animation OK?
189 virtual bool IsValid() const;
190
191 virtual bool LoadFile(const wxString& filename);
192 };
193
194
195 // TODO: Add a wxPyAnimationBase class
196
197 //---------------------------------------------------------------------------
198
199 /* wxGIFAnimation
200 * This will be moved to a separate file in due course.
201 */
202 class wxGIFAnimation : public wxAnimationBase
203 {
204 public:
205 wxGIFAnimation() ;
206 ~wxGIFAnimation() ;
207
208 //// Accessors
209
210 virtual int GetFrameCount() const;
211 %newobject GetFrame;
212 virtual wxImage* GetFrame(int i) const;
213 virtual wxAnimationDisposal GetDisposalMethod(int i) const;
214 virtual wxRect GetFrameRect(int i) const; // Position and size of frame
215 virtual int GetDelay(int i) const; // Delay for this frame
216
217 virtual wxSize GetLogicalScreenSize() const ;
218 virtual bool GetBackgroundColour(wxColour& col) const ;
219 virtual bool GetTransparentColour(wxColour& col) const ;
220
221 virtual bool IsValid() const;
222
223 //// Operations
224
225 virtual bool LoadFile(const wxString& filename);
226
227 };
228
229
230 //---------------------------------------------------------------------------
231
232 /*
233 * wxAnimationCtrlBase
234 * Abstract base class for format-specific animation controls.
235 * This class implements most of the functionality; all a derived
236 * class has to do is create the appropriate animation class on demand.
237 */
238
239 // Resize to animation size if this is set
240 enum { wxAN_FIT_ANIMATION };
241
242
243 // class wxAnimationCtrlBase: public wxControl
244 // {
245 // public:
246 // %pythonAppend wxAnimationCtrlBase "self._setOORInfo(self)"
247 // %pythonAppend wxAnimationCtrlBase() ""
248
249 // wxAnimationCtrlBase(wxWindow *parent, wxWindowID id,
250 // const wxString& filename = wxPyEmptyString,
251 // const wxPoint& pos = wxDefaultPosition,
252 // const wxSize& size = wxDefaultSize,
253 // long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
254 // const wxString& name = wxPyAnimationControlNameStr);
255 // %RenameCtor(PreAnimationCtrlBase, wxAnimationCtrlBase());
256
257 // bool Create(wxWindow *parent, wxWindowID id,
258 // const wxString& filename = wxPyEmptyString,
259 // const wxPoint& pos = wxDefaultPosition,
260 // const wxSize& size = wxDefaultSize,
261 // long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
262 // const wxString& name = wxPyAnimationControlNameStr);
263
264 // //// Operations
265 // virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
266 // virtual bool Play(bool looped = true) ;
267 // virtual void Stop();
268 // virtual void FitToAnimation();
269
270 // //// Accessors
271 // virtual bool IsPlaying() const;
272 // virtual wxAnimationPlayer& GetPlayer();
273 // virtual wxAnimationBase* GetAnimation();
274
275 // const wxString& GetFilename() const;
276 // void SetFilename(const wxString& filename);
277
278 // };
279
280
281 /*
282 * wxGIFAnimationCtrl
283 * Provides a GIF animation class when required.
284 */
285
286 MustHaveApp(wxGIFAnimationCtrl);
287 class wxGIFAnimationCtrl: public wxControl //wxAnimationCtrlBase
288 {
289 public:
290 %pythonAppend wxGIFAnimationCtrl "self._setOORInfo(self)"
291 %pythonAppend wxGIFAnimationCtrl() ""
292
293 wxGIFAnimationCtrl(wxWindow *parent, wxWindowID id=-1,
294 const wxString& filename = wxPyEmptyString,
295 const wxPoint& pos = wxDefaultPosition,
296 const wxSize& size = wxDefaultSize,
297 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
298 const wxString& name = wxPyAnimationControlNameStr);
299 %RenameCtor(PreGIFAnimationCtrl, wxGIFAnimationCtrl());
300
301 bool Create(wxWindow *parent, wxWindowID id=-1,
302 const wxString& filename = wxPyEmptyString,
303 const wxPoint& pos = wxDefaultPosition,
304 const wxSize& size = wxDefaultSize,
305 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
306 const wxString& name = wxPyAnimationControlNameStr);
307
308 //// Operations
309 virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
310 virtual bool Play(bool looped = true) ;
311 virtual void Stop();
312 virtual void FitToAnimation();
313
314 //// Accessors
315 virtual bool IsPlaying() const;
316 virtual wxAnimationPlayer& GetPlayer();
317 virtual wxAnimationBase* GetAnimation();
318
319 const wxString& GetFilename() const;
320 void SetFilename(const wxString& filename);
321
322 };
323
324 //---------------------------------------------------------------------------
325 //---------------------------------------------------------------------------
326