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