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
8 // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_ANIMATEH__
13 #define _WX_GENERIC_ANIMATEH__
15 #include "wx/bitmap.h"
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder
, wxAnimationDecoderList
, class WXDLLIMPEXP_ADV
);
23 class WXDLLIMPEXP_ADV wxAnimation
: public wxAnimationBase
26 virtual bool IsOk() const
27 { return m_refData
!= NULL
; }
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;
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
);
39 public: // extended interface used by the generic implementation of wxAnimationCtrl
41 wxPoint
GetFramePosition(size_t frame
) const;
42 wxSize
GetFrameSize(size_t frame
) const;
43 wxAnimationDisposal
GetDisposalMethod(size_t frame
) const;
44 wxColour
GetTransparentColour(size_t frame
) const;
45 wxColour
GetBackgroundColour() const;
48 static wxAnimationDecoderList sm_handlers
;
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
);
56 static void CleanUpHandlers();
57 static void InitStandardHandlers();
59 DECLARE_DYNAMIC_CLASS(wxAnimation
)
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 class WXDLLIMPEXP_ADV wxAnimationCtrl
: public wxAnimationCtrlBase
70 wxAnimationCtrl() { Init(); }
71 wxAnimationCtrl(wxWindow
*parent
,
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
)
81 Create(parent
, id
, anim
, pos
, size
, style
, name
);
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
);
96 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
100 { return Play(true /* looped */); }
101 virtual bool IsPlaying() const
102 { return m_isPlaying
; }
104 void SetAnimation(const wxAnimation
&animation
);
105 wxAnimation
GetAnimation() const
106 { return m_animation
; }
108 void SetInactiveBitmap(const wxBitmap
&bmp
);
110 // override base class method
111 virtual bool SetBackgroundColour(const wxColour
& col
);
113 public: // event handlers
115 void OnPaint(wxPaintEvent
& event
);
116 void OnTimer(wxTimerEvent
& event
);
117 void OnSize(wxSizeEvent
& event
);
119 public: // extended API specific to this implementation of wxAnimateCtrl
121 // Specify whether the animation's background colour is to be shown (the default),
122 // or whether the window background should show through
123 void SetUseWindowBackgroundColour(bool useWinBackground
= true)
124 { m_useWinBackgroundColour
= useWinBackground
; }
125 bool IsUsingWindowBackgroundColour() const
126 { return m_useWinBackgroundColour
; }
128 // This overload of Play() lets you specify if the animation must loop or not
129 bool Play(bool looped
);
131 // Draw the current frame of the animation into given DC.
132 // This is fast as current frame is always cached.
133 void DrawCurrentFrame(wxDC
& dc
);
135 // Returns a wxBitmap with the current frame drawn in it
136 wxBitmap
& GetBackingStore()
137 { return m_backingStore
; }
139 protected: // internal utilities
141 // resize this control to fit m_animation
142 void FitToAnimation();
144 // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal.
145 void DisposeToBackground();
146 void DisposeToBackground(wxDC
& dc
);
147 void DisposeToBackground(wxDC
& dc
, const wxPoint
&pos
, const wxSize
&sz
);
149 void UpdateBackingStoreWithStaticImage();
150 void IncrementalUpdateBackingStore();
151 bool RebuildBackingStoreUpToFrame(size_t);
152 void DrawFrame(wxDC
&dc
, size_t);
154 virtual wxSize
DoGetBestSize() const;
157 size_t m_currentFrame
; // Current frame
158 bool m_looped
; // Looped, or not
159 wxTimer m_timer
; // The timer
160 wxAnimation m_animation
; // The animation
162 bool m_isPlaying
; // Is the animation playing?
163 bool m_useWinBackgroundColour
; // Use animation bg colour or window bg colour?
165 wxBitmap m_backingStore
; // The frames are drawn here and then blitted
169 typedef wxAnimationCtrlBase base_type
;
170 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
171 DECLARE_EVENT_TABLE()
174 #endif // _WX_GENERIC_ANIMATEH__