* Rename the generic version as wxGenericAnimationCtrl

* Add a simple shim class for the generic wxAnimationCtrl
* Use the generic wxAnimation as the base class (this will probably change...)
This commit is contained in:
Robin Dunn
2020-03-25 16:29:34 -07:00
parent f501177857
commit fae15d39a6
4 changed files with 99 additions and 113 deletions

View File

@@ -27,30 +27,51 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[];
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationBase // wxAnimation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxAnimationBase : public wxObject WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV);
class WXDLLIMPEXP_ADV wxAnimation : public wxObject
{ {
public: public:
wxAnimationBase() {} wxAnimation() {}
wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
{ LoadFile(name, type); }
virtual bool IsOk() const = 0; virtual bool IsOk() const
{ return m_refData != NULL; }
// can be -1 virtual unsigned int GetFrameCount() const;
virtual int GetDelay(unsigned int frame) const = 0; virtual int GetDelay(unsigned int i) const;
virtual wxImage GetFrame(unsigned int i) const;
virtual wxSize GetSize() const;
virtual unsigned int GetFrameCount() const = 0; virtual bool LoadFile(const wxString& filename,
virtual wxImage GetFrame(unsigned int frame) const = 0; wxAnimationType type = wxANIMATION_TYPE_ANY);
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) = 0; wxAnimationType type = wxANIMATION_TYPE_ANY);
// extended interface used by the generic implementation of wxAnimationCtrl
virtual wxPoint GetFramePosition(unsigned int frame) const;
virtual wxSize GetFrameSize(unsigned int frame) const;
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
virtual wxColour GetTransparentColour(unsigned int frame) const;
virtual wxColour GetBackgroundColour() const;
protected: protected:
wxDECLARE_ABSTRACT_CLASS(wxAnimationBase); 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(wxAnimation);
}; };
@@ -114,12 +135,29 @@ private:
// include the platform-specific version of the wxAnimationCtrl class // include the platform-specific version of the wxAnimationCtrl class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxUSE_NATIVE_ANIMATIONCTRL && defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
#define wxUSE_GENERIC_ANIMATIONCTRL 0
#include "wx/gtk/animate.h" #include "wx/gtk/animate.h"
#else #else
#define wxUSE_GENERIC_ANIMATIONCTRL 1
#include "wx/generic/animate.h" #include "wx/generic/animate.h"
class WXDLLIMPEXP_ADV wxAnimationCtrl : public wxGenericAnimationCtrl
{
public:
wxAnimationCtrl()
: wxGenericAnimationCtrl()
{}
wxAnimationCtrl(wxWindow *parent,
wxWindowID id,
const wxAnimation& anim = wxNullAnimation,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxAC_DEFAULT_STYLE,
const wxString& name = wxAnimationCtrlNameStr)
: wxGenericAnimationCtrl(parent, id, anim, pos, size, style, name)
{}
private:
wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl);
};
#endif #endif
#endif // wxUSE_ANIMATIONCTRL #endif // wxUSE_ANIMATIONCTRL

View File

@@ -13,70 +13,21 @@
#include "wx/bitmap.h" #include "wx/bitmap.h"
// ----------------------------------------------------------------------------
// wxAnimation
// ----------------------------------------------------------------------------
WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV);
class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
{
public:
wxAnimation() {}
wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
{ LoadFile(name, type); }
virtual bool IsOk() const wxOVERRIDE
{ 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 by the generic implementation of wxAnimationCtrl
wxPoint GetFramePosition(unsigned int frame) const;
wxSize GetFrameSize(unsigned int frame) const;
wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
wxColour GetTransparentColour(unsigned int frame) const;
wxColour GetBackgroundColour() const;
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(wxAnimation);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationCtrl // wxAnimationCtrl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase class WXDLLIMPEXP_ADV wxGenericAnimationCtrl: public wxAnimationCtrlBase
{ {
public: public:
wxAnimationCtrl() { Init(); } wxGenericAnimationCtrl() { Init(); }
wxAnimationCtrl(wxWindow *parent, wxGenericAnimationCtrl(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxAnimation& 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)
{ {
Init(); Init();
@@ -92,7 +43,7 @@ public:
long style = wxAC_DEFAULT_STYLE, long style = wxAC_DEFAULT_STYLE,
const wxString& name = wxAnimationCtrlNameStr); const wxString& name = wxAnimationCtrlNameStr);
~wxAnimationCtrl(); ~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;
@@ -104,7 +55,7 @@ public:
virtual bool IsPlaying() const wxOVERRIDE virtual bool IsPlaying() const wxOVERRIDE
{ return m_isPlaying; } { return m_isPlaying; }
void SetAnimation(const wxAnimation &animation) wxOVERRIDE; void SetAnimation(const wxAnimation &animation) wxOVERRIDE;
wxAnimation GetAnimation() const wxOVERRIDE wxAnimation GetAnimation() const wxOVERRIDE
{ return m_animation; } { return m_animation; }
@@ -170,7 +121,7 @@ protected:
private: private:
typedef wxAnimationCtrlBase base_type; typedef wxAnimationCtrlBase base_type;
wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl); wxDECLARE_DYNAMIC_CLASS(wxGenericAnimationCtrl);
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };

View File

@@ -34,8 +34,8 @@ const char wxAnimationCtrlNameStr[] = "animationctrl";
// global object // global object
wxAnimation wxNullAnimation; wxAnimation wxNullAnimation;
wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject);
wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl); wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl);
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationCtrl, wxAnimationCtrlBase);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -17,8 +17,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/log.h" #include "wx/log.h"
#include "wx/image.h" #include "wx/image.h"
@@ -41,7 +39,7 @@ wxAnimationDecoderList wxAnimation::sm_handlers;
// wxAnimation // wxAnimation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase); wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxObject);
#define M_ANIMDATA static_cast<wxAnimationDecoder*>(m_refData) #define M_ANIMDATA static_cast<wxAnimationDecoder*>(m_refData)
wxSize wxAnimation::GetSize() const wxSize wxAnimation::GetSize() const
@@ -265,14 +263,14 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationModule, wxModule);
// wxAnimationCtrl // wxAnimationCtrl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxIMPLEMENT_CLASS(wxAnimationCtrl, wxAnimationCtrlBase); wxIMPLEMENT_CLASS(wxGenericAnimationCtrl, wxAnimationCtrlBase);
wxBEGIN_EVENT_TABLE(wxAnimationCtrl, wxAnimationCtrlBase) wxBEGIN_EVENT_TABLE(wxGenericAnimationCtrl, wxAnimationCtrlBase)
EVT_PAINT(wxAnimationCtrl::OnPaint) EVT_PAINT(wxGenericAnimationCtrl::OnPaint)
EVT_SIZE(wxAnimationCtrl::OnSize) EVT_SIZE(wxGenericAnimationCtrl::OnSize)
EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer) EVT_TIMER(wxID_ANY, wxGenericAnimationCtrl::OnTimer)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
void wxAnimationCtrl::Init() void wxGenericAnimationCtrl::Init()
{ {
m_currentFrame = 0; m_currentFrame = 0;
m_looped = false; m_looped = false;
@@ -283,7 +281,7 @@ void wxAnimationCtrl::Init()
m_useWinBackgroundColour = true; m_useWinBackgroundColour = true;
} }
bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id, bool wxGenericAnimationCtrl::Create(wxWindow *parent, wxWindowID id,
const wxAnimation& animation, const wxPoint& pos, const wxAnimation& animation, const wxPoint& pos,
const wxSize& size, long style, const wxString& name) const wxSize& size, long style, const wxString& name)
{ {
@@ -300,12 +298,12 @@ bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id,
return true; return true;
} }
wxAnimationCtrl::~wxAnimationCtrl() wxGenericAnimationCtrl::~wxGenericAnimationCtrl()
{ {
Stop(); Stop();
} }
bool wxAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType type) bool wxGenericAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType type)
{ {
wxFileInputStream fis(filename); wxFileInputStream fis(filename);
if (!fis.IsOk()) if (!fis.IsOk())
@@ -313,7 +311,7 @@ bool wxAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType type)
return Load(fis, type); return Load(fis, type);
} }
bool wxAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type) bool wxGenericAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type)
{ {
wxAnimation anim; wxAnimation anim;
if ( !anim.Load(stream, type) || !anim.IsOk() ) if ( !anim.Load(stream, type) || !anim.IsOk() )
@@ -323,7 +321,7 @@ bool wxAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type)
return true; return true;
} }
wxSize wxAnimationCtrl::DoGetBestSize() const wxSize wxGenericAnimationCtrl::DoGetBestSize() const
{ {
if (m_animation.IsOk() && !this->HasFlag(wxAC_NO_AUTORESIZE)) if (m_animation.IsOk() && !this->HasFlag(wxAC_NO_AUTORESIZE))
return m_animation.GetSize(); return m_animation.GetSize();
@@ -331,10 +329,10 @@ wxSize wxAnimationCtrl::DoGetBestSize() const
return FromDIP(wxSize(100, 100)); return FromDIP(wxSize(100, 100));
} }
void wxAnimationCtrl::SetAnimation(const wxAnimation& animation) void wxGenericAnimationCtrl::SetAnimation(const wxAnimation& animation)
{ {
if (IsPlaying()) if (IsPlaying())
Stop(); Stop();
// set new animation even if it's wxNullAnimation // set new animation even if it's wxNullAnimation
m_animation = animation; m_animation = animation;
@@ -352,7 +350,7 @@ void wxAnimationCtrl::SetAnimation(const wxAnimation& animation)
DisplayStaticImage(); DisplayStaticImage();
} }
void wxAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp) void wxGenericAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp)
{ {
// if the bitmap has an associated mask, we need to set our background to // if the bitmap has an associated mask, we need to set our background to
// the colour of our parent otherwise when calling DrawCurrentFrame() // the colour of our parent otherwise when calling DrawCurrentFrame()
@@ -365,12 +363,12 @@ void wxAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp)
wxAnimationCtrlBase::SetInactiveBitmap(bmp); wxAnimationCtrlBase::SetInactiveBitmap(bmp);
} }
void wxAnimationCtrl::FitToAnimation() void wxGenericAnimationCtrl::FitToAnimation()
{ {
SetSize(m_animation.GetSize()); SetSize(m_animation.GetSize());
} }
bool wxAnimationCtrl::SetBackgroundColour(const wxColour& colour) bool wxGenericAnimationCtrl::SetBackgroundColour(const wxColour& colour)
{ {
if ( !wxWindow::SetBackgroundColour(colour) ) if ( !wxWindow::SetBackgroundColour(colour) )
return false; return false;
@@ -388,7 +386,7 @@ bool wxAnimationCtrl::SetBackgroundColour(const wxColour& colour)
// wxAnimationCtrl - stop/play methods // wxAnimationCtrl - stop/play methods
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxAnimationCtrl::Stop() void wxGenericAnimationCtrl::Stop()
{ {
m_timer.Stop(); m_timer.Stop();
m_isPlaying = false; m_isPlaying = false;
@@ -399,7 +397,7 @@ void wxAnimationCtrl::Stop()
DisplayStaticImage(); DisplayStaticImage();
} }
bool wxAnimationCtrl::Play(bool looped) bool wxGenericAnimationCtrl::Play(bool looped)
{ {
if (!m_animation.IsOk()) if (!m_animation.IsOk())
return false; return false;
@@ -435,7 +433,7 @@ bool wxAnimationCtrl::Play(bool looped)
// wxAnimationCtrl - rendering methods // wxAnimationCtrl - rendering methods
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxAnimationCtrl::RebuildBackingStoreUpToFrame(unsigned int frame) bool wxGenericAnimationCtrl::RebuildBackingStoreUpToFrame(unsigned int frame)
{ {
// if we've not created the backing store yet or it's too // if we've not created the backing store yet or it's too
// small, then recreate it // small, then recreate it
@@ -477,7 +475,7 @@ bool wxAnimationCtrl::RebuildBackingStoreUpToFrame(unsigned int frame)
return true; return true;
} }
void wxAnimationCtrl::IncrementalUpdateBackingStore() void wxGenericAnimationCtrl::IncrementalUpdateBackingStore()
{ {
wxMemoryDC dc; wxMemoryDC dc;
dc.SelectObject(m_backingStore); dc.SelectObject(m_backingStore);
@@ -529,7 +527,7 @@ void wxAnimationCtrl::IncrementalUpdateBackingStore()
dc.SelectObject(wxNullBitmap); dc.SelectObject(wxNullBitmap);
} }
void wxAnimationCtrl::DisplayStaticImage() void wxGenericAnimationCtrl::DisplayStaticImage()
{ {
wxASSERT(!IsPlaying()); wxASSERT(!IsPlaying());
@@ -564,7 +562,7 @@ void wxAnimationCtrl::DisplayStaticImage()
Refresh(); Refresh();
} }
void wxAnimationCtrl::DrawFrame(wxDC &dc, unsigned int frame) void wxGenericAnimationCtrl::DrawFrame(wxDC &dc, unsigned int frame)
{ {
// PERFORMANCE NOTE: // PERFORMANCE NOTE:
// this draw stuff is not as fast as possible: the wxAnimationDecoder // this draw stuff is not as fast as possible: the wxAnimationDecoder
@@ -577,7 +575,7 @@ void wxAnimationCtrl::DrawFrame(wxDC &dc, unsigned int frame)
true /* use mask */); true /* use mask */);
} }
void wxAnimationCtrl::DrawCurrentFrame(wxDC& dc) void wxGenericAnimationCtrl::DrawCurrentFrame(wxDC& dc)
{ {
wxASSERT( m_backingStore.IsOk() ); wxASSERT( m_backingStore.IsOk() );
@@ -585,7 +583,7 @@ void wxAnimationCtrl::DrawCurrentFrame(wxDC& dc)
dc.DrawBitmap(m_backingStore, 0, 0, true /* use mask in case it's present */); dc.DrawBitmap(m_backingStore, 0, 0, true /* use mask in case it's present */);
} }
void wxAnimationCtrl::DisposeToBackground() void wxGenericAnimationCtrl::DisposeToBackground()
{ {
// clear the backing store // clear the backing store
wxMemoryDC dc; wxMemoryDC dc;
@@ -594,7 +592,7 @@ void wxAnimationCtrl::DisposeToBackground()
DisposeToBackground(dc); DisposeToBackground(dc);
} }
void wxAnimationCtrl::DisposeToBackground(wxDC& dc) void wxGenericAnimationCtrl::DisposeToBackground(wxDC& dc)
{ {
wxColour col = IsUsingWindowBackgroundColour() wxColour col = IsUsingWindowBackgroundColour()
? GetBackgroundColour() ? GetBackgroundColour()
@@ -605,7 +603,7 @@ void wxAnimationCtrl::DisposeToBackground(wxDC& dc)
dc.Clear(); dc.Clear();
} }
void wxAnimationCtrl::DisposeToBackground(wxDC& dc, const wxPoint &pos, const wxSize &sz) void wxGenericAnimationCtrl::DisposeToBackground(wxDC& dc, const wxPoint &pos, const wxSize &sz)
{ {
wxColour col = IsUsingWindowBackgroundColour() wxColour col = IsUsingWindowBackgroundColour()
? GetBackgroundColour() ? GetBackgroundColour()
@@ -620,7 +618,7 @@ void wxAnimationCtrl::DisposeToBackground(wxDC& dc, const wxPoint &pos, const wx
// wxAnimationCtrl - event handlers // wxAnimationCtrl - event handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxAnimationCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) void wxGenericAnimationCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{ {
// VERY IMPORTANT: the wxPaintDC *must* be created in any case // VERY IMPORTANT: the wxPaintDC *must* be created in any case
wxPaintDC dc(this); wxPaintDC dc(this);
@@ -640,7 +638,7 @@ void wxAnimationCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
} }
} }
void wxAnimationCtrl::OnTimer(wxTimerEvent &WXUNUSED(event)) void wxGenericAnimationCtrl::OnTimer(wxTimerEvent &WXUNUSED(event))
{ {
m_currentFrame++; m_currentFrame++;
if (m_currentFrame == m_animation.GetFrameCount()) if (m_currentFrame == m_animation.GetFrameCount())
@@ -672,7 +670,7 @@ void wxAnimationCtrl::OnTimer(wxTimerEvent &WXUNUSED(event))
m_timer.Start(delay, true); m_timer.Start(delay, true);
} }
void wxAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event)) void wxGenericAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event))
{ {
// NB: resizing an animation control may take a lot of time // NB: resizing an animation control may take a lot of time
// for big animations as the backing store must be // for big animations as the backing store must be
@@ -693,6 +691,5 @@ void wxAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event))
} }
} }
#endif // wxUSE_GENERIC_ANIMATIONCTRL
#endif // wxUSE_ANIMATIONCTRL #endif // wxUSE_ANIMATIONCTRL