1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/animate.h
3 // Purpose: Animation classes
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_GTKANIMATEH__
13 #define _WX_GTKANIMATEH__
16 #include <gdk-pixbuf/gdk-pixbuf.h>
18 // ----------------------------------------------------------------------------
20 // Unlike the generic wxAnimation object (see generic\animate.cpp), we won't
21 // use directly wxAnimationHandlers as gdk-pixbuf already provides the
22 // concept of handler and will automatically use the available handlers.
23 // Like generic wxAnimation object, this implementation of wxAnimation is
24 // refcounted so that assignment is very fast
25 // ----------------------------------------------------------------------------
27 class WXDLLEXPORT wxAnimation
: public wxAnimationBase
30 wxAnimation(const wxAnimation
&tocopy
)
31 { m_pixbuf
=tocopy
.m_pixbuf
; if (m_pixbuf
) g_object_ref(m_pixbuf
); }
32 wxAnimation(GdkPixbufAnimation
*p
= NULL
)
37 wxAnimation
&operator= (const wxAnimation
&tocopy
)
39 m_pixbuf
=tocopy
.m_pixbuf
;
40 if (m_pixbuf
) g_object_ref(m_pixbuf
);
44 bool operator == (const wxAnimation
& anim
) const
45 { return m_pixbuf
== anim
.m_pixbuf
; }
46 bool operator != (const wxAnimation
& anim
) const
47 { return m_pixbuf
!= anim
.m_pixbuf
; }
49 virtual bool IsOk() const
50 { return m_pixbuf
!= NULL
; }
53 // unfortunately GdkPixbufAnimation does not expose these info:
55 virtual size_t GetFrameCount() const
57 virtual wxImage
GetFrame(size_t i
) const
58 { return wxNullImage
; }
60 // we can retrieve the delay for a frame only after building
61 // a GdkPixbufAnimationIter...
62 virtual int GetDelay(size_t i
) const
65 virtual wxSize
GetSize() const
66 { return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf
),
67 gdk_pixbuf_animation_get_height(m_pixbuf
)); }
69 virtual bool LoadFile(const wxString
&name
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
70 virtual bool Load(wxInputStream
&stream
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
75 g_object_unref(m_pixbuf
);
79 public: // used by GTK callbacks
81 GdkPixbufAnimation
*GetPixbuf() const
83 void SetPixbuf(GdkPixbufAnimation
*p
)
84 { m_pixbuf
=p
; if (m_pixbuf
) g_object_ref(m_pixbuf
); }
87 GdkPixbufAnimation
*m_pixbuf
;
89 // used temporary by Load()
90 //bool m_bLoadComplete;
93 DECLARE_DYNAMIC_CLASS(wxAnimation
)
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 // Resize to animation size if this is set
103 #define wxAN_FIT_ANIMATION 0x0010
105 class WXDLLIMPEXP_ADV wxAnimationCtrl
: public wxAnimationCtrlBase
109 wxAnimationCtrl(wxWindow
*parent
,
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
)
117 Create(parent
, id
, anim
, pos
, size
, style
, name
);
120 bool Create(wxWindow
*parent
, wxWindowID id
,
121 const wxAnimation
& anim
= wxNullAnimation
,
122 const wxPoint
& pos
= wxDefaultPosition
,
123 const wxSize
& size
= wxDefaultSize
,
124 long style
= wxAC_DEFAULT_STYLE
,
125 const wxString
& name
= wxAnimationCtrlNameStr
);
129 public: // event handler
131 void OnTimer(wxTimerEvent
&);
133 public: // public API
135 virtual bool LoadFile(const wxString
& filename
, wxAnimationType type
= wxANIMATION_TYPE_ANY
);
137 virtual void SetAnimation(const wxAnimation
&anim
);
138 virtual wxAnimation
GetAnimation() const
139 { return wxAnimation(m_anim
); }
144 virtual bool IsPlaying() const;
146 bool SetBackgroundColour( const wxColour
&colour
);
150 virtual wxSize
DoGetBestSize() const;
151 void FitToAnimation();
152 void ClearToBackgroundColour();
157 g_object_unref(m_anim
);
164 g_object_unref(m_iter
);
168 protected: // internal vars
170 GdkPixbufAnimation
*m_anim
;
171 GdkPixbufAnimationIter
*m_iter
;
177 DECLARE_DYNAMIC_CLASS(wxAnimationCtrl
)
178 DECLARE_EVENT_TABLE()
181 #endif // _WX_GTKANIMATEH__