Merge branch 'disable-native-animation'

Allow the generic animation classes to be used on all platforms.

See https://github.com/wxWidgets/wxWidgets/pull/1768
This commit is contained in:
Vadim Zeitlin
2020-04-07 00:40:45 +02:00
27 changed files with 1277 additions and 866 deletions

View File

@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/animate.h
// Purpose: wxAnimation and wxAnimationCtrl
// Purpose: wxGenericAnimationCtrl
// Author: Julian Smart and Guillermo Rodriguez Garcia
// Modified by: Francesco Montorsi
// Created: 13/8/99
@@ -13,70 +13,22 @@
#include "wx/bitmap.h"
// ----------------------------------------------------------------------------
// wxAnimation
// wxGenericAnimationCtrl
// ----------------------------------------------------------------------------
WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV);
class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
class WXDLLIMPEXP_ADV wxGenericAnimationCtrl: public wxAnimationCtrlBase
{
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
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase
{
public:
wxAnimationCtrl() { Init(); }
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() { Init(); }
wxGenericAnimationCtrl(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)
{
Init();
@@ -92,7 +44,8 @@ public:
long style = wxAC_DEFAULT_STYLE,
const wxString& name = wxAnimationCtrlNameStr);
~wxAnimationCtrl();
~wxGenericAnimationCtrl();
public:
virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE;
@@ -105,14 +58,14 @@ public:
{ return m_isPlaying; }
void SetAnimation(const wxAnimation &animation) wxOVERRIDE;
wxAnimation GetAnimation() const wxOVERRIDE
{ return m_animation; }
virtual void SetInactiveBitmap(const wxBitmap &bmp) wxOVERRIDE;
// override base class method
virtual bool SetBackgroundColour(const wxColour& col) wxOVERRIDE;
static wxAnimation CreateCompatibleAnimation();
public: // event handlers
void OnPaint(wxPaintEvent& event);
@@ -140,6 +93,7 @@ public: // extended API specific to this implementation of wxAnimateCtrl
{ return m_backingStore; }
protected: // internal utilities
virtual wxAnimationImpl* DoCreateAnimationImpl() const wxOVERRIDE;
// resize this control to fit m_animation
void FitToAnimation();
@@ -156,11 +110,19 @@ protected: // internal utilities
virtual void DisplayStaticImage() wxOVERRIDE;
virtual wxSize DoGetBestSize() const wxOVERRIDE;
// Helpers to safely access methods in the wxAnimationGenericImpl that are
// specific to the generic implementation
wxPoint AnimationImplGetFramePosition(unsigned int frame) const;
wxSize AnimationImplGetFrameSize(unsigned int frame) const;
wxAnimationDisposal AnimationImplGetDisposalMethod(unsigned int frame) const;
wxColour AnimationImplGetTransparentColour(unsigned int frame) const;
wxColour AnimationImplGetBackgroundColour() const;
protected:
unsigned int m_currentFrame; // Current frame
bool m_looped; // Looped, or not
wxTimer m_timer; // The timer
wxAnimation m_animation; // The animation
bool m_isPlaying; // Is the animation playing?
bool m_useWinBackgroundColour; // Use animation bg colour or window bg colour?
@@ -170,7 +132,7 @@ protected:
private:
typedef wxAnimationCtrlBase base_type;
wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl);
wxDECLARE_DYNAMIC_CLASS(wxGenericAnimationCtrl);
wxDECLARE_EVENT_TABLE();
};

View File

@@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/private/animate.h
// Purpose: wxAnimationGenericImpl
// Author: Julian Smart and Guillermo Rodriguez Garcia
// Modified by: Francesco Montorsi
// Created: 13/8/99
// Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_PRIVATE_ANIMATEH__
#define _WX_GENERIC_PRIVATE_ANIMATEH__
#include "wx/private/animate.h"
// ----------------------------------------------------------------------------
// wxAnimationGenericImpl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxAnimationGenericImpl : public wxAnimationImpl
{
public:
wxAnimationGenericImpl() : m_decoder(NULL) {}
virtual ~wxAnimationGenericImpl() { UnRef(); }
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;
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;
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;
private:
void UnRef();
wxAnimationDecoder* m_decoder;
wxDECLARE_NO_COPY_CLASS(wxAnimationGenericImpl);
};
#endif // _WX_GENERIC_PRIVATE_ANIMATEH__