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