Update GTK animation classes for the new pattern
This commit is contained in:
@@ -23,16 +23,21 @@ typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter;
|
||||
// refcounted so that assignment is very fast
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
|
||||
class WXDLLIMPEXP_ADV wxAnimationGTKImpl : public wxAnimationImpl
|
||||
{
|
||||
public:
|
||||
wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
|
||||
: m_pixbuf(NULL) { LoadFile(name, type); }
|
||||
wxAnimation(GdkPixbufAnimation *p = NULL);
|
||||
wxAnimation(const wxAnimation&);
|
||||
~wxAnimation() { UnRef(); }
|
||||
wxAnimationGTKImpl()
|
||||
: m_pixbuf(NULL) {}
|
||||
// wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
|
||||
// : m_pixbuf(NULL) { LoadFile(name, type); }
|
||||
// wxAnimation(GdkPixbufAnimation *p = NULL);
|
||||
// wxAnimation(const wxAnimation&);
|
||||
~wxAnimationGTKImpl() { UnRef(); }
|
||||
|
||||
wxAnimation& operator= (const wxAnimation&);
|
||||
// wxAnimation& operator= (const wxAnimation&);
|
||||
|
||||
virtual wxAnimationImplType GetImplType() wxOVERRIDE
|
||||
{ return wxANIMATION_IMPL_TYPE_NATIVE; }
|
||||
|
||||
virtual bool IsOk() const wxOVERRIDE
|
||||
{ return m_pixbuf != NULL; }
|
||||
@@ -52,16 +57,6 @@ public:
|
||||
{ return 0; }
|
||||
virtual wxImage GetFrame(unsigned int WXUNUSED(frame)) const wxOVERRIDE
|
||||
{ return wxNullImage; }
|
||||
virtual wxPoint GetFramePosition(unsigned int WXUNUSED(frame)) const wxOVERRIDE
|
||||
{ return wxDefaultPosition; }
|
||||
virtual wxSize GetFrameSize(unsigned int WXUNUSED(frame)) const wxOVERRIDE
|
||||
{ return wxDefaultSize; }
|
||||
virtual wxAnimationDisposal GetDisposalMethod(unsigned int WXUNUSED(frame)) const wxOVERRIDE
|
||||
{ return wxANIM_UNSPECIFIED; }
|
||||
virtual wxColour GetTransparentColour(unsigned int WXUNUSED(frame)) const wxOVERRIDE
|
||||
{ return wxNullColour; }
|
||||
virtual wxColour GetBackgroundColour() const wxOVERRIDE
|
||||
{ return wxNullColour; }
|
||||
|
||||
|
||||
// Implementation
|
||||
@@ -77,8 +72,8 @@ protected:
|
||||
private:
|
||||
void UnRef();
|
||||
|
||||
typedef wxAnimationBase base_type;
|
||||
wxDECLARE_DYNAMIC_CLASS(wxAnimation);
|
||||
typedef wxAnimationImpl base_type;
|
||||
wxDECLARE_DYNAMIC_CLASS(wxAnimationGTKImpl);
|
||||
};
|
||||
|
||||
|
||||
@@ -125,8 +120,6 @@ public: // public API
|
||||
virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
|
||||
|
||||
void SetAnimation(const wxAnimation &anim);
|
||||
wxAnimation GetAnimation() const
|
||||
{ return wxAnimation(m_anim) ; }
|
||||
|
||||
virtual bool Play() wxOVERRIDE;
|
||||
virtual void Stop() wxOVERRIDE;
|
||||
@@ -135,6 +128,9 @@ public: // public API
|
||||
|
||||
bool SetBackgroundColour( const wxColour &colour ) wxOVERRIDE;
|
||||
|
||||
static wxAnimationImpl* CreateAnimationImpl(wxAnimationImplType implType);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual void DisplayStaticImage() wxOVERRIDE;
|
||||
@@ -145,6 +141,11 @@ protected:
|
||||
void ResetAnim();
|
||||
void ResetIter();
|
||||
|
||||
// Helpers to safely access methods in the wxAnimationGTKImpl that are
|
||||
// specific to the gtk implementation
|
||||
GdkPixbufAnimation *animation_GetPixbuf() const;
|
||||
void animation_SetPixbuf(GdkPixbufAnimation* p);
|
||||
|
||||
protected: // internal vars
|
||||
|
||||
GdkPixbufAnimation *m_anim;
|
||||
|
@@ -301,6 +301,7 @@ bool wxGenericAnimationCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
|
||||
wxGenericAnimationCtrl::~wxGenericAnimationCtrl()
|
||||
{
|
||||
if (IsPlaying())
|
||||
Stop();
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader,
|
||||
gint WXUNUSED(y),
|
||||
gint WXUNUSED(width),
|
||||
gint WXUNUSED(height),
|
||||
wxAnimation *anim)
|
||||
wxAnimationGTKImpl *anim)
|
||||
{
|
||||
if (anim && anim->GetPixbuf() == NULL)
|
||||
{
|
||||
@@ -48,46 +48,19 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader,
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxAnimation
|
||||
// wxAnimationGTKImpl
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGTKImpl, wxAnimationImpl);
|
||||
|
||||
wxAnimation::wxAnimation(const wxAnimation& that)
|
||||
: base_type(that)
|
||||
{
|
||||
m_pixbuf = that.m_pixbuf;
|
||||
if (m_pixbuf)
|
||||
g_object_ref(m_pixbuf);
|
||||
}
|
||||
|
||||
wxAnimation::wxAnimation(GdkPixbufAnimation *p)
|
||||
{
|
||||
m_pixbuf = p;
|
||||
if ( m_pixbuf )
|
||||
g_object_ref(m_pixbuf);
|
||||
}
|
||||
|
||||
wxAnimation& wxAnimation::operator=(const wxAnimation& that)
|
||||
{
|
||||
if (this != &that)
|
||||
{
|
||||
base_type::operator=(that);
|
||||
UnRef();
|
||||
m_pixbuf = that.m_pixbuf;
|
||||
if (m_pixbuf)
|
||||
g_object_ref(m_pixbuf);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxAnimation::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type))
|
||||
bool wxAnimationGTKImpl::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type))
|
||||
{
|
||||
UnRef();
|
||||
m_pixbuf = gdk_pixbuf_animation_new_from_file(wxGTK_CONV_FN(name), NULL);
|
||||
return IsOk();
|
||||
}
|
||||
|
||||
bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type)
|
||||
bool wxAnimationGTKImpl::Load(wxInputStream &stream, wxAnimationType type)
|
||||
{
|
||||
UnRef();
|
||||
|
||||
@@ -174,20 +147,21 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type)
|
||||
return data_written;
|
||||
}
|
||||
|
||||
wxSize wxAnimation::GetSize() const
|
||||
wxSize wxAnimationGTKImpl::GetSize() const
|
||||
{
|
||||
return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf),
|
||||
gdk_pixbuf_animation_get_height(m_pixbuf));
|
||||
}
|
||||
|
||||
void wxAnimation::UnRef()
|
||||
void wxAnimationGTKImpl::UnRef()
|
||||
{
|
||||
base_type::UnRef();
|
||||
if (m_pixbuf)
|
||||
g_object_unref(m_pixbuf);
|
||||
m_pixbuf = NULL;
|
||||
}
|
||||
|
||||
void wxAnimation::SetPixbuf(GdkPixbufAnimation* p)
|
||||
void wxAnimationGTKImpl::SetPixbuf(GdkPixbufAnimation* p)
|
||||
{
|
||||
UnRef();
|
||||
m_pixbuf = p;
|
||||
@@ -247,6 +221,8 @@ bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||
|
||||
wxAnimationCtrl::~wxAnimationCtrl()
|
||||
{
|
||||
if (IsPlaying())
|
||||
Stop();
|
||||
ResetAnim();
|
||||
ResetIter();
|
||||
}
|
||||
@@ -261,7 +237,7 @@ bool wxAnimationCtrl::LoadFile(const wxString &filename, wxAnimationType type)
|
||||
|
||||
bool wxAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type)
|
||||
{
|
||||
wxAnimation anim;
|
||||
wxAnimation anim(wxANIMATION_IMPL_TYPE_NATIVE);
|
||||
if ( !anim.Load(stream, type) || !anim.IsOk() )
|
||||
return false;
|
||||
|
||||
@@ -277,8 +253,19 @@ void wxAnimationCtrl::SetAnimation(const wxAnimation &anim)
|
||||
ResetAnim();
|
||||
ResetIter();
|
||||
|
||||
m_animation = anim;
|
||||
if (!m_animation.IsOk())
|
||||
{
|
||||
m_anim = NULL;
|
||||
DisplayStaticImage();
|
||||
return;
|
||||
}
|
||||
|
||||
wxCHECK_RET(anim.GetImpl()->GetImplType() == wxANIMATION_IMPL_TYPE_NATIVE,
|
||||
wxT("incorrect animation implementation type provided") );
|
||||
|
||||
// copy underlying GdkPixbuf object
|
||||
m_anim = anim.GetPixbuf();
|
||||
m_anim = animation_GetPixbuf();
|
||||
|
||||
// m_anim may be null in case wxNullAnimation has been passed
|
||||
if (m_anim)
|
||||
@@ -459,4 +446,36 @@ void wxAnimationCtrl::OnTimer(wxTimerEvent& WXUNUSED(ev))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
wxAnimationImpl* wxAnimationCtrl::CreateAnimationImpl(wxAnimationImplType implType)
|
||||
{
|
||||
switch (implType) {
|
||||
case wxANIMATION_IMPL_TYPE_GENERIC:
|
||||
return new wxAnimationGenericImpl();
|
||||
|
||||
case wxANIMATION_IMPL_TYPE_NATIVE:
|
||||
return new wxAnimationGTKImpl();
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// helpers to safely access wxAnimationGenericImpl methods
|
||||
#define ANIMATION (static_cast<wxAnimationGTKImpl*>(m_animation.GetImpl()))
|
||||
|
||||
GdkPixbufAnimation* wxAnimationCtrl::animation_GetPixbuf() const
|
||||
{
|
||||
wxCHECK_MSG( m_animation.IsOk(), NULL, wxT("invalid animation") );
|
||||
return ANIMATION->GetPixbuf();
|
||||
}
|
||||
|
||||
void wxAnimationCtrl::animation_SetPixbuf(GdkPixbufAnimation* p)
|
||||
{
|
||||
wxCHECK_RET( m_animation.IsOk(), wxT("invalid animation") );
|
||||
ANIMATION->SetPixbuf(p);
|
||||
}
|
||||
|
||||
#endif // wxUSE_ANIMATIONCTRL
|
||||
|
Reference in New Issue
Block a user