]>
Commit | Line | Data |
---|---|---|
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 | virtual bool IsOk() const | |
37 | { return m_pixbuf != NULL; } | |
38 | ||
39 | ||
40 | // unfortunately GdkPixbufAnimation does not expose these info: | |
41 | ||
42 | virtual size_t GetFrameCount() const | |
43 | { return 0; } | |
44 | virtual wxImage GetFrame(size_t i) const; | |
45 | ||
46 | // we can retrieve the delay for a frame only after building | |
47 | // a GdkPixbufAnimationIter... | |
48 | virtual int GetDelay(size_t i) const | |
49 | { return 0; } | |
50 | ||
51 | virtual wxSize GetSize() const; | |
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 | ||
56 | // Implementation | |
57 | public: // used by GTK callbacks | |
58 | ||
59 | GdkPixbufAnimation *GetPixbuf() const | |
60 | { return m_pixbuf; } | |
61 | void SetPixbuf(GdkPixbufAnimation* p); | |
62 | ||
63 | protected: | |
64 | GdkPixbufAnimation *m_pixbuf; | |
65 | ||
66 | private: | |
67 | void UnRef(); | |
68 | ||
69 | typedef wxAnimationBase base_type; | |
70 | DECLARE_DYNAMIC_CLASS(wxAnimation) | |
71 | }; | |
72 | ||
73 | ||
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: | |
84 | wxAnimationCtrl() { Init(); } | |
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 | { | |
93 | Init(); | |
94 | ||
95 | Create(parent, id, anim, pos, size, style, name); | |
96 | } | |
97 | ||
98 | void Init(); | |
99 | ||
100 | bool Create(wxWindow *parent, wxWindowID id, | |
101 | const wxAnimation& anim = wxNullAnimation, | |
102 | const wxPoint& pos = wxDefaultPosition, | |
103 | const wxSize& size = wxDefaultSize, | |
104 | long style = wxAC_DEFAULT_STYLE, | |
105 | const wxString& name = wxAnimationCtrlNameStr); | |
106 | ||
107 | ~wxAnimationCtrl(); | |
108 | ||
109 | public: // event handler | |
110 | ||
111 | void OnTimer(wxTimerEvent &); | |
112 | ||
113 | public: // public API | |
114 | ||
115 | virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
116 | ||
117 | virtual void SetAnimation(const wxAnimation &anim); | |
118 | virtual wxAnimation GetAnimation() const | |
119 | { return wxAnimation(m_anim); } | |
120 | ||
121 | virtual bool Play(); | |
122 | virtual void Stop(); | |
123 | ||
124 | virtual bool IsPlaying() const; | |
125 | ||
126 | bool SetBackgroundColour( const wxColour &colour ); | |
127 | void SetInactiveBitmap(const wxBitmap &bmp); | |
128 | ||
129 | protected: | |
130 | ||
131 | virtual wxSize DoGetBestSize() const; | |
132 | void FitToAnimation(); | |
133 | void ClearToBackgroundColour(); | |
134 | void DisplayStaticImage(); | |
135 | ||
136 | void ResetAnim(); | |
137 | void ResetIter(); | |
138 | ||
139 | protected: // internal vars | |
140 | ||
141 | GdkPixbufAnimation *m_anim; | |
142 | GdkPixbufAnimationIter *m_iter; | |
143 | ||
144 | wxTimer m_timer; | |
145 | bool m_bPlaying; | |
146 | ||
147 | private: | |
148 | typedef wxAnimationCtrlBase base_type; | |
149 | DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) | |
150 | DECLARE_EVENT_TABLE() | |
151 | }; | |
152 | ||
153 | #endif // _WX_GTKANIMATEH__ |