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