1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/gtk/animate.h 3 // Purpose: Animation classes 4 // Author: Julian Smart and Guillermo Rodriguez Garcia 5 // Modified by: Francesco Montorsi 6 // Created: 13/8/99 7 // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_GTKANIMATEH__ 12 #define _WX_GTKANIMATEH__ 13 14 typedef struct _GdkPixbufAnimation GdkPixbufAnimation; 15 typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter; 16 17 // ---------------------------------------------------------------------------- 18 // wxAnimation 19 // Unlike the generic wxAnimation object (see generic\animate.cpp), we won't 20 // use directly wxAnimationHandlers as gdk-pixbuf already provides the 21 // concept of handler and will automatically use the available handlers. 22 // Like generic wxAnimation object, this implementation of wxAnimation is 23 // refcounted so that assignment is very fast 24 // ---------------------------------------------------------------------------- 25 26 class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase 27 { 28 public: 29 wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) m_pixbuf(NULL)30 : m_pixbuf(NULL) { LoadFile(name, type); } 31 wxAnimation(GdkPixbufAnimation *p = NULL); 32 wxAnimation(const wxAnimation&); ~wxAnimation()33 ~wxAnimation() { UnRef(); } 34 35 wxAnimation& operator= (const wxAnimation&); 36 IsOk()37 virtual bool IsOk() const 38 { return m_pixbuf != NULL; } 39 40 41 // unfortunately GdkPixbufAnimation does not expose these info: 42 GetFrameCount()43 virtual unsigned int GetFrameCount() const { return 0; } 44 virtual wxImage GetFrame(unsigned int frame) const; 45 46 // we can retrieve the delay for a frame only after building 47 // a GdkPixbufAnimationIter... GetDelay(unsigned int WXUNUSED (frame))48 virtual int GetDelay(unsigned int WXUNUSED(frame)) const { return 0; } 49 50 virtual wxSize GetSize() const; 51 52 virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY); 53 virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY); 54 55 // Implementation 56 public: // used by GTK callbacks 57 GetPixbuf()58 GdkPixbufAnimation *GetPixbuf() const 59 { return m_pixbuf; } 60 void SetPixbuf(GdkPixbufAnimation* p); 61 62 protected: 63 GdkPixbufAnimation *m_pixbuf; 64 65 private: 66 void UnRef(); 67 68 typedef wxAnimationBase base_type; 69 DECLARE_DYNAMIC_CLASS(wxAnimation) 70 }; 71 72 73 // ---------------------------------------------------------------------------- 74 // wxAnimationCtrl 75 // ---------------------------------------------------------------------------- 76 77 // Resize to animation size if this is set 78 #define wxAN_FIT_ANIMATION 0x0010 79 80 class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase 81 { 82 public: wxAnimationCtrl()83 wxAnimationCtrl() { Init(); } 84 wxAnimationCtrl(wxWindow *parent, 85 wxWindowID id, 86 const wxAnimation& anim = wxNullAnimation, 87 const wxPoint& pos = wxDefaultPosition, 88 const wxSize& size = wxDefaultSize, 89 long style = wxAC_DEFAULT_STYLE, 90 const wxString& name = wxAnimationCtrlNameStr) 91 { 92 Init(); 93 94 Create(parent, id, anim, pos, size, style, name); 95 } 96 97 bool Create(wxWindow *parent, wxWindowID id, 98 const wxAnimation& anim = wxNullAnimation, 99 const wxPoint& pos = wxDefaultPosition, 100 const wxSize& size = wxDefaultSize, 101 long style = wxAC_DEFAULT_STYLE, 102 const wxString& name = wxAnimationCtrlNameStr); 103 104 ~wxAnimationCtrl(); 105 106 public: // event handler 107 108 void OnTimer(wxTimerEvent &); 109 110 public: // public API 111 112 virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY); 113 virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY); 114 115 virtual void SetAnimation(const wxAnimation &anim); GetAnimation()116 virtual wxAnimation GetAnimation() const 117 { return wxAnimation(m_anim); } 118 119 virtual bool Play(); 120 virtual void Stop(); 121 122 virtual bool IsPlaying() const; 123 124 bool SetBackgroundColour( const wxColour &colour ); 125 126 protected: 127 128 virtual void DisplayStaticImage(); 129 virtual wxSize DoGetBestSize() const; 130 void FitToAnimation(); 131 void ClearToBackgroundColour(); 132 133 void ResetAnim(); 134 void ResetIter(); 135 136 protected: // internal vars 137 138 GdkPixbufAnimation *m_anim; 139 GdkPixbufAnimationIter *m_iter; 140 141 wxTimer m_timer; 142 bool m_bPlaying; 143 144 private: 145 typedef wxAnimationCtrlBase base_type; 146 147 void Init(); 148 149 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) 150 DECLARE_EVENT_TABLE() 151 }; 152 153 #endif // _WX_GTKANIMATEH__ 154