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 unsigned int GetFrameCount() const;
30 virtual int GetDelay(unsigned int i
) const;
31 virtual wxImage
GetFrame(unsigned int 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 // extended interface used by the generic implementation of wxAnimationCtrl
40 wxPoint
GetFramePosition(unsigned int frame
) const;
41 wxSize
GetFrameSize(unsigned int frame
) const;
42 wxAnimationDisposal
GetDisposalMethod(unsigned int frame
) const;
43 wxColour
GetTransparentColour(unsigned int 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
69 wxAnimationCtrl() { Init(); }
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
)
80 Create(parent
, id
, anim
, pos
, size
, style
, name
);
85 bool Create(wxWindow
*parent
, wxWindowID id
,
86 const wxAnimation
& anim
= wxNullAnimation
,
87 const wxPoint
& pos
= wxDefaultPosition
,
88 const wxSize
& size
= wxDefaultSize
,
89 long style
= wxAC_DEFAULT_STYLE
,
90 const wxString
& name
= wxAnimationCtrlNameStr
);
95 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
99 { return Play(true /* looped */); }
100 virtual bool IsPlaying() const
101 { return m_isPlaying
; }
103 void SetAnimation(const wxAnimation
&animation
);
104 wxAnimation
GetAnimation() const
105 { return m_animation
; }
107 virtual void SetInactiveBitmap(const wxBitmap
&bmp
);
109 // override base class method
110 virtual bool SetBackgroundColour(const wxColour
& col
);
112 public: // event handlers
114 void OnPaint(wxPaintEvent
& event
);
115 void OnTimer(wxTimerEvent
& event
);
116 void OnSize(wxSizeEvent
& event
);
118 public: // extended API specific to this implementation of wxAnimateCtrl
120 // Specify whether the animation's background colour is to be shown (the default),
121 // or whether the window background should show through
122 void SetUseWindowBackgroundColour(bool useWinBackground
= true)
123 { m_useWinBackgroundColour
= useWinBackground
; }
124 bool IsUsingWindowBackgroundColour() const
125 { return m_useWinBackgroundColour
; }
127 // This overload of Play() lets you specify if the animation must loop or not
128 bool Play(bool looped
);
130 // Draw the current frame of the animation into given DC.
131 // This is fast as current frame is always cached.
132 void DrawCurrentFrame(wxDC
& dc
);
134 // Returns a wxBitmap with the current frame drawn in it
135 wxBitmap
& GetBackingStore()
136 { return m_backingStore
; }
138 protected: // internal utilities
140 // resize this control to fit m_animation
141 void FitToAnimation();
143 // Draw the background; use this when e.g. previous frame had wxANIM_TOBACKGROUND disposal.
144 void DisposeToBackground();
145 void DisposeToBackground(wxDC
& dc
);
146 void DisposeToBackground(wxDC
& dc
, const wxPoint
&pos
, const wxSize
&sz
);
148 void IncrementalUpdateBackingStore();
149 bool RebuildBackingStoreUpToFrame(unsigned int);
150 void DrawFrame(wxDC
&dc
, unsigned int);
152 virtual void DisplayStaticImage();
153 virtual wxSize
DoGetBestSize() const;
156 unsigned int m_currentFrame
; // Current frame
157 bool m_looped
; // Looped, or not
158 wxTimer m_timer
; // The timer
159 wxAnimation m_animation
; // The animation
161 bool m_isPlaying
; // Is the animation playing?
162 bool m_useWinBackgroundColour
; // Use animation bg colour or window bg colour?
164 wxBitmap m_backingStore
; // The frames are drawn here and then blitted
168 typedef wxAnimationCtrlBase base_type
;
169 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
170 DECLARE_EVENT_TABLE()
173 #endif // _WX_GENERIC_ANIMATEH__