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