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 `wxGIFAnimationCtrl` 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 %include _animate_rename.i
40 //---------------------------------------------------------------------------
43 enum wxAnimationDisposal
45 wxANIM_UNSPECIFIED = -1,
46 wxANIM_DONOTREMOVE = 0,
47 wxANIM_TOBACKGROUND = 1,
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
59 class wxAnimationPlayer : public wxObject
62 wxAnimationPlayer(wxAnimationBase *animation = NULL,
63 bool destroyAnimation = false);
67 void SetAnimation(wxAnimationBase* animation, bool destroyAnimation = false);
68 wxAnimationBase* GetAnimation() const;
70 void SetDestroyAnimation(bool destroyAnimation);
71 bool GetDestroyAnimation() const;
73 void SetCurrentFrame(int currentFrame);
74 int GetCurrentFrame() const;
76 void SetWindow(wxWindow* window);
77 wxWindow* GetWindow() const;
79 void SetPosition(const wxPoint& pos);
80 wxPoint GetPosition() const;
82 void SetLooped(bool looped);
83 bool GetLooped() const;
85 bool HasAnimation() const;
87 bool IsPlaying() const;
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;
94 // Set and use a user-specified background colour (valid for transparent
96 void SetCustomBackgroundColour(const wxColour& col,
97 bool useCustomBackgroundColour = true);
99 bool UsingCustomBackgroundColour() const;
100 const wxColour& GetCustomBackgroundColour() const;
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;
111 virtual bool Play(wxWindow& window, const wxPoint& pos = wxPoint(0, 0), bool looped = true);
113 // Build animation (list of wxImages). If not called before Play
114 // is called, Play will call this automatically.
115 virtual bool Build();
117 // Stop the animation
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);
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
131 virtual wxSize GetLogicalScreenSize() const;
132 virtual bool GetBackgroundColour(wxColour& col) const ;
133 virtual bool GetTransparentColour(wxColour& col) const ;
137 virtual bool PlayFrame(int frame, wxWindow& window, const wxPoint& pos);
138 %Rename(PlayNextFrame,
139 virtual bool, PlayFrame());
141 virtual void DrawFrame(int frame, wxDC& dc, const wxPoint& pos);
142 virtual void DrawBackground(wxDC& dc, const wxPoint& pos, const wxColour& colour);
144 // Clear the wxImage cache
145 virtual void ClearCache();
147 // Save the pertinent area of the window so we can restore
148 // it if drawing transparently
149 void SaveBackground(const wxRect& rect);
151 wxBitmap& GetBackingStore();
156 //---------------------------------------------------------------------------
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.
168 class wxAnimationBase : public wxObject
171 //wxAnimationBase() {}; // It's an ABC
172 ~wxAnimationBase() {};
174 //// Accessors. Should be overridden by each derived class.
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
182 virtual wxSize GetLogicalScreenSize() const;
183 virtual bool GetBackgroundColour(wxColour& col) const;
184 virtual bool GetTransparentColour(wxColour& col) const;
186 // Is the animation OK?
187 virtual bool IsValid() const;
189 virtual bool LoadFile(const wxString& filename);
193 // TODO: Add a wxPyAnimationBase class
195 //---------------------------------------------------------------------------
198 * This will be moved to a separate file in due course.
200 class wxGIFAnimation : public wxAnimationBase
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
214 virtual wxSize GetLogicalScreenSize() const ;
215 virtual bool GetBackgroundColour(wxColour& col) const ;
216 virtual bool GetTransparentColour(wxColour& col) const ;
218 virtual bool IsValid() const;
222 virtual bool LoadFile(const wxString& filename);
227 //---------------------------------------------------------------------------
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.
236 // Resize to animation size if this is set
237 enum { wxAN_FIT_ANIMATION };
240 // class wxAnimationCtrlBase: public wxControl
243 // %pythonAppend wxAnimationCtrlBase "self._setOORInfo(self)"
244 // %pythonAppend wxAnimationCtrlBase() ""
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());
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);
262 // virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
263 // virtual bool Play(bool looped = true) ;
264 // virtual void Stop();
265 // virtual void FitToAnimation();
268 // virtual bool IsPlaying() const;
269 // virtual wxAnimationPlayer& GetPlayer();
270 // virtual wxAnimationBase* GetAnimation();
272 // const wxString& GetFilename() const;
273 // void SetFilename(const wxString& filename);
280 * Provides a GIF animation class when required.
283 MustHaveApp(wxGIFAnimationCtrl);
284 class wxGIFAnimationCtrl: public wxControl //wxAnimationCtrlBase
287 %pythonAppend wxGIFAnimationCtrl "self._setOORInfo(self)"
288 %pythonAppend wxGIFAnimationCtrl() ""
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());
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);
306 virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
307 virtual bool Play(bool looped = true) ;
309 virtual void FitToAnimation();
312 virtual bool IsPlaying() const;
313 virtual wxAnimationPlayer& GetPlayer();
314 virtual wxAnimationBase* GetAnimation();
316 const wxString& GetFilename() const;
317 void SetFilename(const wxString& filename);
321 //---------------------------------------------------------------------------
322 //---------------------------------------------------------------------------