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 //---------------------------------------------------------------------------
 
  41 enum wxAnimationDisposal
 
  43     wxANIM_UNSPECIFIED = -1,
 
  44     wxANIM_DONOTREMOVE = 0,
 
  45     wxANIM_TOBACKGROUND = 1,
 
  51  * Create an object of this class, and either pass an wxXXXAnimation object in
 
  52  * the constructor, or call SetAnimation. Then call Play().  The wxAnimation
 
  53  * object is only destroyed in the destructor if destroyAnimation is true in
 
  57 class wxAnimationPlayer : public wxObject
 
  60     wxAnimationPlayer(wxAnimationBase *animation = NULL,
 
  61                       bool destroyAnimation = false);
 
  65     void SetAnimation(wxAnimationBase* animation, bool destroyAnimation = false);
 
  66     wxAnimationBase* GetAnimation() const;
 
  68     void SetDestroyAnimation(bool destroyAnimation);
 
  69     bool GetDestroyAnimation() const;
 
  71     void SetCurrentFrame(int currentFrame);
 
  72     int GetCurrentFrame() const;
 
  74     void SetWindow(wxWindow* window);
 
  75     wxWindow* GetWindow() const;
 
  77     void SetPosition(const wxPoint& pos);
 
  78     wxPoint GetPosition() const;
 
  80     void SetLooped(bool looped);
 
  81     bool GetLooped() const;
 
  83     bool HasAnimation() const;
 
  85     bool IsPlaying() const;
 
  87     // Specify whether the GIF's background colour is to be shown,
 
  88     // or whether the window background should show through (the default)
 
  89     void UseBackgroundColour(bool useBackground);
 
  90     bool UsingBackgroundColour() const;
 
  92     // Set and use a user-specified background colour (valid for transparent
 
  94     void SetCustomBackgroundColour(const wxColour& col,
 
  95                                    bool useCustomBackgroundColour = true);
 
  97     bool UsingCustomBackgroundColour() const;
 
  98     const wxColour& GetCustomBackgroundColour() const;
 
 100     // Another refinement - suppose we're drawing the animation in a separate
 
 101     // control or window. We may wish to use the background of the parent
 
 102     // window as the background of our animation. This allows us to specify
 
 103     // whether to grab from the parent or from this window.
 
 104     void UseParentBackground(bool useParent);
 
 105     bool UsingParentBackground() const;
 
 109     virtual bool Play(wxWindow& window, const wxPoint& pos = wxPoint(0, 0), bool looped = true);
 
 111     // Build animation (list of wxImages). If not called before Play
 
 112     // is called, Play will call this automatically.
 
 113     virtual bool Build();
 
 115     // Stop the animation
 
 118     // Draw the current view of the animation into this DC.
 
 119     // Call this from your OnPaint, for example.
 
 120     virtual void Draw(wxDC& dc);
 
 123     virtual int GetFrameCount() const;
 
 125     virtual wxImage* GetFrame(int i) const; // Creates a new wxImage
 
 126     virtual wxAnimationDisposal GetDisposalMethod(int i) const;
 
 127     virtual wxRect GetFrameRect(int i) const; // Position and size of frame
 
 128     virtual int GetDelay(int i) const; // Delay for this frame
 
 130     virtual wxSize GetLogicalScreenSize() const;
 
 131     virtual bool GetBackgroundColour(wxColour& col) const ;
 
 132     virtual bool GetTransparentColour(wxColour& col) const ;
 
 136     virtual bool PlayFrame(int frame, wxWindow& window, const wxPoint& pos);
 
 137     %Rename(PlayNextFrame,
 
 138             virtual bool, PlayFrame());
 
 140     virtual void DrawFrame(int frame, wxDC& dc, const wxPoint& pos);
 
 141     virtual void DrawBackground(wxDC& dc, const wxPoint& pos, const wxColour& colour);
 
 143     // Clear the wxImage cache
 
 144     virtual void ClearCache();
 
 146     // Save the pertinent area of the window so we can restore
 
 147     // it if drawing transparently
 
 148     void SaveBackground(const wxRect& rect);
 
 150     wxBitmap& GetBackingStore();
 
 155 //---------------------------------------------------------------------------
 
 158  * Base class for animations.
 
 159  * A wxXXXAnimation only stores the animation, providing accessors to
 
 160  * wxAnimationPlayer.  Currently an animation is read-only, but we could
 
 161  * extend the API for adding frames programmatically, and perhaps have a
 
 162  * wxMemoryAnimation class that stores its frames in memory, and is able to
 
 163  * save all files with suitable filenames. You could then use e.g. Ulead GIF
 
 164  * Animator to load the image files into a GIF animation.
 
 167 class wxAnimationBase : public wxObject
 
 170     //wxAnimationBase() {};  // It's an ABC
 
 171     ~wxAnimationBase() {};
 
 173 //// Accessors. Should be overridden by each derived class.
 
 175     virtual int GetFrameCount() const;
 
 177     virtual wxImage* GetFrame(int i) const;
 
 178     virtual wxAnimationDisposal GetDisposalMethod(int i) const;
 
 179     virtual wxRect GetFrameRect(int i) const; // Position and size of frame
 
 180     virtual int GetDelay(int i) const; // Delay for this frame
 
 182     virtual wxSize GetLogicalScreenSize() const;
 
 183     virtual bool GetBackgroundColour(wxColour& col) const;
 
 184     virtual bool GetTransparentColour(wxColour& col) const;
 
 186     // Is the animation OK?
 
 187     virtual bool IsValid() const;
 
 189     virtual bool LoadFile(const wxString& filename);
 
 193 // TODO:  Add a wxPyAnimationBase class
 
 195 //---------------------------------------------------------------------------
 
 198  * This will be moved to a separate file in due course.
 
 200 class wxGIFAnimation : public wxAnimationBase
 
 208     virtual int GetFrameCount() const;
 
 210     virtual wxImage* GetFrame(int i) const;
 
 211     virtual wxAnimationDisposal GetDisposalMethod(int i) const;
 
 212     virtual wxRect GetFrameRect(int i) const; // Position and size of frame
 
 213     virtual int GetDelay(int i) const; // Delay for this frame
 
 215     virtual wxSize GetLogicalScreenSize() const ;
 
 216     virtual bool GetBackgroundColour(wxColour& col) const ;
 
 217     virtual bool GetTransparentColour(wxColour& col) const ;
 
 219     virtual bool IsValid() const;
 
 223     virtual bool LoadFile(const wxString& filename);
 
 228 //---------------------------------------------------------------------------
 
 231  * wxAnimationCtrlBase
 
 232  * Abstract base class for format-specific animation controls.
 
 233  * This class implements most of the functionality; all a derived
 
 234  * class has to do is create the appropriate animation class on demand.
 
 237 // Resize to animation size if this is set
 
 238 enum { wxAN_FIT_ANIMATION };
 
 241 // class  wxAnimationCtrlBase: public wxControl
 
 244 //     %pythonAppend wxAnimationCtrlBase         "self._setOORInfo(self)"
 
 245 //     %pythonAppend wxAnimationCtrlBase()       ""
 
 247 //     wxAnimationCtrlBase(wxWindow *parent, wxWindowID id,
 
 248 //                         const wxString& filename = wxPyEmptyString,
 
 249 //                         const wxPoint& pos = wxDefaultPosition,
 
 250 //                         const wxSize& size = wxDefaultSize,
 
 251 //                         long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 252 //                         const wxString& name = wxPyAnimationControlNameStr);
 
 253 //     %RenameCtor(PreAnimationCtrlBase, wxAnimationCtrlBase());
 
 255 //     bool Create(wxWindow *parent, wxWindowID id,
 
 256 //                 const wxString& filename = wxPyEmptyString,
 
 257 //                 const wxPoint& pos = wxDefaultPosition,
 
 258 //                 const wxSize& size = wxDefaultSize,
 
 259 //                 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 260 //                 const wxString& name = wxPyAnimationControlNameStr);
 
 263 //     virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
 
 264 //     virtual bool Play(bool looped = true) ;
 
 265 //     virtual void Stop();
 
 266 //     virtual void FitToAnimation();
 
 269 //     virtual bool IsPlaying() const;
 
 270 //     virtual wxAnimationPlayer& GetPlayer();
 
 271 //     virtual wxAnimationBase* GetAnimation();
 
 273 //     const wxString& GetFilename() const;
 
 274 //     void SetFilename(const wxString& filename);
 
 281  * Provides a GIF animation class when required.
 
 284 MustHaveApp(wxGIFAnimationCtrl);
 
 285 class wxGIFAnimationCtrl: public wxControl  //wxAnimationCtrlBase
 
 288     %pythonAppend wxGIFAnimationCtrl         "self._setOORInfo(self)"
 
 289     %pythonAppend wxGIFAnimationCtrl()       ""
 
 291     wxGIFAnimationCtrl(wxWindow *parent, wxWindowID id=-1,
 
 292                        const wxString& filename = wxPyEmptyString,
 
 293                        const wxPoint& pos = wxDefaultPosition,
 
 294                        const wxSize& size = wxDefaultSize,
 
 295                        long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 296                        const wxString& name = wxPyAnimationControlNameStr);
 
 297     %RenameCtor(PreGIFAnimationCtrl, wxGIFAnimationCtrl());
 
 299     bool Create(wxWindow *parent, wxWindowID id=-1,
 
 300                 const wxString& filename = wxPyEmptyString,
 
 301                 const wxPoint& pos = wxDefaultPosition,
 
 302                 const wxSize& size = wxDefaultSize,
 
 303                 long style = wxAN_FIT_ANIMATION|wxNO_BORDER,
 
 304                 const wxString& name = wxPyAnimationControlNameStr);
 
 307     virtual bool LoadFile(const wxString& filename = wxPyEmptyString);
 
 308     virtual bool Play(bool looped = true) ;
 
 310     virtual void FitToAnimation();
 
 313     virtual bool IsPlaying() const;
 
 314     virtual wxAnimationPlayer& GetPlayer();
 
 315     virtual wxAnimationBase* GetAnimation();
 
 317     const wxString& GetFilename() const;
 
 318     void SetFilename(const wxString& filename);
 
 322 //---------------------------------------------------------------------------
 
 323 //---------------------------------------------------------------------------