]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/generic/animate.h | |
3 | // Purpose: wxAnimation and wxAnimationCtrl | |
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_GENERIC_ANIMATEH__ | |
13 | #define _WX_GENERIC_ANIMATEH__ | |
14 | ||
15 | #include <wx/defs.h> | |
16 | #include <wx/string.h> | |
17 | #include <wx/gdicmn.h> | |
18 | #include <wx/list.h> | |
19 | #include <wx/timer.h> | |
20 | #include <wx/bitmap.h> | |
21 | #include <wx/colour.h> | |
22 | #include <wx/control.h> | |
23 | #include <wx/animdecod.h> | |
24 | ||
25 | class WXDLLIMPEXP_ADV wxAnimationBase; | |
26 | class WXDLLIMPEXP_ADV wxAnimationPlayer; | |
27 | class WXDLLEXPORT wxImage; | |
28 | class WXDLLEXPORT wxGIFDecoder; | |
29 | class WXDLLEXPORT wxAnimation; | |
30 | ||
31 | ||
32 | // ---------------------------------------------------------------------------- | |
33 | // wxAnimation | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | WX_DECLARE_LIST(wxAnimationDecoder, wxAnimationDecoderList); | |
37 | ||
38 | class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase | |
39 | { | |
40 | public: | |
41 | wxAnimation(const wxAnimation &tocopy) | |
42 | { Ref(tocopy); } | |
43 | wxAnimation() {} | |
44 | ~wxAnimation() { UnRef(); } | |
45 | ||
46 | wxAnimation &operator= (const wxAnimation &tocopy) | |
47 | { | |
48 | Ref(tocopy); | |
49 | return *this; | |
50 | } | |
51 | ||
52 | bool operator == (const wxAnimation& anim) const | |
53 | { return m_refData == anim.m_refData; } | |
54 | bool operator != (const wxAnimation& anim) const | |
55 | { return m_refData != anim.m_refData; } | |
56 | ||
57 | bool IsOk() const | |
58 | { return m_refData != NULL; } | |
59 | ||
60 | size_t GetFrameCount() const; | |
61 | int GetDelay(size_t i) const; | |
62 | wxImage GetFrame(size_t i) const; | |
63 | wxSize GetSize() const; | |
64 | ||
65 | bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
66 | bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
67 | ||
68 | public: // extended interface used by the generic implementation of wxAnimationCtrl | |
69 | ||
70 | wxPoint GetFramePosition(size_t frame) const; | |
71 | wxAnimationDisposal GetDisposalMethod(size_t frame) const; | |
72 | wxColour GetBackgroundColour() const; | |
73 | ||
74 | protected: | |
75 | static wxAnimationDecoderList sm_handlers; | |
76 | ||
77 | public: | |
78 | static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; } | |
79 | static void AddHandler(wxAnimationDecoder *handler); | |
80 | static void InsertHandler(wxAnimationDecoder *handler); | |
81 | static const wxAnimationDecoder *FindHandler( wxAnimationType animType ); | |
82 | ||
83 | static void CleanUpHandlers(); | |
84 | static void InitStandardHandlers(); | |
85 | ||
86 | protected: | |
87 | DECLARE_DYNAMIC_CLASS(wxAnimation) | |
88 | }; | |
89 | ||
90 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // wxAnimationCtrl | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase | |
96 | { | |
97 | public: | |
98 | wxAnimationCtrl() {} | |
99 | wxAnimationCtrl(wxWindow *parent, | |
100 | 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 | Create(parent, id, anim, pos, size, style, name); | |
108 | } | |
109 | ||
110 | bool Create(wxWindow *parent, wxWindowID id, | |
111 | const wxAnimation& anim = wxNullAnimation, | |
112 | const wxPoint& pos = wxDefaultPosition, | |
113 | const wxSize& size = wxDefaultSize, | |
114 | long style = wxAC_DEFAULT_STYLE, | |
115 | const wxString& name = wxAnimationCtrlNameStr); | |
116 | ||
117 | ~wxAnimationCtrl(); | |
118 | ||
119 | public: | |
120 | virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY); | |
121 | ||
122 | virtual void Stop(); | |
123 | virtual bool Play() | |
124 | { return Play(true /* looped */); } | |
125 | virtual bool IsPlaying() const | |
126 | { return m_isPlaying; } | |
127 | ||
128 | void SetAnimation(const wxAnimation &animation); | |
129 | wxAnimation GetAnimation() const | |
130 | { return m_animation; } | |
131 | ||
132 | public: // event handlers | |
133 | ||
134 | void OnPaint(wxPaintEvent& event); | |
135 | void OnTimer(wxTimerEvent& event); | |
136 | void OnSize(wxSizeEvent& event); | |
137 | ||
138 | public: // extended API specific to this implementation of wxAnimateCtrl | |
139 | ||
140 | // Specify whether the animation's background colour is to be shown (the default), | |
141 | // or whether the window background should show through | |
142 | void SetUseWindowBackgroundColour(bool useWinBackground = true) | |
143 | { m_useWinBackgroundColour = useWinBackground; } | |
144 | bool IsUsingWindowBackgroundColour() const | |
145 | { return m_useWinBackgroundColour; } | |
146 | ||
147 | // This overload of Play() lets you specify if the animation must loop or not | |
148 | bool Play(bool looped); | |
149 | ||
150 | // Draw the current frame of the animation into given DC. | |
151 | // This is fast as current frame is always cached. | |
152 | void DrawCurrentFrame(wxDC& dc); | |
153 | ||
154 | // Returns a wxBitmap with the current frame drawn in it | |
155 | wxBitmap& GetBackingStore() | |
156 | { return m_backingStore; } | |
157 | ||
158 | protected: // internal utilities | |
159 | ||
160 | // resize this control to fit m_animation | |
161 | void FitToAnimation(); | |
162 | ||
163 | // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal. | |
164 | void DisposeToBackground(wxDC& dc); | |
165 | ||
166 | void IncrementalUpdateBackingStore(); | |
167 | void RebuildBackingStoreUpToFrame(size_t); | |
168 | void DrawFrame(wxDC &dc, size_t); | |
169 | ||
170 | virtual wxSize DoGetBestSize() const; | |
171 | ||
172 | protected: | |
173 | size_t m_currentFrame; // Current frame | |
174 | bool m_looped; // Looped, or not | |
175 | wxTimer m_timer; // The timer | |
176 | wxAnimation m_animation; // The animation | |
177 | ||
178 | bool m_isPlaying; // Is the animation playing? | |
179 | bool m_useWinBackgroundColour; // Use animation bg colour or window bg colour? | |
180 | ||
181 | wxBitmap m_backingStore; // The frames are drawn here and then blitted | |
182 | // on the screen | |
183 | ||
184 | private: | |
185 | DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) | |
186 | DECLARE_EVENT_TABLE() | |
187 | }; | |
188 | ||
189 | #endif // _WX_GENERIC_ANIMATEH__ |