]>
Commit | Line | Data |
---|---|---|
2e5aa9c4 RD |
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 | |
485f878c | 14 | "Simple animation player classes, including `GIFAnimationCtrl` for displaying |
2e5aa9c4 RD |
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 | virtual wxImage* GetFrame(int i) const; // Creates a new wxImage | |
127 | virtual wxAnimationDisposal GetDisposalMethod(int i) const; | |
128 | virtual wxRect GetFrameRect(int i) const; // Position and size of frame | |
129 | virtual int GetDelay(int i) const; // Delay for this frame | |
130 | ||
131 | virtual wxSize GetLogicalScreenSize() const; | |
132 | virtual bool GetBackgroundColour(wxColour& col) const ; | |
133 | virtual bool GetTransparentColour(wxColour& col) const ; | |
134 | ||
135 | ||
136 | // Play the frame | |
137 | virtual bool PlayFrame(int frame, wxWindow& window, const wxPoint& pos); | |
138 | %Rename(PlayNextFrame, | |
139 | virtual bool, PlayFrame()); | |
140 | ||
141 | virtual void DrawFrame(int frame, wxDC& dc, const wxPoint& pos); | |
142 | virtual void DrawBackground(wxDC& dc, const wxPoint& pos, const wxColour& colour); | |
143 | ||
144 | // Clear the wxImage cache | |
145 | virtual void ClearCache(); | |
146 | ||
147 | // Save the pertinent area of the window so we can restore | |
148 | // it if drawing transparently | |
149 | void SaveBackground(const wxRect& rect); | |
150 | ||
151 | wxBitmap& GetBackingStore(); | |
152 | ||
153 | }; | |
154 | ||
155 | ||
156 | //--------------------------------------------------------------------------- | |
157 | ||
158 | /* wxAnimationBase | |
159 | * Base class for animations. | |
160 | * A wxXXXAnimation only stores the animation, providing accessors to | |
161 | * wxAnimationPlayer. Currently an animation is read-only, but we could | |
162 | * extend the API for adding frames programmatically, and perhaps have a | |
163 | * wxMemoryAnimation class that stores its frames in memory, and is able to | |
164 | * save all files with suitable filenames. You could then use e.g. Ulead GIF | |
165 | * Animator to load the image files into a GIF animation. | |
166 | */ | |
167 | ||
168 | class wxAnimationBase : public wxObject | |
169 | { | |
170 | public: | |
171 | //wxAnimationBase() {}; // It's an ABC | |
172 | ~wxAnimationBase() {}; | |
173 | ||
174 | //// Accessors. Should be overridden by each derived class. | |
175 | ||
176 | virtual int GetFrameCount() const; | |
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 | virtual wxImage* GetFrame(int i) const; | |
210 | virtual wxAnimationDisposal GetDisposalMethod(int i) const; | |
211 | virtual wxRect GetFrameRect(int i) const; // Position and size of frame | |
212 | virtual int GetDelay(int i) const; // Delay for this frame | |
213 | ||
214 | virtual wxSize GetLogicalScreenSize() const ; | |
215 | virtual bool GetBackgroundColour(wxColour& col) const ; | |
216 | virtual bool GetTransparentColour(wxColour& col) const ; | |
217 | ||
218 | virtual bool IsValid() const; | |
219 | ||
220 | //// Operations | |
221 | ||
222 | virtual bool LoadFile(const wxString& filename); | |
223 | ||
224 | }; | |
225 | ||
226 | ||
227 | //--------------------------------------------------------------------------- | |
228 | ||
229 | /* | |
230 | * wxAnimationCtrlBase | |
231 | * Abstract base class for format-specific animation controls. | |
232 | * This class implements most of the functionality; all a derived | |
233 | * class has to do is create the appropriate animation class on demand. | |
234 | */ | |
235 | ||
236 | // Resize to animation size if this is set | |
237 | enum { wxAN_FIT_ANIMATION }; | |
238 | ||
239 | ||
240 | // class wxAnimationCtrlBase: public wxControl | |
241 | // { | |
242 | // public: | |
243 | // %pythonAppend wxAnimationCtrlBase "self._setOORInfo(self)" | |
244 | // %pythonAppend wxAnimationCtrlBase() "" | |
245 | ||
246 | // wxAnimationCtrlBase(wxWindow *parent, wxWindowID id, | |
247 | // const wxString& filename = wxPyEmptyString, | |
248 | // const wxPoint& pos = wxDefaultPosition, | |
249 | // const wxSize& size = wxDefaultSize, | |
250 | // long style = wxAN_FIT_ANIMATION|wxNO_BORDER, | |
251 | // const wxString& name = wxPyAnimationControlNameStr); | |
252 | // %RenameCtor(PreAnimationCtrlBase, wxAnimationCtrlBase()); | |
253 | ||
254 | // bool Create(wxWindow *parent, wxWindowID id, | |
255 | // const wxString& filename = wxPyEmptyString, | |
256 | // const wxPoint& pos = wxDefaultPosition, | |
257 | // const wxSize& size = wxDefaultSize, | |
258 | // long style = wxAN_FIT_ANIMATION|wxNO_BORDER, | |
259 | // const wxString& name = wxPyAnimationControlNameStr); | |
260 | ||
261 | // //// Operations | |
262 | // virtual bool LoadFile(const wxString& filename = wxPyEmptyString); | |
263 | // virtual bool Play(bool looped = true) ; | |
264 | // virtual void Stop(); | |
265 | // virtual void FitToAnimation(); | |
266 | ||
267 | // //// Accessors | |
268 | // virtual bool IsPlaying() const; | |
269 | // virtual wxAnimationPlayer& GetPlayer(); | |
270 | // virtual wxAnimationBase* GetAnimation(); | |
271 | ||
272 | // const wxString& GetFilename() const; | |
273 | // void SetFilename(const wxString& filename); | |
274 | ||
275 | // }; | |
276 | ||
277 | ||
278 | /* | |
279 | * wxGIFAnimationCtrl | |
280 | * Provides a GIF animation class when required. | |
281 | */ | |
282 | ||
283 | MustHaveApp(wxGIFAnimationCtrl); | |
284 | class wxGIFAnimationCtrl: public wxControl //wxAnimationCtrlBase | |
285 | { | |
286 | public: | |
287 | %pythonAppend wxGIFAnimationCtrl "self._setOORInfo(self)" | |
288 | %pythonAppend wxGIFAnimationCtrl() "" | |
289 | ||
290 | wxGIFAnimationCtrl(wxWindow *parent, wxWindowID id=-1, | |
291 | const wxString& filename = wxPyEmptyString, | |
292 | const wxPoint& pos = wxDefaultPosition, | |
293 | const wxSize& size = wxDefaultSize, | |
294 | long style = wxAN_FIT_ANIMATION|wxNO_BORDER, | |
295 | const wxString& name = wxPyAnimationControlNameStr); | |
296 | %RenameCtor(PreGIFAnimationCtrl, wxGIFAnimationCtrl()); | |
297 | ||
298 | bool Create(wxWindow *parent, wxWindowID id=-1, | |
299 | const wxString& filename = wxPyEmptyString, | |
300 | const wxPoint& pos = wxDefaultPosition, | |
301 | const wxSize& size = wxDefaultSize, | |
302 | long style = wxAN_FIT_ANIMATION|wxNO_BORDER, | |
303 | const wxString& name = wxPyAnimationControlNameStr); | |
304 | ||
305 | //// Operations | |
306 | virtual bool LoadFile(const wxString& filename = wxPyEmptyString); | |
307 | virtual bool Play(bool looped = true) ; | |
308 | virtual void Stop(); | |
309 | virtual void FitToAnimation(); | |
310 | ||
311 | //// Accessors | |
312 | virtual bool IsPlaying() const; | |
313 | virtual wxAnimationPlayer& GetPlayer(); | |
314 | virtual wxAnimationBase* GetAnimation(); | |
315 | ||
316 | const wxString& GetFilename() const; | |
317 | void SetFilename(const wxString& filename); | |
318 | ||
319 | }; | |
320 | ||
321 | //--------------------------------------------------------------------------- | |
322 | //--------------------------------------------------------------------------- | |
323 |