* Switch back to using an wxAnimationBase class

* Change the [GS]etAnimation methods to be non-virtual so they can use generic/native types of animation obj
This commit is contained in:
Robin Dunn
2020-03-30 14:53:11 -07:00
parent 08ac4dbad6
commit a7f9d5e3c5
6 changed files with 120 additions and 67 deletions

View File

@@ -20,9 +20,11 @@
#include "wx/timer.h" #include "wx/timer.h"
#include "wx/bitmap.h" #include "wx/bitmap.h"
class WXDLLIMPEXP_FWD_CORE wxAnimation;
class WXDLLIMPEXP_FWD_CORE wxGenericAnimation; class WXDLLIMPEXP_FWD_CORE wxGenericAnimation;
extern WXDLLIMPEXP_DATA_CORE(wxGenericAnimation) wxNullAnimation; extern WXDLLIMPEXP_DATA_CORE(wxAnimation) wxNullAnimation;
extern WXDLLIMPEXP_DATA_CORE(wxGenericAnimation) wxNullGenericAnimation;
extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[]; extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[];
@@ -32,46 +34,38 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[];
WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV); WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV);
class WXDLLIMPEXP_ADV wxGenericAnimation : public wxObject // ----------------------------------------------------------------------------
// wxAnimationBase
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxAnimationBase : public wxObject
{ {
public: public:
wxGenericAnimation() {} wxAnimationBase() {}
wxGenericAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
{ LoadFile(name, type); }
virtual bool IsOk() const virtual bool IsOk() const = 0;
{ return m_refData != NULL; }
virtual unsigned int GetFrameCount() const; // can be -1
virtual int GetDelay(unsigned int i) const; virtual int GetDelay(unsigned int frame) const = 0;
virtual wxImage GetFrame(unsigned int i) const;
virtual wxSize GetSize() const;
virtual bool LoadFile(const wxString& filename, virtual unsigned int GetFrameCount() const = 0;
wxAnimationType type = wxANIMATION_TYPE_ANY); virtual wxImage GetFrame(unsigned int frame) const = 0;
virtual wxSize GetSize() const = 0;
virtual bool LoadFile(const wxString& name,
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
virtual bool Load(wxInputStream& stream, virtual bool Load(wxInputStream& stream,
wxAnimationType type = wxANIMATION_TYPE_ANY); wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
// extended interface used by the generic implementation of wxAnimationCtrl // extended interface used only by the generic implementation of wxAnimationCtrl
virtual wxPoint GetFramePosition(unsigned int frame) const; virtual wxPoint GetFramePosition(unsigned int frame) const = 0;
virtual wxSize GetFrameSize(unsigned int frame) const; virtual wxSize GetFrameSize(unsigned int frame) const = 0;
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const; virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const = 0;
virtual wxColour GetTransparentColour(unsigned int frame) const; virtual wxColour GetTransparentColour(unsigned int frame) const = 0;
virtual wxColour GetBackgroundColour() const; virtual wxColour GetBackgroundColour() const = 0;
protected: protected:
static wxAnimationDecoderList sm_handlers; wxDECLARE_ABSTRACT_CLASS(wxAnimationBase);
public:
static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; }
static void AddHandler(wxAnimationDecoder *handler);
static void InsertHandler(wxAnimationDecoder *handler);
static const wxAnimationDecoder *FindHandler( wxAnimationType animType );
static void CleanUpHandlers();
static void InitStandardHandlers();
wxDECLARE_DYNAMIC_CLASS(wxGenericAnimation);
}; };
@@ -98,9 +92,6 @@ public:
virtual bool Load(wxInputStream& stream, virtual bool Load(wxInputStream& stream,
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0; wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
virtual void SetAnimation(const wxGenericAnimation &anim) = 0;
virtual wxGenericAnimation GetAnimation() const = 0;
virtual bool Play() = 0; virtual bool Play() = 0;
virtual void Stop() = 0; virtual void Stop() = 0;
@@ -135,7 +126,8 @@ private:
// include the platform-specific version of the wxAnimationCtrl class // include the platform-specific version of the wxAnimationCtrl class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) #if defined(__WXGTK20__)
#include "wx/generic/animate.h"
#include "wx/gtk/animate.h" #include "wx/gtk/animate.h"
#else #else
#include "wx/generic/animate.h" #include "wx/generic/animate.h"
@@ -147,6 +139,8 @@ private:
: wxGenericAnimation() {} : wxGenericAnimation() {}
wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
: wxGenericAnimation(name, type) {} : wxGenericAnimation(name, type) {}
wxAnimation(const wxGenericAnimation& other)
: wxGenericAnimation(other) {}
private: private:
wxDECLARE_DYNAMIC_CLASS(wxAnimation); wxDECLARE_DYNAMIC_CLASS(wxAnimation);
}; };
@@ -159,13 +153,17 @@ private:
{} {}
wxAnimationCtrl(wxWindow *parent, wxAnimationCtrl(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxGenericAnimation& anim = wxNullAnimation, const wxAnimation& anim = wxNullAnimation,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxAC_DEFAULT_STYLE, long style = wxAC_DEFAULT_STYLE,
const wxString& name = wxAnimationCtrlNameStr) const wxString& name = wxAnimationCtrlNameStr)
: wxGenericAnimationCtrl(parent, id, anim, pos, size, style, name) : wxGenericAnimationCtrl(parent, id, anim, pos, size, style, name)
{} {}
virtual wxAnimation GetAnimation() const
{ return wxAnimation(m_animation) ; }
private: private:
wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl); wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl);
}; };

View File

@@ -13,6 +13,53 @@
#include "wx/bitmap.h" #include "wx/bitmap.h"
// ----------------------------------------------------------------------------
// wxGenericAnimation
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxGenericAnimation : public wxAnimationBase
{
public:
wxGenericAnimation() {}
wxGenericAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
{ LoadFile(name, type); }
virtual bool IsOk() const
{ return m_refData != NULL; }
virtual unsigned int GetFrameCount() const wxOVERRIDE;
virtual int GetDelay(unsigned int i) const wxOVERRIDE;
virtual wxImage GetFrame(unsigned int i) const wxOVERRIDE;
virtual wxSize GetSize() const wxOVERRIDE;
virtual bool LoadFile(const wxString& filename,
wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
virtual bool Load(wxInputStream& stream,
wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
// extended interface used only by the generic implementation of wxAnimationCtrl
virtual wxPoint GetFramePosition(unsigned int frame) const wxOVERRIDE;
virtual wxSize GetFrameSize(unsigned int frame) const wxOVERRIDE;
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const wxOVERRIDE;
virtual wxColour GetTransparentColour(unsigned int frame) const wxOVERRIDE;
virtual wxColour GetBackgroundColour() const wxOVERRIDE;
protected:
static wxAnimationDecoderList sm_handlers;
public:
static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; }
static void AddHandler(wxAnimationDecoder *handler);
static void InsertHandler(wxAnimationDecoder *handler);
static const wxAnimationDecoder *FindHandler( wxAnimationType animType );
static void CleanUpHandlers();
static void InitStandardHandlers();
wxDECLARE_DYNAMIC_CLASS(wxGenericAnimation);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGenericAnimationCtrl // wxGenericAnimationCtrl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -23,7 +70,7 @@ public:
wxGenericAnimationCtrl() { Init(); } wxGenericAnimationCtrl() { Init(); }
wxGenericAnimationCtrl(wxWindow *parent, wxGenericAnimationCtrl(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxGenericAnimation& anim = wxNullAnimation, const wxGenericAnimation& anim = wxNullGenericAnimation,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxAC_DEFAULT_STYLE, long style = wxAC_DEFAULT_STYLE,
@@ -37,7 +84,7 @@ public:
void Init(); void Init();
bool Create(wxWindow *parent, wxWindowID id, bool Create(wxWindow *parent, wxWindowID id,
const wxGenericAnimation& anim = wxNullAnimation, const wxGenericAnimation& anim = wxNullGenericAnimation,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxAC_DEFAULT_STYLE, long style = wxAC_DEFAULT_STYLE,
@@ -45,6 +92,7 @@ public:
~wxGenericAnimationCtrl(); ~wxGenericAnimationCtrl();
public: public:
virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
@@ -55,8 +103,8 @@ public:
virtual bool IsPlaying() const wxOVERRIDE virtual bool IsPlaying() const wxOVERRIDE
{ return m_isPlaying; } { return m_isPlaying; }
void SetAnimation(const wxGenericAnimation &animation) wxOVERRIDE; void SetAnimation(const wxGenericAnimation &animation);
wxGenericAnimation GetAnimation() const wxOVERRIDE wxGenericAnimation GetAnimation() const
{ return m_animation; } { return m_animation; }
virtual void SetInactiveBitmap(const wxBitmap &bmp) wxOVERRIDE; virtual void SetInactiveBitmap(const wxBitmap &bmp) wxOVERRIDE;

View File

@@ -38,20 +38,32 @@ public:
{ return m_pixbuf != NULL; } { return m_pixbuf != NULL; }
// unfortunately GdkPixbufAnimation does not expose these info:
virtual unsigned int GetFrameCount() const wxOVERRIDE { return 0; }
virtual wxImage GetFrame(unsigned int frame) const wxOVERRIDE;
// we can retrieve the delay for a frame only after building // we can retrieve the delay for a frame only after building
// a GdkPixbufAnimationIter... // a GdkPixbufAnimationIter...
virtual int GetDelay(unsigned int WXUNUSED(frame)) const wxOVERRIDE { return 0; } virtual int GetDelay(unsigned int WXUNUSED(frame)) const wxOVERRIDE { return 0; }
virtual wxSize GetSize() const wxOVERRIDE; virtual wxSize GetSize() const wxOVERRIDE;
virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
// unfortunately GdkPixbufAnimation does not expose these info:
virtual unsigned int GetFrameCount() const wxOVERRIDE
{ 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 // Implementation
public: // used by GTK callbacks public: // used by GTK callbacks
@@ -112,8 +124,8 @@ public: // public API
virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
virtual void SetAnimation(const wxAnimation &anim) wxOVERRIDE; void SetAnimation(const wxAnimation &anim);
virtual wxAnimation GetAnimation() const wxOVERRIDE wxAnimation GetAnimation() const
{ return wxAnimation(m_anim) ; } { return wxAnimation(m_anim) ; }
virtual bool Play() wxOVERRIDE; virtual bool Play() wxOVERRIDE;

View File

@@ -30,14 +30,18 @@
#include "wx/dcmemory.h" #include "wx/dcmemory.h"
const char wxAnimationCtrlNameStr[] = "animationctrl"; const char wxAnimationCtrlNameStr[] = "animationctrl";
wxGenericAnimation wxNullGenericAnimation;
wxAnimation wxNullAnimation;
// global object wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject);
wxGenericAnimation wxNullAnimation;
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxGenericAnimation);
wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl); wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl);
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationCtrl, wxAnimationCtrlBase); wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase);
wxIMPLEMENT_DYNAMIC_CLASS(wxGenericAnimation, wxAnimationBase);
#if !defined(__WXGTK20__)
// In this case the "native" ctrl is the generic ctrl. See wx/animate.h
wxIMPLEMENT_CLASS(wxAnimationCtrl, wxGenericAnimationCtrl);
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationCtrlBase // wxAnimationCtrlBase

View File

@@ -39,7 +39,6 @@ wxAnimationDecoderList wxGenericAnimation::sm_handlers;
// wxAnimation // wxAnimation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxIMPLEMENT_DYNAMIC_CLASS(wxGenericAnimation, wxObject);
#define M_ANIMDATA static_cast<wxAnimationDecoder*>(m_refData) #define M_ANIMDATA static_cast<wxAnimationDecoder*>(m_refData)
wxSize wxGenericAnimation::GetSize() const wxSize wxGenericAnimation::GetSize() const
@@ -313,7 +312,7 @@ bool wxGenericAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType
bool wxGenericAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type) bool wxGenericAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type)
{ {
wxAnimation anim; wxGenericAnimation anim;
if ( !anim.Load(stream, type) || !anim.IsOk() ) if ( !anim.Load(stream, type) || !anim.IsOk() )
return false; return false;
@@ -554,7 +553,7 @@ void wxGenericAnimationCtrl::DisplayStaticImage()
if (!m_animation.IsOk() || if (!m_animation.IsOk() ||
!RebuildBackingStoreUpToFrame(0)) !RebuildBackingStoreUpToFrame(0))
{ {
m_animation = wxNullAnimation; m_animation = wxNullGenericAnimation;
DisposeToBackground(); DisposeToBackground();
} }
} }

View File

@@ -14,7 +14,6 @@
#if wxUSE_ANIMATIONCTRL #if wxUSE_ANIMATIONCTRL
#include "wx/animate.h" #include "wx/animate.h"
#if !wxUSE_GENERIC_ANIMATIONCTRL
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/image.h" #include "wx/image.h"
@@ -53,7 +52,6 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader,
// wxAnimation // wxAnimation
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase);
wxAnimation::wxAnimation(const wxAnimation& that) wxAnimation::wxAnimation(const wxAnimation& that)
: base_type(that) : base_type(that)
@@ -177,11 +175,6 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type)
return data_written; return data_written;
} }
wxImage wxAnimation::GetFrame(unsigned int WXUNUSED(frame)) const
{
return wxNullImage;
}
wxSize wxAnimation::GetSize() const wxSize wxAnimation::GetSize() const
{ {
return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf), return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf),
@@ -467,5 +460,4 @@ void wxAnimationCtrl::OnTimer(wxTimerEvent& WXUNUSED(ev))
} }
} }
#endif // !wxUSE_GENERIC_ANIMATIONCTRL
#endif // wxUSE_ANIMATIONCTRL #endif // wxUSE_ANIMATIONCTRL