| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: animate.i |
| 3 | // Purpose: Wrappers for the animation classes in wx/contrib |
| 4 | // |
| 5 | // Author: Robin Dunn |
| 6 | // |
| 7 | // Created: 4-April-2005 |
| 8 | // RCS-ID: $Id$ |
| 9 | // Copyright: (c) 2005 by Total Control Software |
| 10 | // Licence: wxWindows license |
| 11 | ///////////////////////////////////////////////////////////////////////////// |
| 12 | |
| 13 | %define DOCSTRING |
| 14 | "Simple animation player classes, including `GIFAnimationCtrl` for displaying |
| 15 | animated GIF files |
| 16 | " |
| 17 | %enddef |
| 18 | |
| 19 | %module(package="wx", docstring=DOCSTRING) animate |
| 20 | |
| 21 | |
| 22 | %{ |
| 23 | #include "wx/wxPython/wxPython.h" |
| 24 | #include "wx/wxPython/pyclasses.h" |
| 25 | #include "wx/wxPython/pyistream.h" |
| 26 | #include <wx/animate.h> |
| 27 | %} |
| 28 | |
| 29 | //--------------------------------------------------------------------------- |
| 30 | |
| 31 | %import core.i |
| 32 | %pythoncode { import wx } |
| 33 | %pythoncode { __docfilter__ = wx._core.__DocFilter(globals()) } |
| 34 | |
| 35 | |
| 36 | MAKE_CONST_WXSTRING(AnimationCtrlNameStr); |
| 37 | MAKE_CONST_WXSTRING_NOSWIG(EmptyString); |
| 38 | |
| 39 | //--------------------------------------------------------------------------- |
| 40 | |
| 41 | enum wxAnimationDisposal |
| 42 | { |
| 43 | // No disposal specified. The decoder is not required to take any action. |
| 44 | wxANIM_UNSPECIFIED = -1, |
| 45 | |
| 46 | // Do not dispose. The graphic is to be left in place. |
| 47 | wxANIM_DONOTREMOVE = 0, |
| 48 | |
| 49 | // Restore to background color. The area used by the graphic must be |
| 50 | // restored to the background color. |
| 51 | wxANIM_TOBACKGROUND = 1, |
| 52 | |
| 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. |
| 55 | wxANIM_TOPREVIOUS = 2 |
| 56 | }; |
| 57 | |
| 58 | enum wxAnimationType |
| 59 | { |
| 60 | wxANIMATION_TYPE_INVALID, |
| 61 | wxANIMATION_TYPE_GIF, |
| 62 | wxANIMATION_TYPE_ANI, |
| 63 | |
| 64 | wxANIMATION_TYPE_ANY |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | //--------------------------------------------------------------------------- |
| 69 | |
| 70 | |
| 71 | class wxAnimationBase : public wxObject |
| 72 | { |
| 73 | public: |
| 74 | //wxAnimationBase() {}; // It's an ABC |
| 75 | ~wxAnimationBase() {}; |
| 76 | |
| 77 | virtual bool IsOk() const; |
| 78 | |
| 79 | // can be -1 |
| 80 | virtual int GetDelay(size_t i) const; |
| 81 | |
| 82 | virtual size_t GetFrameCount() const; |
| 83 | |
| 84 | %newobject GetFrame; |
| 85 | virtual wxImage GetFrame(size_t i) const; |
| 86 | virtual wxSize GetSize() const; |
| 87 | |
| 88 | virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY); |
| 89 | virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY); |
| 90 | |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | class wxAnimation : public wxAnimationBase |
| 97 | { |
| 98 | public: |
| 99 | %nokwargs wxAnimation; |
| 100 | wxAnimation(); |
| 101 | %extend { |
| 102 | wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) { |
| 103 | wxAnimation* ani = new wxAnimation(); |
| 104 | ani->LoadFile(name, type); |
| 105 | return ani; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | ~wxAnimation(); |
| 110 | |
| 111 | |
| 112 | public: // extended interface used by the generic implementation of wxAnimationCtrl |
| 113 | |
| 114 | #ifndef __WXGTK__ |
| 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; |
| 120 | #else |
| 121 | %extend { |
| 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; } |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | // public: |
| 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(); |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | |
| 141 | %immutable; |
| 142 | %threadWrapperOff; |
| 143 | |
| 144 | const wxAnimation wxNullAnimation; |
| 145 | |
| 146 | %threadWrapperOn; |
| 147 | %mutable; |
| 148 | |
| 149 | |
| 150 | |
| 151 | %{// for backwards compatibility |
| 152 | #ifndef wxAN_FIT_ANIMATION |
| 153 | #define wxAN_FIT_ANIMATION 0x0010 |
| 154 | #endif |
| 155 | %} |
| 156 | |
| 157 | |
| 158 | enum { |
| 159 | wxAC_NO_AUTORESIZE, |
| 160 | wxAC_DEFAULT_STYLE, |
| 161 | |
| 162 | wxAN_FIT_ANIMATION |
| 163 | }; |
| 164 | |
| 165 | |
| 166 | class wxAnimationCtrlBase : public wxControl |
| 167 | { |
| 168 | public: |
| 169 | // wxAnimationCtrlBase() {} *** It's an ABC |
| 170 | |
| 171 | virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY); |
| 172 | |
| 173 | virtual void SetAnimation(const wxAnimation &anim); |
| 174 | virtual wxAnimation GetAnimation() const; |
| 175 | %property(Animation, GetAnimation, SetAnimation); |
| 176 | |
| 177 | virtual bool Play(); |
| 178 | virtual void Stop(); |
| 179 | |
| 180 | virtual bool IsPlaying() const; |
| 181 | }; |
| 182 | |
| 183 | |
| 184 | |
| 185 | MustHaveApp(wxAnimationCtrl); |
| 186 | |
| 187 | class wxAnimationCtrl: public wxAnimationCtrlBase |
| 188 | { |
| 189 | public: |
| 190 | %pythonAppend wxAnimationCtrl "self._setOORInfo(self)" |
| 191 | %pythonAppend wxAnimationCtrl() "" |
| 192 | |
| 193 | wxAnimationCtrl(wxWindow *parent, |
| 194 | wxWindowID id=-1, |
| 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); |
| 200 | |
| 201 | %RenameCtor(PreAnimationCtrl, wxAnimationCtrl()); |
| 202 | |
| 203 | |
| 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); |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | public: // extended API specific to this implementation of wxAnimateCtrl |
| 215 | |
| 216 | #ifndef __WXGTK__ |
| 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; |
| 221 | |
| 222 | // // This overload of Play() lets you specify if the animation must loop or not |
| 223 | // bool Play(bool looped); |
| 224 | |
| 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); |
| 228 | |
| 229 | // Returns a wxBitmap with the current frame drawn in it |
| 230 | wxBitmap& GetBackingStore(); |
| 231 | #else |
| 232 | %extend { |
| 233 | void SetUseWindowBackgroundColour(bool useWinBackground = true) {} |
| 234 | bool IsUsingWindowBackgroundColour() const { return false; } |
| 235 | void DrawCurrentFrame(wxDC& dc) {} |
| 236 | wxBitmap& GetBackingStore() { return wxNullBitmap; } |
| 237 | } |
| 238 | #endif |
| 239 | |
| 240 | }; |
| 241 | |
| 242 | |
| 243 | |
| 244 | %pythoncode { |
| 245 | |
| 246 | class GIFAnimationCtrl(AnimationCtrl): |
| 247 | """ |
| 248 | Backwards compatibility class for AnimationCtrl. |
| 249 | """ |
| 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) |
| 256 | |
| 257 | def GetPlayer(self): |
| 258 | return self |
| 259 | |
| 260 | def UseBackgroundColour(self, useBackground=True): |
| 261 | self.SetUseWindowBackgroundColour(useBackground) |
| 262 | } |
| 263 | |
| 264 | //--------------------------------------------------------------------------- |
| 265 | //--------------------------------------------------------------------------- |
| 266 | |