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/wxPython/pyistream.h"
26 #include <wx/animate.h>
29 //---------------------------------------------------------------------------
32 %pythoncode { import wx }
33 %pythoncode { __docfilter__ = wx._core.__DocFilter(globals()) }
36 MAKE_CONST_WXSTRING(AnimationCtrlNameStr);
37 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
39 //---------------------------------------------------------------------------
41 enum wxAnimationDisposal
43 // No disposal specified. The decoder is not required to take any action.
44 wxANIM_UNSPECIFIED = -1,
46 // Do not dispose. The graphic is to be left in place.
47 wxANIM_DONOTREMOVE = 0,
49 // Restore to background color. The area used by the graphic must be
50 // restored to the background color.
51 wxANIM_TOBACKGROUND = 1,
53 // Restore to previous. The decoder is required to restore the area
54 // overwritten by the graphic with what was there prior to rendering the graphic.
60 wxANIMATION_TYPE_INVALID,
68 //---------------------------------------------------------------------------
71 class wxAnimationBase : public wxObject
74 //wxAnimationBase() {}; // It's an ABC
75 ~wxAnimationBase() {};
77 virtual bool IsOk() const;
80 virtual int GetDelay(size_t i) const;
82 virtual size_t GetFrameCount() const;
85 virtual wxImage GetFrame(size_t i) const;
86 virtual wxSize GetSize() const;
88 virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
89 virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
96 class wxAnimation : public wxAnimationBase
99 %nokwargs wxAnimation;
102 wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) {
103 wxAnimation* ani = new wxAnimation();
104 ani->LoadFile(name, type);
112 public: // extended interface used by the generic implementation of wxAnimationCtrl
115 wxPoint GetFramePosition(size_t frame) const;
116 wxAnimationDisposal GetDisposalMethod(size_t frame) const;
117 wxColour GetBackgroundColour() const;
120 wxPoint GetFramePosition(size_t frame) const { return wxDefaultPosition; }
121 wxAnimationDisposal GetDisposalMethod(size_t frame) const { return wxANIM_UNSPECIFIED; }
122 wxColour GetBackgroundColour() const { return wxNullColour; }
127 // static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; }
128 // static void AddHandler(wxAnimationDecoder *handler);
129 // static void InsertHandler(wxAnimationDecoder *handler);
130 // static const wxAnimationDecoder *FindHandler( wxAnimationType animType );
131 // static void CleanUpHandlers();
132 // static void InitStandardHandlers();
140 const wxAnimation wxNullAnimation;
147 %{// for backwards compatibility
148 #ifndef wxAN_FIT_ANIMATION
149 #define wxAN_FIT_ANIMATION 0x0010
162 class wxAnimationCtrlBase : public wxControl
165 // wxAnimationCtrlBase() {} *** It's an ABC
167 virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY);
169 virtual void SetAnimation(const wxAnimation &anim);
170 virtual wxAnimation GetAnimation() const;
171 %property(Animation, GetAnimation, SetAnimation);
176 virtual bool IsPlaying() const;
181 MustHaveApp(wxAnimationCtrl);
183 class wxAnimationCtrl: public wxAnimationCtrlBase
186 %pythonAppend wxAnimationCtrl "self._setOORInfo(self)"
187 %pythonAppend wxAnimationCtrl() ""
189 wxAnimationCtrl(wxWindow *parent,
191 const wxAnimation& anim = wxNullAnimation,
192 const wxPoint& pos = wxDefaultPosition,
193 const wxSize& size = wxDefaultSize,
194 long style = wxAC_DEFAULT_STYLE,
195 const wxString& name = wxPyAnimationCtrlNameStr);
197 %RenameCtor(PreAnimationCtrl, wxAnimationCtrl());
200 bool Create(wxWindow *parent, wxWindowID id,
201 const wxAnimation& anim = wxNullAnimation,
202 const wxPoint& pos = wxDefaultPosition,
203 const wxSize& size = wxDefaultSize,
204 long style = wxAC_DEFAULT_STYLE,
205 const wxString& name = wxPyAnimationCtrlNameStr);
210 public: // extended API specific to this implementation of wxAnimateCtrl
213 // Specify whether the animation's background colour is to be shown (the default),
214 // or whether the window background should show through
215 void SetUseWindowBackgroundColour(bool useWinBackground = true);
216 bool IsUsingWindowBackgroundColour() const;
218 // // This overload of Play() lets you specify if the animation must loop or not
219 // bool Play(bool looped);
221 // Draw the current frame of the animation into given DC.
222 // This is fast as current frame is always cached.
223 void DrawCurrentFrame(wxDC& dc);
225 // Returns a wxBitmap with the current frame drawn in it
226 wxBitmap& GetBackingStore();
229 void SetUseWindowBackgroundColour(bool useWinBackground = true) {}
230 bool IsUsingWindowBackgroundColour() const { return false; }
231 void DrawCurrentFrame(wxDC& dc) {}
232 wxBitmap& GetBackingStore() { return wxNullBitmap; }
242 class GIFAnimationCtrl(AnimationCtrl):
244 Backwards compatibility class for AnimationCtrl.
246 def __init__(self, parent, id=-1, filename="",
247 pos=wx.DefaultPosition, size=wx.DefaultSize,
248 style=AC_DEFAULT_STYLE,
249 name="gifAnimation"):
250 AnimationCtrl.__init__(self, parent, id, NullAnimation, pos, size, style, name)
251 self.LoadFile(filename)
256 def UseBackgroundColour(self, useBackground=True):
257 self.SetUseWindowBackgroundColour(useBackground)
260 //---------------------------------------------------------------------------
261 //---------------------------------------------------------------------------