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/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;
 
 127     virtual wxImage* GetFrame(int i) const; // Creates a new wxImage
 
 128     virtual wxAnimationDisposal GetDisposalMethod(int i) const;
 
 129     virtual wxRect GetFrameRect(int i) const; // Position and size of frame
 
 130     virtual int GetDelay(int i) const; // Delay for this frame
 
 132     virtual wxSize GetLogicalScreenSize() const;
 
 133     virtual bool GetBackgroundColour(wxColour& col) const ;
 
 134     virtual bool GetTransparentColour(wxColour& col) const ;
 
 138     virtual bool PlayFrame(int frame, wxWindow& window, const wxPoint& pos);
 
 139     %Rename(PlayNextFrame,
 
 140             virtual bool, PlayFrame());
 
 142     virtual void DrawFrame(int frame, wxDC& dc, const wxPoint& pos);
 
 143     virtual void DrawBackground(wxDC& dc, const wxPoint& pos, const wxColour& colour);
 
 145     // Clear the wxImage cache
 
 146     virtual void ClearCache();
 
 148     // Save the pertinent area of the window so we can restore
 
 149     // it if drawing transparently
 
 150     void SaveBackground(const wxRect& rect);
 
 152     wxBitmap& GetBackingStore();
 
 157 //---------------------------------------------------------------------------
 
 160  * Base class for animations.
 
 161  * A wxXXXAnimation only stores the animation, providing accessors to
 
 162  * wxAnimationPlayer.  Currently an animation is read-only, but we could
 
 163  * extend the API for adding frames programmatically, and perhaps have a
 
 164  * wxMemoryAnimation class that stores its frames in memory, and is able to
 
 165  * save all files with suitable filenames. You could then use e.g. Ulead GIF
 
 166  * Animator to load the image files into a GIF animation.
 
 169 class wxAnimationBase : public wxObject
 
 172     //wxAnimationBase() {};  // It's an ABC
 
 173     ~wxAnimationBase() {};
 
 175 //// Accessors. Should be overridden by each derived class.
 
 177     virtual int GetFrameCount() const;
 
 179     virtual wxImage* GetFrame(int i) const;
 
 180     virtual wxAnimationDisposal GetDisposalMethod(int i) const;
 
 181     virtual wxRect GetFrameRect(int i) const; // Position and size of frame
 
 182     virtual int GetDelay(int i) const; // Delay for this frame
 
 184     virtual wxSize GetLogicalScreenSize() const;
 
 185     virtual bool GetBackgroundColour(wxColour& col) const;
 
 186     virtual bool GetTransparentColour(wxColour& col) const;
 
 188     // Is the animation OK?
 
 189     virtual bool IsValid() const;
 
 191     virtual bool LoadFile(const wxString& filename);
 
 195 // TODO:  Add a wxPyAnimationBase class
 
 197 //---------------------------------------------------------------------------
 
 200  * This will be moved to a separate file in due course.
 
 202 class wxGIFAnimation : public wxAnimationBase
 
 210     virtual int GetFrameCount() const;
 
 212     virtual wxImage* GetFrame(int i) const;
 
 213     virtual wxAnimationDisposal GetDisposalMethod(int i) const;
 
 214     virtual wxRect GetFrameRect(int i) const; // Position and size of frame
 
 215     virtual int GetDelay(int i) const; // Delay for this frame
 
 217     virtual wxSize GetLogicalScreenSize() const ;
 
 218     virtual bool GetBackgroundColour(wxColour& col) const ;
 
 219     virtual bool GetTransparentColour(wxColour& col) const ;
 
 221     virtual bool IsValid() const;
 
 225     virtual bool LoadFile(const wxString& filename);
 
 230 //---------------------------------------------------------------------------
 
 233  * wxAnimationCtrlBase
 
 234  * Abstract base class for format-specific animation controls.
 
 235  * This class implements most of the functionality; all a derived
 
 236  * class has to do is create the appropriate animation class on demand.
 
 239 // Resize to animation size if this is set
 
 240 enum { wxAN_FIT_ANIMATION };
 
 243 // class  wxAnimationCtrlBase: public wxControl
 
 246 //     %pythonAppend wxAnimationCtrlBase         "self._setOORInfo(self)"
 
 247 //     %pythonAppend wxAnimationCtrlBase()       ""
 
 249 //     wxAnimationCtrlBase(wxWindow *parent, wxWindowID id,
 
 250 //                         const wxString& filename = wxPyEmptyString,
 
 251 //                         const wxPoint& pos = wxDefaultPosition,
 
 252 //                         const wxSize& size = wxDefaultSize,
 
 253 //                         long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 254 //                         const wxString& name = wxPyAnimationControlNameStr);
 
 255 //     %RenameCtor(PreAnimationCtrlBase, wxAnimationCtrlBase());
 
 257 //     bool Create(wxWindow *parent, wxWindowID id,
 
 258 //                 const wxString& filename = wxPyEmptyString,
 
 259 //                 const wxPoint& pos = wxDefaultPosition,
 
 260 //                 const wxSize& size = wxDefaultSize,
 
 261 //                 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 262 //                 const wxString& name = wxPyAnimationControlNameStr);
 
 265 //     virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
 
 266 //     virtual bool Play(bool looped = true) ;
 
 267 //     virtual void Stop();
 
 268 //     virtual void FitToAnimation();
 
 271 //     virtual bool IsPlaying() const;
 
 272 //     virtual wxAnimationPlayer& GetPlayer();
 
 273 //     virtual wxAnimationBase* GetAnimation();
 
 275 //     const wxString& GetFilename() const;
 
 276 //     void SetFilename(const wxString& filename);
 
 283  * Provides a GIF animation class when required.
 
 286 MustHaveApp(wxGIFAnimationCtrl);
 
 287 class wxGIFAnimationCtrl: public wxControl  //wxAnimationCtrlBase
 
 290     %pythonAppend wxGIFAnimationCtrl         "self._setOORInfo(self)"
 
 291     %pythonAppend wxGIFAnimationCtrl()       ""
 
 293     wxGIFAnimationCtrl(wxWindow *parent, wxWindowID id=-1,
 
 294                        const wxString& filename = wxPyEmptyString,
 
 295                        const wxPoint& pos = wxDefaultPosition,
 
 296                        const wxSize& size = wxDefaultSize,
 
 297                        long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 298                        const wxString& name = wxPyAnimationControlNameStr);
 
 299     %RenameCtor(PreGIFAnimationCtrl, wxGIFAnimationCtrl());
 
 301     bool Create(wxWindow *parent, wxWindowID id=-1,
 
 302                 const wxString& filename = wxPyEmptyString,
 
 303                 const wxPoint& pos = wxDefaultPosition,
 
 304                 const wxSize& size = wxDefaultSize,
 
 305                 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 306                 const wxString& name = wxPyAnimationControlNameStr);
 
 309     virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
 
 310     virtual bool Play(bool looped = true) ;
 
 312     virtual void FitToAnimation();
 
 315     virtual bool IsPlaying() const;
 
 316     virtual wxAnimationPlayer& GetPlayer();
 
 317     virtual wxAnimationBase* GetAnimation();
 
 319     const wxString& GetFilename() const;
 
 320     void SetFilename(const wxString& filename);
 
 324 //---------------------------------------------------------------------------
 
 325 //---------------------------------------------------------------------------