Make wxAnimationImpl private and get rid of wxAnimationImplType

Simplify and streamline animation classes relationship: wxAnimation is
the only public class representing an animation and it can be created by
both the native wxAnimationCtrl and wxGenericAnimationCtrl using the new
public CreateAnimation() method.

Replace wxAnimationImplType enum with more flexible type info based
check.
This commit is contained in:
Vadim Zeitlin
2020-04-06 01:00:15 +02:00
parent 86d6cb8d1f
commit b08db49bf6
11 changed files with 184 additions and 165 deletions

View File

@@ -21,46 +21,13 @@
#include "wx/bitmap.h"
class WXDLLIMPEXP_FWD_CORE wxAnimation;
class wxAnimationImpl;
extern WXDLLIMPEXP_DATA_CORE(wxAnimation) wxNullAnimation;
extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[];
WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_CORE);
// ----------------------------------------------------------------------------
// wxAnimationImpl
// ----------------------------------------------------------------------------
enum wxAnimationImplType
{
wxANIMATION_IMPL_TYPE_NATIVE,
wxANIMATION_IMPL_TYPE_GENERIC
};
class WXDLLIMPEXP_CORE wxAnimationImpl : public wxRefCounter
{
public:
wxAnimationImpl() {}
virtual ~wxAnimationImpl() {}
virtual wxAnimationImplType GetImplType() = 0;
virtual bool IsOk() const = 0;
// can be -1
virtual int GetDelay(unsigned int frame) const = 0;
virtual unsigned int GetFrameCount() const = 0;
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,
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
};
// ----------------------------------------------------------------------------
// wxAnimation
// ----------------------------------------------------------------------------
@@ -68,18 +35,14 @@ public:
class WXDLLIMPEXP_CORE wxAnimation : public wxObject
{
public:
explicit wxAnimation(wxAnimationImplType implType = wxANIMATION_IMPL_TYPE_NATIVE);
explicit wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY,
wxAnimationImplType implType = wxANIMATION_IMPL_TYPE_NATIVE);
wxAnimation();
explicit wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
wxAnimation(const wxAnimation& other);
wxAnimation& operator=(const wxAnimation& other);
wxAnimationImpl* GetImpl() const
{ return static_cast<wxAnimationImpl*>(m_refData); }
bool IsOk() const
{ return GetImpl() && GetImpl()->IsOk(); }
bool IsOk() const;
bool IsCompatibleWith(wxClassInfo* ci) const;
int GetDelay(unsigned int frame) const;
unsigned int GetFrameCount() const;
@@ -99,8 +62,18 @@ public:
static void InitStandardHandlers();
protected:
wxAnimationImpl* GetImpl() const;
private:
static wxAnimationDecoderList sm_handlers;
// Ctor used by wxAnimationCtrl::CreateAnimation() only.
explicit wxAnimation(wxAnimationImpl* impl);
// Give it permission to create objects of this class using specific impl
// and access our GetImpl().
friend class wxAnimationCtrlBase;
wxDECLARE_DYNAMIC_CLASS(wxAnimation);
};
@@ -141,7 +114,16 @@ public:
wxBitmap GetInactiveBitmap() const
{ return m_bmpStatic; }
wxAnimation CreateAnimation() const
{ return wxAnimation(DoCreateAnimationImpl()); }
protected:
virtual wxAnimationImpl* DoCreateAnimationImpl() const = 0;
// This method allows derived classes access to wxAnimation::GetImpl().
wxAnimationImpl* GetAnimImpl(const wxAnimation& anim) const
{ return anim.GetImpl(); }
// the inactive bitmap as it was set by the user
wxBitmap m_bmpStatic;

View File

@@ -92,9 +92,8 @@ public: // extended API specific to this implementation of wxAnimateCtrl
wxBitmap& GetBackingStore()
{ return m_backingStore; }
static wxAnimationImpl* CreateAnimationImpl(wxAnimationImplType implType);
protected: // internal utilities
virtual wxAnimationImpl* DoCreateAnimationImpl() const wxOVERRIDE;
// resize this control to fit m_animation
void FitToAnimation();

View File

@@ -11,6 +11,8 @@
#ifndef _WX_GENERIC_PRIVATE_ANIMATEH__
#define _WX_GENERIC_PRIVATE_ANIMATEH__
#include "wx/private/animate.h"
// ----------------------------------------------------------------------------
// wxAnimationGenericImpl
// ----------------------------------------------------------------------------
@@ -21,11 +23,9 @@ public:
wxAnimationGenericImpl() : m_decoder(NULL) {}
virtual ~wxAnimationGenericImpl() { UnRef(); }
virtual wxAnimationImplType GetImplType() wxOVERRIDE
{ return wxANIMATION_IMPL_TYPE_GENERIC; }
virtual bool IsOk() const wxOVERRIDE
{ return m_decoder != NULL; }
virtual bool IsCompatibleWith(wxClassInfo* ci) const wxOVERRIDE;
virtual unsigned int GetFrameCount() const wxOVERRIDE;
virtual int GetDelay(unsigned int i) const wxOVERRIDE;

View File

@@ -65,10 +65,8 @@ public: // public API
bool SetBackgroundColour( const wxColour &colour ) wxOVERRIDE;
static wxAnimationImpl* CreateAnimationImpl(wxAnimationImplType implType);
protected:
virtual wxAnimationImpl* DoCreateAnimationImpl() const wxOVERRIDE;
virtual void DisplayStaticImage() wxOVERRIDE;
virtual wxSize DoGetBestSize() const wxOVERRIDE;

View File

@@ -11,6 +11,8 @@
#ifndef _WX_GTK_PRIVATE_ANIMATEH__
#define _WX_GTK_PRIVATE_ANIMATEH__
#include "wx/private/animate.h"
typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter;
@@ -28,12 +30,9 @@ public:
: m_pixbuf(NULL) {}
~wxAnimationGTKImpl() { UnRef(); }
virtual wxAnimationImplType GetImplType() wxOVERRIDE
{ return wxANIMATION_IMPL_TYPE_NATIVE; }
virtual bool IsOk() const wxOVERRIDE
{ return m_pixbuf != NULL; }
virtual bool IsCompatibleWith(wxClassInfo* ci) const wxOVERRIDE;
// unfortunately GdkPixbufAnimation does not expose these info:

View File

@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/animate.h
// Purpose: wxAnimationImpl declaration
// Author: Robin Dunn, Vadim Zeitlin
// Created: 2020-04-06
// Copyright: (c) 2020 wxWidgets development team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_ANIMATEH__
#define _WX_PRIVATE_ANIMATEH__
// ----------------------------------------------------------------------------
// wxAnimationImpl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxAnimationImpl : public wxRefCounter
{
public:
wxAnimationImpl() {}
virtual ~wxAnimationImpl() {}
virtual bool IsOk() const = 0;
virtual bool IsCompatibleWith(wxClassInfo* ci) const = 0;
// can be -1
virtual int GetDelay(unsigned int frame) const = 0;
virtual unsigned int GetFrameCount() const = 0;
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,
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
// This function creates the default implementation for this platform:
// currently it's wxAnimationGTKImpl under wxGTK and wxAnimationGenericImpl
// under all the other platforms.
static wxAnimationImpl *CreateDefault();
};
#endif // _WX_PRIVATE_ANIMATEH__