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 bool operator == (const wxAnimation
& anim
) const
27 { return m_refData
== anim
.m_refData
; }
28 bool operator != (const wxAnimation
& anim
) const
29 { return m_refData
!= anim
.m_refData
; }
32 { return m_refData
!= NULL
; }
34 size_t GetFrameCount() const;
35 int GetDelay(size_t i
) const;
36 wxImage
GetFrame(size_t i
) const;
37 wxSize
GetSize() const;
39 bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
40 bool Load(wxInputStream
&stream
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
42 public: // extended interface used by the generic implementation of wxAnimationCtrl
44 wxPoint
GetFramePosition(size_t frame
) const;
45 wxAnimationDisposal
GetDisposalMethod(size_t frame
) const;
46 wxColour
GetBackgroundColour() const;
49 static wxAnimationDecoderList sm_handlers
;
52 static inline wxAnimationDecoderList
& GetHandlers() { return sm_handlers
; }
53 static void AddHandler(wxAnimationDecoder
*handler
);
54 static void InsertHandler(wxAnimationDecoder
*handler
);
55 static const wxAnimationDecoder
*FindHandler( wxAnimationType animType
);
57 static void CleanUpHandlers();
58 static void InitStandardHandlers();
60 DECLARE_DYNAMIC_CLASS(wxAnimation
)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 class WXDLLIMPEXP_ADV wxAnimationCtrl
: public wxAnimationCtrlBase
72 wxAnimationCtrl(wxWindow
*parent
,
74 const wxAnimation
& anim
= wxNullAnimation
,
75 const wxPoint
& pos
= wxDefaultPosition
,
76 const wxSize
& size
= wxDefaultSize
,
77 long style
= wxAC_DEFAULT_STYLE
,
78 const wxString
& name
= wxAnimationCtrlNameStr
)
80 Create(parent
, id
, anim
, pos
, size
, style
, name
);
83 bool Create(wxWindow
*parent
, wxWindowID id
,
84 const wxAnimation
& anim
= wxNullAnimation
,
85 const wxPoint
& pos
= wxDefaultPosition
,
86 const wxSize
& size
= wxDefaultSize
,
87 long style
= wxAC_DEFAULT_STYLE
,
88 const wxString
& name
= wxAnimationCtrlNameStr
);
93 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
97 { return Play(true /* looped */); }
98 virtual bool IsPlaying() const
99 { return m_isPlaying
; }
101 void SetAnimation(const wxAnimation
&animation
);
102 wxAnimation
GetAnimation() const
103 { return m_animation
; }
105 public: // event handlers
107 void OnPaint(wxPaintEvent
& event
);
108 void OnTimer(wxTimerEvent
& event
);
109 void OnSize(wxSizeEvent
& event
);
111 public: // extended API specific to this implementation of wxAnimateCtrl
113 // Specify whether the animation's background colour is to be shown (the default),
114 // or whether the window background should show through
115 void SetUseWindowBackgroundColour(bool useWinBackground
= true)
116 { m_useWinBackgroundColour
= useWinBackground
; }
117 bool IsUsingWindowBackgroundColour() const
118 { return m_useWinBackgroundColour
; }
120 // This overload of Play() lets you specify if the animation must loop or not
121 bool Play(bool looped
);
123 // Draw the current frame of the animation into given DC.
124 // This is fast as current frame is always cached.
125 void DrawCurrentFrame(wxDC
& dc
);
127 // Returns a wxBitmap with the current frame drawn in it
128 wxBitmap
& GetBackingStore()
129 { return m_backingStore
; }
131 protected: // internal utilities
133 // resize this control to fit m_animation
134 void FitToAnimation();
136 // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal.
137 void DisposeToBackground(wxDC
& dc
);
139 void IncrementalUpdateBackingStore();
140 void RebuildBackingStoreUpToFrame(size_t);
141 void DrawFrame(wxDC
&dc
, size_t);
143 virtual wxSize
DoGetBestSize() const;
146 size_t m_currentFrame
; // Current frame
147 bool m_looped
; // Looped, or not
148 wxTimer m_timer
; // The timer
149 wxAnimation m_animation
; // The animation
151 bool m_isPlaying
; // Is the animation playing?
152 bool m_useWinBackgroundColour
; // Use animation bg colour or window bg colour?
154 wxBitmap m_backingStore
; // The frames are drawn here and then blitted
158 typedef wxAnimationCtrlBase base_type
;
159 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
160 DECLARE_EVENT_TABLE()
163 #endif // _WX_GENERIC_ANIMATEH__