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 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder
, wxAnimationDecoderList
, class WXDLLIMPEXP_ADV
);
21 class WXDLLIMPEXP_ADV wxAnimation
: public wxAnimationBase
24 bool operator == (const wxAnimation
& anim
) const
25 { return m_refData
== anim
.m_refData
; }
26 bool operator != (const wxAnimation
& anim
) const
27 { return m_refData
!= anim
.m_refData
; }
30 { return m_refData
!= NULL
; }
32 size_t GetFrameCount() const;
33 int GetDelay(size_t i
) const;
34 wxImage
GetFrame(size_t i
) const;
35 wxSize
GetSize() const;
37 bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
38 bool Load(wxInputStream
&stream
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
40 public: // extended interface used by the generic implementation of wxAnimationCtrl
42 wxPoint
GetFramePosition(size_t frame
) const;
43 wxAnimationDisposal
GetDisposalMethod(size_t frame
) const;
44 wxColour
GetBackgroundColour() const;
47 static wxAnimationDecoderList sm_handlers
;
50 static inline wxAnimationDecoderList
& GetHandlers() { return sm_handlers
; }
51 static void AddHandler(wxAnimationDecoder
*handler
);
52 static void InsertHandler(wxAnimationDecoder
*handler
);
53 static const wxAnimationDecoder
*FindHandler( wxAnimationType animType
);
55 static void CleanUpHandlers();
56 static void InitStandardHandlers();
58 DECLARE_DYNAMIC_CLASS(wxAnimation
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 class WXDLLIMPEXP_ADV wxAnimationCtrl
: public wxAnimationCtrlBase
70 wxAnimationCtrl(wxWindow
*parent
,
72 const wxAnimation
& anim
= wxNullAnimation
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
75 long style
= wxAC_DEFAULT_STYLE
,
76 const wxString
& name
= wxAnimationCtrlNameStr
)
78 Create(parent
, id
, anim
, pos
, size
, style
, name
);
81 bool Create(wxWindow
*parent
, wxWindowID id
,
82 const wxAnimation
& anim
= wxNullAnimation
,
83 const wxPoint
& pos
= wxDefaultPosition
,
84 const wxSize
& size
= wxDefaultSize
,
85 long style
= wxAC_DEFAULT_STYLE
,
86 const wxString
& name
= wxAnimationCtrlNameStr
);
91 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
95 { return Play(true /* looped */); }
96 virtual bool IsPlaying() const
97 { return m_isPlaying
; }
99 void SetAnimation(const wxAnimation
&animation
);
100 wxAnimation
GetAnimation() const
101 { return m_animation
; }
103 public: // event handlers
105 void OnPaint(wxPaintEvent
& event
);
106 void OnTimer(wxTimerEvent
& event
);
107 void OnSize(wxSizeEvent
& event
);
109 public: // extended API specific to this implementation of wxAnimateCtrl
111 // Specify whether the animation's background colour is to be shown (the default),
112 // or whether the window background should show through
113 void SetUseWindowBackgroundColour(bool useWinBackground
= true)
114 { m_useWinBackgroundColour
= useWinBackground
; }
115 bool IsUsingWindowBackgroundColour() const
116 { return m_useWinBackgroundColour
; }
118 // This overload of Play() lets you specify if the animation must loop or not
119 bool Play(bool looped
);
121 // Draw the current frame of the animation into given DC.
122 // This is fast as current frame is always cached.
123 void DrawCurrentFrame(wxDC
& dc
);
125 // Returns a wxBitmap with the current frame drawn in it
126 wxBitmap
& GetBackingStore()
127 { return m_backingStore
; }
129 protected: // internal utilities
131 // resize this control to fit m_animation
132 void FitToAnimation();
134 // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal.
135 void DisposeToBackground(wxDC
& dc
);
137 void IncrementalUpdateBackingStore();
138 void RebuildBackingStoreUpToFrame(size_t);
139 void DrawFrame(wxDC
&dc
, size_t);
141 virtual wxSize
DoGetBestSize() const;
144 size_t m_currentFrame
; // Current frame
145 bool m_looped
; // Looped, or not
146 wxTimer m_timer
; // The timer
147 wxAnimation m_animation
; // The animation
149 bool m_isPlaying
; // Is the animation playing?
150 bool m_useWinBackgroundColour
; // Use animation bg colour or window bg colour?
152 wxBitmap m_backingStore
; // The frames are drawn here and then blitted
156 typedef wxAnimationCtrlBase base_type
;
157 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
158 DECLARE_EVENT_TABLE()
161 #endif // _WX_GENERIC_ANIMATEH__