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