]>
Commit | Line | Data |
---|---|---|
72045d57 VZ |
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 | ||
c2f12218 PC |
15 | typedef struct _GdkPixbufAnimation GdkPixbufAnimation; |
16 | typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter; | |
72045d57 VZ |
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 | ||
a4adcc43 | 27 | class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase |
72045d57 VZ |
28 | { |
29 | public: | |
70f9d2be FM |
30 | wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) |
31 | : m_pixbuf(NULL) { LoadFile(name, type); } | |
1afdfc9d | 32 | wxAnimation(GdkPixbufAnimation *p = NULL); |
c2f12218 PC |
33 | wxAnimation(const wxAnimation&); |
34 | ~wxAnimation() { UnRef(); } | |
35 | ||
36 | wxAnimation& operator= (const wxAnimation&); | |
72045d57 | 37 | |
72045d57 VZ |
38 | virtual bool IsOk() const |
39 | { return m_pixbuf != NULL; } | |
40 | ||
41 | ||
42 | // unfortunately GdkPixbufAnimation does not expose these info: | |
43 | ||
870cf35c | 44 | virtual unsigned int GetFrameCount() const { return 0; } |
a8ed16c9 | 45 | virtual wxImage GetFrame(unsigned int frame) const; |
72045d57 VZ |
46 | |
47 | // we can retrieve the delay for a frame only after building | |
48 | // a GdkPixbufAnimationIter... | |
e4161a2a | 49 | virtual int GetDelay(unsigned int WXUNUSED(frame)) const { return 0; } |
72045d57 | 50 | |
c2f12218 | 51 | virtual wxSize GetSize() const; |
72045d57 VZ |
52 | |
53 | virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
54 | virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
55 | ||
c2f12218 | 56 | // Implementation |
72045d57 VZ |
57 | public: // used by GTK callbacks |
58 | ||
59 | GdkPixbufAnimation *GetPixbuf() const | |
60 | { return m_pixbuf; } | |
c2f12218 | 61 | void SetPixbuf(GdkPixbufAnimation* p); |
72045d57 VZ |
62 | |
63 | protected: | |
64 | GdkPixbufAnimation *m_pixbuf; | |
65 | ||
c2f12218 PC |
66 | private: |
67 | void UnRef(); | |
68 | ||
69 | typedef wxAnimationBase base_type; | |
72045d57 VZ |
70 | DECLARE_DYNAMIC_CLASS(wxAnimation) |
71 | }; | |
72 | ||
73 | ||
72045d57 VZ |
74 | // ---------------------------------------------------------------------------- |
75 | // wxAnimationCtrl | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | // Resize to animation size if this is set | |
79 | #define wxAN_FIT_ANIMATION 0x0010 | |
80 | ||
81 | class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase | |
82 | { | |
83 | public: | |
05a98b6d | 84 | wxAnimationCtrl() { Init(); } |
72045d57 VZ |
85 | wxAnimationCtrl(wxWindow *parent, |
86 | wxWindowID id, | |
87 | const wxAnimation& anim = wxNullAnimation, | |
88 | const wxPoint& pos = wxDefaultPosition, | |
89 | const wxSize& size = wxDefaultSize, | |
90 | long style = wxAC_DEFAULT_STYLE, | |
91 | const wxString& name = wxAnimationCtrlNameStr) | |
92 | { | |
05a98b6d RR |
93 | Init(); |
94 | ||
72045d57 VZ |
95 | Create(parent, id, anim, pos, size, style, name); |
96 | } | |
97 | ||
98 | bool Create(wxWindow *parent, wxWindowID id, | |
99 | const wxAnimation& anim = wxNullAnimation, | |
100 | const wxPoint& pos = wxDefaultPosition, | |
101 | const wxSize& size = wxDefaultSize, | |
102 | long style = wxAC_DEFAULT_STYLE, | |
103 | const wxString& name = wxAnimationCtrlNameStr); | |
104 | ||
105 | ~wxAnimationCtrl(); | |
106 | ||
107 | public: // event handler | |
108 | ||
109 | void OnTimer(wxTimerEvent &); | |
110 | ||
111 | public: // public API | |
112 | ||
113 | virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
462167a9 | 114 | virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY); |
72045d57 VZ |
115 | |
116 | virtual void SetAnimation(const wxAnimation &anim); | |
117 | virtual wxAnimation GetAnimation() const | |
118 | { return wxAnimation(m_anim); } | |
119 | ||
120 | virtual bool Play(); | |
121 | virtual void Stop(); | |
122 | ||
123 | virtual bool IsPlaying() const; | |
124 | ||
125 | bool SetBackgroundColour( const wxColour &colour ); | |
126 | ||
127 | protected: | |
128 | ||
1bd2ceb5 | 129 | virtual void DisplayStaticImage(); |
72045d57 VZ |
130 | virtual wxSize DoGetBestSize() const; |
131 | void FitToAnimation(); | |
132 | void ClearToBackgroundColour(); | |
133 | ||
c2f12218 PC |
134 | void ResetAnim(); |
135 | void ResetIter(); | |
72045d57 VZ |
136 | |
137 | protected: // internal vars | |
138 | ||
139 | GdkPixbufAnimation *m_anim; | |
140 | GdkPixbufAnimationIter *m_iter; | |
141 | ||
142 | wxTimer m_timer; | |
143 | bool m_bPlaying; | |
144 | ||
145 | private: | |
c2f12218 | 146 | typedef wxAnimationCtrlBase base_type; |
95dc31e0 PC |
147 | |
148 | void Init(); | |
149 | ||
72045d57 VZ |
150 | DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) |
151 | DECLARE_EVENT_TABLE() | |
152 | }; | |
153 | ||
154 | #endif // _WX_GTKANIMATEH__ |