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