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__
16 #include <wx/string.h>
17 #include <wx/gdicmn.h>
20 #include <wx/bitmap.h>
21 #include <wx/colour.h>
22 #include <wx/control.h>
23 #include <wx/animdecod.h>
25 class WXDLLIMPEXP_ADV wxAnimationBase
;
26 class WXDLLIMPEXP_ADV wxAnimationPlayer
;
27 class WXDLLEXPORT wxImage
;
28 class WXDLLEXPORT wxGIFDecoder
;
29 class WXDLLIMPEXP_ADV wxAnimation
;
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 WX_DECLARE_LIST(wxAnimationDecoder
, wxAnimationDecoderList
);
38 class WXDLLIMPEXP_ADV wxAnimation
: public wxAnimationBase
41 wxAnimation(const wxAnimation
&tocopy
)
44 ~wxAnimation() { UnRef(); }
46 wxAnimation
&operator= (const wxAnimation
&tocopy
)
52 bool operator == (const wxAnimation
& anim
) const
53 { return m_refData
== anim
.m_refData
; }
54 bool operator != (const wxAnimation
& anim
) const
55 { return m_refData
!= anim
.m_refData
; }
58 { return m_refData
!= NULL
; }
60 size_t GetFrameCount() const;
61 int GetDelay(size_t i
) const;
62 wxImage
GetFrame(size_t i
) const;
63 wxSize
GetSize() const;
65 bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
66 bool Load(wxInputStream
&stream
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
68 public: // extended interface used by the generic implementation of wxAnimationCtrl
70 wxPoint
GetFramePosition(size_t frame
) const;
71 wxAnimationDisposal
GetDisposalMethod(size_t frame
) const;
72 wxColour
GetBackgroundColour() const;
75 static wxAnimationDecoderList sm_handlers
;
78 static inline wxAnimationDecoderList
& GetHandlers() { return sm_handlers
; }
79 static void AddHandler(wxAnimationDecoder
*handler
);
80 static void InsertHandler(wxAnimationDecoder
*handler
);
81 static const wxAnimationDecoder
*FindHandler( wxAnimationType animType
);
83 static void CleanUpHandlers();
84 static void InitStandardHandlers();
87 DECLARE_DYNAMIC_CLASS(wxAnimation
)
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 class WXDLLIMPEXP_ADV wxAnimationCtrl
: public wxAnimationCtrlBase
99 wxAnimationCtrl(wxWindow
*parent
,
101 const wxAnimation
& anim
= wxNullAnimation
,
102 const wxPoint
& pos
= wxDefaultPosition
,
103 const wxSize
& size
= wxDefaultSize
,
104 long style
= wxAC_DEFAULT_STYLE
,
105 const wxString
& name
= wxAnimationCtrlNameStr
)
107 Create(parent
, id
, anim
, pos
, size
, style
, name
);
110 bool Create(wxWindow
*parent
, wxWindowID id
,
111 const wxAnimation
& anim
= wxNullAnimation
,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
114 long style
= wxAC_DEFAULT_STYLE
,
115 const wxString
& name
= wxAnimationCtrlNameStr
);
120 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
124 { return Play(true /* looped */); }
125 virtual bool IsPlaying() const
126 { return m_isPlaying
; }
128 void SetAnimation(const wxAnimation
&animation
);
129 wxAnimation
GetAnimation() const
130 { return m_animation
; }
132 public: // event handlers
134 void OnPaint(wxPaintEvent
& event
);
135 void OnTimer(wxTimerEvent
& event
);
136 void OnSize(wxSizeEvent
& event
);
138 public: // extended API specific to this implementation of wxAnimateCtrl
140 // Specify whether the animation's background colour is to be shown (the default),
141 // or whether the window background should show through
142 void SetUseWindowBackgroundColour(bool useWinBackground
= true)
143 { m_useWinBackgroundColour
= useWinBackground
; }
144 bool IsUsingWindowBackgroundColour() const
145 { return m_useWinBackgroundColour
; }
147 // This overload of Play() lets you specify if the animation must loop or not
148 bool Play(bool looped
);
150 // Draw the current frame of the animation into given DC.
151 // This is fast as current frame is always cached.
152 void DrawCurrentFrame(wxDC
& dc
);
154 // Returns a wxBitmap with the current frame drawn in it
155 wxBitmap
& GetBackingStore()
156 { return m_backingStore
; }
158 protected: // internal utilities
160 // resize this control to fit m_animation
161 void FitToAnimation();
163 // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal.
164 void DisposeToBackground(wxDC
& dc
);
166 void IncrementalUpdateBackingStore();
167 void RebuildBackingStoreUpToFrame(size_t);
168 void DrawFrame(wxDC
&dc
, size_t);
170 virtual wxSize
DoGetBestSize() const;
173 size_t m_currentFrame
; // Current frame
174 bool m_looped
; // Looped, or not
175 wxTimer m_timer
; // The timer
176 wxAnimation m_animation
; // The animation
178 bool m_isPlaying
; // Is the animation playing?
179 bool m_useWinBackgroundColour
; // Use animation bg colour or window bg colour?
181 wxBitmap m_backingStore
; // The frames are drawn here and then blitted
185 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
186 DECLARE_EVENT_TABLE()
189 #endif // _WX_GENERIC_ANIMATEH__