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(int i) const;
82 virtual int GetFrameCount() const;
85 virtual wxImage GetFrame(int 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(int frame) const;
116 wxSize GetFrameSize(int frame) const;
117 wxAnimationDisposal GetDisposalMethod(int frame) const;
118 wxColour GetTransparentColour(int frame) const;
119 wxColour GetBackgroundColour() const;
122 wxPoint GetFramePosition(int frame) const { return wxDefaultPosition; }
123 wxSize GetFrameSize(int frame) const { return wxDefaultSize; }
124 wxAnimationDisposal GetDisposalMethod(int frame) const { return wxANIM_UNSPECIFIED; }
125 wxColour GetTransparentColour(int 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;
181 virtual void SetInactiveBitmap(const wxBitmap &bmp);
182 wxBitmap GetInactiveBitmap() const;
184 %property(InactiveBitmap, GetInactiveBitmap, SetInactiveBitmap);
189 MustHaveApp(wxAnimationCtrl);
191 class wxAnimationCtrl: public wxAnimationCtrlBase
194 %pythonAppend wxAnimationCtrl "self._setOORInfo(self)"
195 %pythonAppend wxAnimationCtrl() ""
197 wxAnimationCtrl(wxWindow *parent,
199 const wxAnimation& anim = wxNullAnimation,
200 const wxPoint& pos = wxDefaultPosition,
201 const wxSize& size = wxDefaultSize,
202 long style = wxAC_DEFAULT_STYLE,
203 const wxString& name = wxPyAnimationCtrlNameStr);
205 %RenameCtor(PreAnimationCtrl, wxAnimationCtrl());
208 bool Create(wxWindow *parent, wxWindowID id,
209 const wxAnimation& anim = wxNullAnimation,
210 const wxPoint& pos = wxDefaultPosition,
211 const wxSize& size = wxDefaultSize,
212 long style = wxAC_DEFAULT_STYLE,
213 const wxString& name = wxPyAnimationCtrlNameStr);
218 public: // extended API specific to this implementation of wxAnimateCtrl
221 // Specify whether the animation's background colour is to be shown (the default),
222 // or whether the window background should show through
223 void SetUseWindowBackgroundColour(bool useWinBackground = true);
224 bool IsUsingWindowBackgroundColour() const;
226 // // This overload of Play() lets you specify if the animation must loop or not
227 // bool Play(bool looped);
229 // Draw the current frame of the animation into given DC.
230 // This is fast as current frame is always cached.
231 void DrawCurrentFrame(wxDC& dc);
233 // Returns a wxBitmap with the current frame drawn in it
234 wxBitmap& GetBackingStore();
237 void SetUseWindowBackgroundColour(bool useWinBackground = true) {}
238 bool IsUsingWindowBackgroundColour() const { return false; }
239 void DrawCurrentFrame(wxDC& dc) {}
240 wxBitmap& GetBackingStore() { return wxNullBitmap; }
250 class GIFAnimationCtrl(AnimationCtrl):
252 Backwards compatibility class for AnimationCtrl.
254 def __init__(self, parent, id=-1, filename="",
255 pos=wx.DefaultPosition, size=wx.DefaultSize,
256 style=AC_DEFAULT_STYLE,
257 name="gifAnimation"):
258 AnimationCtrl.__init__(self, parent, id, NullAnimation, pos, size, style, name)
259 self.LoadFile(filename)
264 def UseBackgroundColour(self, useBackground=True):
265 self.SetUseWindowBackgroundColour(useBackground)
268 //---------------------------------------------------------------------------
269 //---------------------------------------------------------------------------