1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Wrappers for the animation classes in wx/contrib
7 // Created: 4-April-2005
9 // Copyright: (c) 2005 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 "Simple animation player classes, including `GIFAnimationCtrl` for displaying
19 %module(package="wx", docstring=DOCSTRING) animate
23 #include "wx/wxPython/wxPython.h"
24 #include "wx/wxPython/pyclasses.h"
25 #include <wx/animate/animate.h>
28 //---------------------------------------------------------------------------
31 %pythoncode { import wx }
32 %pythoncode { __docfilter__ = wx._core.__DocFilter(globals()) }
35 MAKE_CONST_WXSTRING2(AnimationControlNameStr, wxT("animationControl"));
36 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
38 //---------------------------------------------------------------------------
41 enum wxAnimationDisposal
43 wxANIM_UNSPECIFIED = -1,
44 wxANIM_DONOTREMOVE = 0,
45 wxANIM_TOBACKGROUND = 1,
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
57 class wxAnimationPlayer : public wxObject
60 wxAnimationPlayer(wxAnimationBase *animation = NULL,
61 bool destroyAnimation = false);
65 void SetAnimation(wxAnimationBase* animation, bool destroyAnimation = false);
66 wxAnimationBase* GetAnimation() const;
68 void SetDestroyAnimation(bool destroyAnimation);
69 bool GetDestroyAnimation() const;
71 void SetCurrentFrame(int currentFrame);
72 int GetCurrentFrame() const;
74 void SetWindow(wxWindow* window);
75 wxWindow* GetWindow() const;
77 void SetPosition(const wxPoint& pos);
78 wxPoint GetPosition() const;
80 void SetLooped(bool looped);
81 bool GetLooped() const;
83 bool HasAnimation() const;
85 bool IsPlaying() const;
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;
92 // Set and use a user-specified background colour (valid for transparent
94 void SetCustomBackgroundColour(const wxColour& col,
95 bool useCustomBackgroundColour = true);
97 bool UsingCustomBackgroundColour() const;
98 const wxColour& GetCustomBackgroundColour() const;
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;
109 virtual bool Play(wxWindow& window, const wxPoint& pos = wxPoint(0, 0), bool looped = true);
111 // Build animation (list of wxImages). If not called before Play
112 // is called, Play will call this automatically.
113 virtual bool Build();
115 // Stop the animation
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);
123 virtual int GetFrameCount() const;
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
130 virtual wxSize GetLogicalScreenSize() const;
131 virtual bool GetBackgroundColour(wxColour& col) const ;
132 virtual bool GetTransparentColour(wxColour& col) const ;
136 virtual bool PlayFrame(int frame, wxWindow& window, const wxPoint& pos);
137 %Rename(PlayNextFrame,
138 virtual bool, PlayFrame());
140 virtual void DrawFrame(int frame, wxDC& dc, const wxPoint& pos);
141 virtual void DrawBackground(wxDC& dc, const wxPoint& pos, const wxColour& colour);
143 // Clear the wxImage cache
144 virtual void ClearCache();
146 // Save the pertinent area of the window so we can restore
147 // it if drawing transparently
148 void SaveBackground(const wxRect& rect);
150 wxBitmap& GetBackingStore();
152 %property(Animation, GetAnimation, SetAnimation, doc="See `GetAnimation` and `SetAnimation`");
153 %property(BackingStore, GetBackingStore, doc="See `GetBackingStore`");
154 %property(CurrentFrame, GetCurrentFrame, SetCurrentFrame, doc="See `GetCurrentFrame` and `SetCurrentFrame`");
155 %property(CustomBackgroundColour, GetCustomBackgroundColour, SetCustomBackgroundColour, doc="See `GetCustomBackgroundColour` and `SetCustomBackgroundColour`");
156 %property(DestroyAnimation, GetDestroyAnimation, SetDestroyAnimation, doc="See `GetDestroyAnimation` and `SetDestroyAnimation`");
157 %property(DisposalMethod, GetDisposalMethod, doc="See `GetDisposalMethod`");
158 %property(FrameCount, GetFrameCount, doc="See `GetFrameCount`");
159 %property(LogicalScreenSize, GetLogicalScreenSize, doc="See `GetLogicalScreenSize`");
160 %property(Looped, GetLooped, SetLooped, doc="See `GetLooped` and `SetLooped`");
161 %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`");
162 %property(Window, GetWindow, SetWindow, doc="See `GetWindow` and `SetWindow`");
166 //---------------------------------------------------------------------------
169 * Base class for animations.
170 * A wxXXXAnimation only stores the animation, providing accessors to
171 * wxAnimationPlayer. Currently an animation is read-only, but we could
172 * extend the API for adding frames programmatically, and perhaps have a
173 * wxMemoryAnimation class that stores its frames in memory, and is able to
174 * save all files with suitable filenames. You could then use e.g. Ulead GIF
175 * Animator to load the image files into a GIF animation.
178 class wxAnimationBase : public wxObject
181 //wxAnimationBase() {}; // It's an ABC
182 ~wxAnimationBase() {};
184 //// Accessors. Should be overridden by each derived class.
186 virtual int GetFrameCount() const;
188 virtual wxImage* GetFrame(int i) const;
189 virtual wxAnimationDisposal GetDisposalMethod(int i) const;
190 virtual wxRect GetFrameRect(int i) const; // Position and size of frame
191 virtual int GetDelay(int i) const; // Delay for this frame
193 virtual wxSize GetLogicalScreenSize() const;
194 virtual bool GetBackgroundColour(wxColour& col) const;
195 virtual bool GetTransparentColour(wxColour& col) const;
197 // Is the animation OK?
198 virtual bool IsValid() const;
200 virtual bool LoadFile(const wxString& filename);
202 %property(DisposalMethod, GetDisposalMethod, doc="See `GetDisposalMethod`");
203 %property(FrameCount, GetFrameCount, doc="See `GetFrameCount`");
204 %property(LogicalScreenSize, GetLogicalScreenSize, doc="See `GetLogicalScreenSize`");
208 // TODO: Add a wxPyAnimationBase class
210 //---------------------------------------------------------------------------
213 * This will be moved to a separate file in due course.
215 class wxGIFAnimation : public wxAnimationBase
223 virtual int GetFrameCount() const;
225 virtual wxImage* GetFrame(int i) const;
226 virtual wxAnimationDisposal GetDisposalMethod(int i) const;
227 virtual wxRect GetFrameRect(int i) const; // Position and size of frame
228 virtual int GetDelay(int i) const; // Delay for this frame
230 virtual wxSize GetLogicalScreenSize() const ;
231 virtual bool GetBackgroundColour(wxColour& col) const ;
232 virtual bool GetTransparentColour(wxColour& col) const ;
234 virtual bool IsValid() const;
238 virtual bool LoadFile(const wxString& filename);
243 //---------------------------------------------------------------------------
246 * wxAnimationCtrlBase
247 * Abstract base class for format-specific animation controls.
248 * This class implements most of the functionality; all a derived
249 * class has to do is create the appropriate animation class on demand.
252 // Resize to animation size if this is set
253 enum { wxAN_FIT_ANIMATION };
256 // class wxAnimationCtrlBase: public wxControl
259 // %pythonAppend wxAnimationCtrlBase "self._setOORInfo(self)"
260 // %pythonAppend wxAnimationCtrlBase() ""
262 // wxAnimationCtrlBase(wxWindow *parent, wxWindowID id,
263 // const wxString& filename = wxPyEmptyString,
264 // const wxPoint& pos = wxDefaultPosition,
265 // const wxSize& size = wxDefaultSize,
266 // long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
267 // const wxString& name = wxPyAnimationControlNameStr);
268 // %RenameCtor(PreAnimationCtrlBase, wxAnimationCtrlBase());
270 // bool Create(wxWindow *parent, wxWindowID id,
271 // const wxString& filename = wxPyEmptyString,
272 // const wxPoint& pos = wxDefaultPosition,
273 // const wxSize& size = wxDefaultSize,
274 // long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
275 // const wxString& name = wxPyAnimationControlNameStr);
278 // virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
279 // virtual bool Play(bool looped = true) ;
280 // virtual void Stop();
281 // virtual void FitToAnimation();
284 // virtual bool IsPlaying() const;
285 // virtual wxAnimationPlayer& GetPlayer();
286 // virtual wxAnimationBase* GetAnimation();
288 // const wxString& GetFilename() const;
289 // void SetFilename(const wxString& filename);
296 * Provides a GIF animation class when required.
299 MustHaveApp(wxGIFAnimationCtrl);
300 class wxGIFAnimationCtrl: public wxControl //wxAnimationCtrlBase
303 %pythonAppend wxGIFAnimationCtrl "self._setOORInfo(self)"
304 %pythonAppend wxGIFAnimationCtrl() ""
306 wxGIFAnimationCtrl(wxWindow *parent, wxWindowID id=-1,
307 const wxString& filename = wxPyEmptyString,
308 const wxPoint& pos = wxDefaultPosition,
309 const wxSize& size = wxDefaultSize,
310 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
311 const wxString& name = wxPyAnimationControlNameStr);
312 %RenameCtor(PreGIFAnimationCtrl, wxGIFAnimationCtrl());
314 bool Create(wxWindow *parent, wxWindowID id=-1,
315 const wxString& filename = wxPyEmptyString,
316 const wxPoint& pos = wxDefaultPosition,
317 const wxSize& size = wxDefaultSize,
318 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
319 const wxString& name = wxPyAnimationControlNameStr);
322 virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
323 virtual bool Play(bool looped = true) ;
325 virtual void FitToAnimation();
328 virtual bool IsPlaying() const;
329 virtual wxAnimationPlayer& GetPlayer();
330 virtual wxAnimationBase* GetAnimation();
332 const wxString& GetFilename() const;
333 void SetFilename(const wxString& filename);
335 %property(Animation, GetAnimation, doc="See `GetAnimation`");
336 %property(Filename, GetFilename, SetFilename, doc="See `GetFilename` and `SetFilename`");
337 %property(Player, GetPlayer, doc="See `GetPlayer`");
340 //---------------------------------------------------------------------------
341 //---------------------------------------------------------------------------