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