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
7 // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERIC_ANIMATEH__
12 #define _WX_GENERIC_ANIMATEH__
14 #include "wx/bitmap.h"
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder
, wxAnimationDecoderList
, class WXDLLIMPEXP_ADV
);
22 class WXDLLIMPEXP_ADV wxAnimation
: public wxAnimationBase
26 wxAnimation(const wxString
&name
, wxAnimationType type
= wxANIMATION_TYPE_ANY
)
27 { LoadFile(name
, type
); }
29 virtual bool IsOk() const
30 { return m_refData
!= NULL
; }
32 virtual unsigned int GetFrameCount() const;
33 virtual int GetDelay(unsigned int i
) const;
34 virtual wxImage
GetFrame(unsigned int i
) const;
35 virtual wxSize
GetSize() const;
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
);
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;
47 wxColour
GetBackgroundColour() const;
50 static wxAnimationDecoderList sm_handlers
;
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
);
58 static void CleanUpHandlers();
59 static void InitStandardHandlers();
61 DECLARE_DYNAMIC_CLASS(wxAnimation
)
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 class WXDLLIMPEXP_ADV wxAnimationCtrl
: public wxAnimationCtrlBase
72 wxAnimationCtrl() { Init(); }
73 wxAnimationCtrl(wxWindow
*parent
,
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
)
83 Create(parent
, id
, anim
, pos
, size
, style
, name
);
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
);
98 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
99 virtual bool Load(wxInputStream
& stream
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
103 { return Play(true /* looped */); }
104 virtual bool IsPlaying() const
105 { return m_isPlaying
; }
107 void SetAnimation(const wxAnimation
&animation
);
108 wxAnimation
GetAnimation() const
109 { return m_animation
; }
111 virtual void SetInactiveBitmap(const wxBitmap
&bmp
);
113 // override base class method
114 virtual bool SetBackgroundColour(const wxColour
& col
);
116 public: // event handlers
118 void OnPaint(wxPaintEvent
& event
);
119 void OnTimer(wxTimerEvent
& event
);
120 void OnSize(wxSizeEvent
& event
);
122 public: // extended API specific to this implementation of wxAnimateCtrl
124 // Specify whether the animation's background colour is to be shown (the default),
125 // or whether the window background should show through
126 void SetUseWindowBackgroundColour(bool useWinBackground
= true)
127 { m_useWinBackgroundColour
= useWinBackground
; }
128 bool IsUsingWindowBackgroundColour() const
129 { return m_useWinBackgroundColour
; }
131 // This overload of Play() lets you specify if the animation must loop or not
132 bool Play(bool looped
);
134 // Draw the current frame of the animation into given DC.
135 // This is fast as current frame is always cached.
136 void DrawCurrentFrame(wxDC
& dc
);
138 // Returns a wxBitmap with the current frame drawn in it
139 wxBitmap
& GetBackingStore()
140 { return m_backingStore
; }
142 protected: // internal utilities
144 // resize this control to fit m_animation
145 void FitToAnimation();
147 // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal.
148 void DisposeToBackground();
149 void DisposeToBackground(wxDC
& dc
);
150 void DisposeToBackground(wxDC
& dc
, const wxPoint
&pos
, const wxSize
&sz
);
152 void IncrementalUpdateBackingStore();
153 bool RebuildBackingStoreUpToFrame(unsigned int);
154 void DrawFrame(wxDC
&dc
, unsigned int);
156 virtual void DisplayStaticImage();
157 virtual wxSize
DoGetBestSize() const;
160 unsigned int m_currentFrame
; // Current frame
161 bool m_looped
; // Looped, or not
162 wxTimer m_timer
; // The timer
163 wxAnimation m_animation
; // The animation
165 bool m_isPlaying
; // Is the animation playing?
166 bool m_useWinBackgroundColour
; // Use animation bg colour or window bg colour?
168 wxBitmap m_backingStore
; // The frames are drawn here and then blitted
172 typedef wxAnimationCtrlBase base_type
;
173 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
174 DECLARE_EVENT_TABLE()
177 #endif // _WX_GENERIC_ANIMATEH__