]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/animate.h
implement {Create,Clone}RefData for gtk wxBitmap
[wxWidgets.git] / include / wx / gtk / animate.h
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$
8 // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GTKANIMATEH__
13 #define _WX_GTKANIMATEH__
14
15 typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
16 typedef 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
27 class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
28 {
29 public:
30 wxAnimation(GdkPixbufAnimation *p = NULL) { m_pixbuf = p; }
31 wxAnimation(const wxAnimation&);
32 ~wxAnimation() { UnRef(); }
33
34 wxAnimation& operator= (const wxAnimation&);
35
36 bool operator == (const wxAnimation& anim) const
37 { return m_pixbuf == anim.m_pixbuf; }
38 bool operator != (const wxAnimation& anim) const
39 { return m_pixbuf != anim.m_pixbuf; }
40
41 virtual bool IsOk() const
42 { return m_pixbuf != NULL; }
43
44
45 // unfortunately GdkPixbufAnimation does not expose these info:
46
47 virtual size_t GetFrameCount() const
48 { return 0; }
49 virtual wxImage GetFrame(size_t i) const;
50
51 // we can retrieve the delay for a frame only after building
52 // a GdkPixbufAnimationIter...
53 virtual int GetDelay(size_t i) const
54 { return 0; }
55
56 virtual wxSize GetSize() const;
57
58 virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
59 virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
60
61 // Implementation
62 public: // used by GTK callbacks
63
64 GdkPixbufAnimation *GetPixbuf() const
65 { return m_pixbuf; }
66 void SetPixbuf(GdkPixbufAnimation* p);
67
68 protected:
69 GdkPixbufAnimation *m_pixbuf;
70
71 // used temporary by Load()
72 //bool m_bLoadComplete;
73
74 private:
75 void UnRef();
76
77 typedef wxAnimationBase base_type;
78 DECLARE_DYNAMIC_CLASS(wxAnimation)
79 };
80
81
82 // ----------------------------------------------------------------------------
83 // wxAnimationCtrl
84 // ----------------------------------------------------------------------------
85
86 // Resize to animation size if this is set
87 #define wxAN_FIT_ANIMATION 0x0010
88
89 class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase
90 {
91 public:
92 wxAnimationCtrl() { Init(); }
93 wxAnimationCtrl(wxWindow *parent,
94 wxWindowID id,
95 const wxAnimation& anim = wxNullAnimation,
96 const wxPoint& pos = wxDefaultPosition,
97 const wxSize& size = wxDefaultSize,
98 long style = wxAC_DEFAULT_STYLE,
99 const wxString& name = wxAnimationCtrlNameStr)
100 {
101 Init();
102
103 Create(parent, id, anim, pos, size, style, name);
104 }
105
106 void Init();
107
108 bool Create(wxWindow *parent, wxWindowID id,
109 const wxAnimation& anim = wxNullAnimation,
110 const wxPoint& pos = wxDefaultPosition,
111 const wxSize& size = wxDefaultSize,
112 long style = wxAC_DEFAULT_STYLE,
113 const wxString& name = wxAnimationCtrlNameStr);
114
115 ~wxAnimationCtrl();
116
117 public: // event handler
118
119 void OnTimer(wxTimerEvent &);
120
121 public: // public API
122
123 virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY);
124
125 virtual void SetAnimation(const wxAnimation &anim);
126 virtual wxAnimation GetAnimation() const
127 { return wxAnimation(m_anim); }
128
129 virtual bool Play();
130 virtual void Stop();
131
132 virtual bool IsPlaying() const;
133
134 bool SetBackgroundColour( const wxColour &colour );
135
136 protected:
137
138 virtual wxSize DoGetBestSize() const;
139 void FitToAnimation();
140 void ClearToBackgroundColour();
141
142 void ResetAnim();
143 void ResetIter();
144
145 protected: // internal vars
146
147 GdkPixbufAnimation *m_anim;
148 GdkPixbufAnimationIter *m_iter;
149
150 wxTimer m_timer;
151 bool m_bPlaying;
152
153 private:
154 typedef wxAnimationCtrlBase base_type;
155 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl)
156 DECLARE_EVENT_TABLE()
157 };
158
159 #endif // _WX_GTKANIMATEH__