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 wxSize GetFrameSize(size_t frame) const;
117 wxAnimationDisposal GetDisposalMethod(size_t frame) const;
118 wxColour GetTransparentColour(size_t frame) const;
119 wxColour GetBackgroundColour() const;
122 wxPoint GetFramePosition(size_t frame) const { return wxDefaultPosition; }
123 wxSize GetFrameSize(size_t frame) const { return wxDefaultSize; }
124 wxAnimationDisposal GetDisposalMethod(size_t frame) const { return wxANIM_UNSPECIFIED; }
125 wxColour GetTransparentColour(size_t frame) const { return wxNullColour; }
126 wxColour GetBackgroundColour() const { return wxNullColour; }
131 // static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; }
132 // static void AddHandler(wxAnimationDecoder *handler);
133 // static void InsertHandler(wxAnimationDecoder *handler);
134 // static const wxAnimationDecoder *FindHandler( wxAnimationType animType );
135 // static void CleanUpHandlers();
136 // static void InitStandardHandlers();
144 const wxAnimation wxNullAnimation;
151 %{// for backwards compatibility
152 #ifndef wxAN_FIT_ANIMATION
153 #define wxAN_FIT_ANIMATION 0x0010
166 class wxAnimationCtrlBase : public wxControl
169 // wxAnimationCtrlBase() {} *** It's an ABC
171 virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY);
173 virtual void SetAnimation(const wxAnimation &anim);
174 virtual wxAnimation GetAnimation() const;
175 %property(Animation, GetAnimation, SetAnimation);
180 virtual bool IsPlaying() const;
185 MustHaveApp(wxAnimationCtrl);
187 class wxAnimationCtrl: public wxAnimationCtrlBase
190 %pythonAppend wxAnimationCtrl "self._setOORInfo(self)"
191 %pythonAppend wxAnimationCtrl() ""
193 wxAnimationCtrl(wxWindow *parent,
195 const wxAnimation& anim = wxNullAnimation,
196 const wxPoint& pos = wxDefaultPosition,
197 const wxSize& size = wxDefaultSize,
198 long style = wxAC_DEFAULT_STYLE,
199 const wxString& name = wxPyAnimationCtrlNameStr);
201 %RenameCtor(PreAnimationCtrl, wxAnimationCtrl());
204 bool Create(wxWindow *parent, wxWindowID id,
205 const wxAnimation& anim = wxNullAnimation,
206 const wxPoint& pos = wxDefaultPosition,
207 const wxSize& size = wxDefaultSize,
208 long style = wxAC_DEFAULT_STYLE,
209 const wxString& name = wxPyAnimationCtrlNameStr);
214 public: // extended API specific to this implementation of wxAnimateCtrl
217 // Specify whether the animation's background colour is to be shown (the default),
218 // or whether the window background should show through
219 void SetUseWindowBackgroundColour(bool useWinBackground = true);
220 bool IsUsingWindowBackgroundColour() const;
222 // // This overload of Play() lets you specify if the animation must loop or not
223 // bool Play(bool looped);
225 // Draw the current frame of the animation into given DC.
226 // This is fast as current frame is always cached.
227 void DrawCurrentFrame(wxDC& dc);
229 // Returns a wxBitmap with the current frame drawn in it
230 wxBitmap& GetBackingStore();
233 void SetUseWindowBackgroundColour(bool useWinBackground = true) {}
234 bool IsUsingWindowBackgroundColour() const { return false; }
235 void DrawCurrentFrame(wxDC& dc) {}
236 wxBitmap& GetBackingStore() { return wxNullBitmap; }
246 class GIFAnimationCtrl(AnimationCtrl):
248 Backwards compatibility class for AnimationCtrl.
250 def __init__(self, parent, id=-1, filename="",
251 pos=wx.DefaultPosition, size=wx.DefaultSize,
252 style=AC_DEFAULT_STYLE,
253 name="gifAnimation"):
254 AnimationCtrl.__init__(self, parent, id, NullAnimation, pos, size, style, name)
255 self.LoadFile(filename)
260 def UseBackgroundColour(self, useBackground=True):
261 self.SetUseWindowBackgroundColour(useBackground)
264 //---------------------------------------------------------------------------
265 //---------------------------------------------------------------------------