diff --git a/include/wx/animate.h b/include/wx/animate.h index c04a884670..12cc2ed039 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -21,27 +21,25 @@ #include "wx/bitmap.h" class WXDLLIMPEXP_FWD_CORE wxAnimation; -class WXDLLIMPEXP_FWD_CORE wxGenericAnimation; extern WXDLLIMPEXP_DATA_CORE(wxAnimation) wxNullAnimation; -extern WXDLLIMPEXP_DATA_CORE(wxGenericAnimation) wxNullGenericAnimation; extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[]; // ---------------------------------------------------------------------------- -// wxAnimation +// wxAnimationImpl // ---------------------------------------------------------------------------- -WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV); +enum wxAnimationImplType +{ + wxANIMATION_IMPL_TYPE_NATIVE, + wxANIMATION_IMPL_TYPE_GENERIC +}; -// ---------------------------------------------------------------------------- -// wxAnimationBase -// ---------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxAnimationBase : public wxObject +class WXDLLIMPEXP_CORE wxAnimationImpl : public wxObject, public wxRefCounter { public: - wxAnimationBase() {} + wxAnimationImpl() {} virtual bool IsOk() const = 0; @@ -65,10 +63,47 @@ public: virtual wxColour GetBackgroundColour() const = 0; protected: - wxDECLARE_ABSTRACT_CLASS(wxAnimationBase); + wxDECLARE_ABSTRACT_CLASS(wxAnimationImpl); }; +// ---------------------------------------------------------------------------- +// wxAnimation +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_CORE wxAnimation : public wxObject +{ +public: + wxAnimation(wxAnimationImplType implType = wxANIMATION_IMPL_TYPE_NATIVE); + wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY, + wxAnimationImplType implType = wxANIMATION_IMPL_TYPE_NATIVE); + wxAnimation(const wxAnimation& other); + + wxAnimationImpl* GetImpl() const + { return static_cast(m_refData); } + + bool IsOk() const + { return GetImpl() && GetImpl()->IsOk(); } + + int GetDelay(unsigned int frame) const; + unsigned int GetFrameCount() const; + wxImage GetFrame(unsigned int frame); + wxSize GetSize() const; + + bool LoadFile(const wxString& name, wxAnimationType type = wxANIMATION_TYPE_ANY); + bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY); + + // extended interface used only by wxGenericAnimationCtrl + 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: + wxDECLARE_DYNAMIC_CLASS(wxAnimation); +}; + // ---------------------------------------------------------------------------- // wxAnimationCtrlBase @@ -92,6 +127,9 @@ public: virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) = 0; + virtual void SetAnimation(const wxAnimation &anim) = 0; + virtual wxAnimation GetAnimation() const = 0; + virtual bool Play() = 0; virtual void Stop() = 0; @@ -126,25 +164,11 @@ private: // include the platform-specific version of the wxAnimationCtrl class // ---------------------------------------------------------------------------- +#include "wx/generic/animate.h" + #if defined(__WXGTK20__) - #include "wx/generic/animate.h" #include "wx/gtk/animate.h" #else - #include "wx/generic/animate.h" - - class WXDLLIMPEXP_ADV wxAnimation : public wxGenericAnimation - { - public: - wxAnimation() - : wxGenericAnimation() {} - wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) - : wxGenericAnimation(name, type) {} - wxAnimation(const wxGenericAnimation& other) - : wxGenericAnimation(other) {} - private: - wxDECLARE_DYNAMIC_CLASS(wxAnimation); - }; - class WXDLLIMPEXP_ADV wxAnimationCtrl : public wxGenericAnimationCtrl { public: @@ -162,22 +186,23 @@ private: {} bool Create(wxWindow *parent, wxWindowID id, - const wxAnimation& anim = wxNullGenericAnimation, + const wxAnimation& anim = wxNullAnimation, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxAC_DEFAULT_STYLE, const wxString& name = wxAnimationCtrlNameStr) { return wxGenericAnimationCtrl::Create(parent, id, anim, pos, size, style, name); } - void SetAnimation(const wxAnimation &anim) - { wxGenericAnimationCtrl::SetAnimation(anim); } - virtual wxAnimation GetAnimation() const - { return wxAnimation(m_animation) ; } + static wxAnimationImpl* CreateAnimationImpl(wxAnimationImplType WXUNUSED(implType)) + { + // For the generic widget we always use the generic impl and ignore the given type + return new wxAnimationGenericImpl(); + } private: wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl); }; -#endif +#endif // defined(__WXGTK20__) #endif // wxUSE_ANIMATIONCTRL diff --git a/include/wx/generic/animate.h b/include/wx/generic/animate.h index 29a87ae4cc..90ecdd7486 100644 --- a/include/wx/generic/animate.h +++ b/include/wx/generic/animate.h @@ -17,14 +17,14 @@ // wxGenericAnimation // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_ADV wxGenericAnimation : public wxAnimationBase +WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV); + +class WXDLLIMPEXP_ADV wxAnimationGenericImpl : public wxAnimationImpl { public: - wxGenericAnimation() {} - wxGenericAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) - { LoadFile(name, type); } + wxAnimationGenericImpl() {} - virtual bool IsOk() const + virtual bool IsOk() const wxOVERRIDE { return m_refData != NULL; } virtual unsigned int GetFrameCount() const wxOVERRIDE; @@ -56,7 +56,7 @@ public: static void CleanUpHandlers(); static void InitStandardHandlers(); - wxDECLARE_DYNAMIC_CLASS(wxGenericAnimation); + wxDECLARE_DYNAMIC_CLASS(wxAnimationGenericImpl); }; @@ -70,7 +70,7 @@ public: wxGenericAnimationCtrl() { Init(); } wxGenericAnimationCtrl(wxWindow *parent, wxWindowID id, - const wxGenericAnimation& anim = wxNullGenericAnimation, + const wxAnimation& anim = wxNullAnimation, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxAC_DEFAULT_STYLE, @@ -84,7 +84,7 @@ public: void Init(); bool Create(wxWindow *parent, wxWindowID id, - const wxGenericAnimation& anim = wxNullGenericAnimation, + const wxAnimation& anim = wxNullAnimation, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxAC_DEFAULT_STYLE, @@ -103,8 +103,8 @@ public: virtual bool IsPlaying() const wxOVERRIDE { return m_isPlaying; } - void SetAnimation(const wxGenericAnimation &animation); - wxGenericAnimation GetAnimation() const + void SetAnimation(const wxAnimation &animation) wxOVERRIDE; + wxAnimation GetAnimation() const wxOVERRIDE { return m_animation; } virtual void SetInactiveBitmap(const wxBitmap &bmp) wxOVERRIDE; @@ -159,7 +159,7 @@ protected: unsigned int m_currentFrame; // Current frame bool m_looped; // Looped, or not wxTimer m_timer; // The timer - wxGenericAnimation m_animation; // The animation + wxAnimation m_animation; // The animation bool m_isPlaying; // Is the animation playing? bool m_useWinBackgroundColour; // Use animation bg colour or window bg colour? diff --git a/src/common/animatecmn.cpp b/src/common/animatecmn.cpp index ea34aca2d1..5b5faee437 100644 --- a/src/common/animatecmn.cpp +++ b/src/common/animatecmn.cpp @@ -30,19 +30,108 @@ #include "wx/dcmemory.h" const char wxAnimationCtrlNameStr[] = "animationctrl"; -wxGenericAnimation wxNullGenericAnimation; wxAnimation wxNullAnimation; -wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject); +wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationImpl, wxObject); +wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxObject); wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl); -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 + +// ---------------------------------------------------------------------------- +// wxAnimation +// ---------------------------------------------------------------------------- + +wxAnimation::wxAnimation(wxAnimationImplType implType) +{ + m_refData = wxAnimationCtrl::CreateAnimationImpl(implType); +} + +wxAnimation::wxAnimation(const wxString &name, wxAnimationType type, + wxAnimationImplType implType) +{ + m_refData = wxAnimationCtrl::CreateAnimationImpl(implType); + LoadFile(name, type); +} + +wxAnimation::wxAnimation(const wxAnimation& other) +{ + Ref(other); +} + +int wxAnimation::GetDelay(unsigned int frame) const +{ + wxCHECK_MSG( IsOk(), -1, wxT("invalid animation") ); + return GetImpl()->GetDelay(frame); +} + +unsigned int wxAnimation::GetFrameCount() const +{ + wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); + return GetImpl()->GetFrameCount(); +} + +wxImage wxAnimation::GetFrame(unsigned int frame) +{ + wxCHECK_MSG( IsOk(), wxNullImage, wxT("invalid animation") ); + return GetImpl()->GetFrame(frame); +} + +wxSize wxAnimation::GetSize() const +{ + wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); + return GetImpl()->GetSize(); +} + +bool wxAnimation::LoadFile(const wxString& name, wxAnimationType type) +{ + // the animation impl may not be fully ready until after it has loaded the + // file, so just check GetImpl the Load methods + wxCHECK_MSG( GetImpl(), false, wxT("invalid animation") ); + return GetImpl()->LoadFile(name, type); +} + +bool wxAnimation::Load(wxInputStream& stream, wxAnimationType type) +{ + wxCHECK_MSG( GetImpl(), false, wxT("invalid animation") ); + return GetImpl()->Load(stream, type); +} + +wxPoint wxAnimation::GetFramePosition(unsigned int frame) const +{ + wxCHECK_MSG( IsOk(), wxDefaultPosition, wxT("invalid animation") ); + return GetImpl()->GetFramePosition(frame); +} + +wxSize wxAnimation::GetFrameSize(unsigned int frame) const +{ + wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); + return GetImpl()->GetFrameSize(frame); +} + +wxAnimationDisposal wxAnimation::GetDisposalMethod(unsigned int frame) const +{ + wxCHECK_MSG( IsOk(), wxANIM_UNSPECIFIED, wxT("invalid animation") ); + return GetImpl()->GetDisposalMethod(frame); +} + +wxColour wxAnimation::GetTransparentColour(unsigned int frame) const +{ + wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); + return GetImpl()->GetTransparentColour(frame); +} + +wxColour wxAnimation::GetBackgroundColour() const +{ + wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); + return GetImpl()->GetBackgroundColour(); +} + + // ---------------------------------------------------------------------------- // wxAnimationCtrlBase // ---------------------------------------------------------------------------- diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index 787beae25a..648407111d 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -32,30 +32,32 @@ #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxAnimationDecoderList) -wxAnimationDecoderList wxGenericAnimation::sm_handlers; +wxAnimationDecoderList wxAnimationGenericImpl::sm_handlers; // ---------------------------------------------------------------------------- // wxAnimation // ---------------------------------------------------------------------------- +wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGenericImpl, wxAnimationImpl); + #define M_ANIMDATA static_cast(m_refData) -wxSize wxGenericAnimation::GetSize() const +wxSize wxAnimationGenericImpl::GetSize() const { wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); return M_ANIMDATA->GetAnimationSize(); } -unsigned int wxGenericAnimation::GetFrameCount() const +unsigned int wxAnimationGenericImpl::GetFrameCount() const { wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); return M_ANIMDATA->GetFrameCount(); } -wxImage wxGenericAnimation::GetFrame(unsigned int i) const +wxImage wxAnimationGenericImpl::GetFrame(unsigned int i) const { wxCHECK_MSG( IsOk(), wxNullImage, wxT("invalid animation") ); @@ -65,49 +67,49 @@ wxImage wxGenericAnimation::GetFrame(unsigned int i) const return ret; } -int wxGenericAnimation::GetDelay(unsigned int i) const +int wxAnimationGenericImpl::GetDelay(unsigned int i) const { wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); return M_ANIMDATA->GetDelay(i); } -wxPoint wxGenericAnimation::GetFramePosition(unsigned int frame) const +wxPoint wxAnimationGenericImpl::GetFramePosition(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxDefaultPosition, wxT("invalid animation") ); return M_ANIMDATA->GetFramePosition(frame); } -wxSize wxGenericAnimation::GetFrameSize(unsigned int frame) const +wxSize wxAnimationGenericImpl::GetFrameSize(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); return M_ANIMDATA->GetFrameSize(frame); } -wxAnimationDisposal wxGenericAnimation::GetDisposalMethod(unsigned int frame) const +wxAnimationDisposal wxAnimationGenericImpl::GetDisposalMethod(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxANIM_UNSPECIFIED, wxT("invalid animation") ); return M_ANIMDATA->GetDisposalMethod(frame); } -wxColour wxGenericAnimation::GetTransparentColour(unsigned int frame) const +wxColour wxAnimationGenericImpl::GetTransparentColour(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); return M_ANIMDATA->GetTransparentColour(frame); } -wxColour wxGenericAnimation::GetBackgroundColour() const +wxColour wxAnimationGenericImpl::GetBackgroundColour() const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); return M_ANIMDATA->GetBackgroundColour(); } -bool wxGenericAnimation::LoadFile(const wxString& filename, wxAnimationType type) +bool wxAnimationGenericImpl::LoadFile(const wxString& filename, wxAnimationType type) { wxFileInputStream stream(filename); if ( !stream.IsOk() ) @@ -116,7 +118,7 @@ bool wxGenericAnimation::LoadFile(const wxString& filename, wxAnimationType type return Load(stream, type); } -bool wxGenericAnimation::Load(wxInputStream &stream, wxAnimationType type) +bool wxAnimationGenericImpl::Load(wxInputStream &stream, wxAnimationType type) { UnRef(); @@ -169,7 +171,7 @@ bool wxGenericAnimation::Load(wxInputStream &stream, wxAnimationType type) // animation decoders // ---------------------------------------------------------------------------- -void wxGenericAnimation::AddHandler( wxAnimationDecoder *handler ) +void wxAnimationGenericImpl::AddHandler( wxAnimationDecoder *handler ) { // Check for an existing handler of the type being added. if (FindHandler( handler->GetType() ) == 0) @@ -189,7 +191,7 @@ void wxGenericAnimation::AddHandler( wxAnimationDecoder *handler ) } } -void wxGenericAnimation::InsertHandler( wxAnimationDecoder *handler ) +void wxAnimationGenericImpl::InsertHandler( wxAnimationDecoder *handler ) { // Check for an existing handler of the type being added. if (FindHandler( handler->GetType() ) == 0) @@ -205,7 +207,7 @@ void wxGenericAnimation::InsertHandler( wxAnimationDecoder *handler ) } } -const wxAnimationDecoder *wxGenericAnimation::FindHandler( wxAnimationType animType ) +const wxAnimationDecoder *wxAnimationGenericImpl::FindHandler( wxAnimationType animType ) { wxAnimationDecoderList::compatibility_iterator node = sm_handlers.GetFirst(); while (node) @@ -217,7 +219,7 @@ const wxAnimationDecoder *wxGenericAnimation::FindHandler( wxAnimationType animT return 0; } -void wxGenericAnimation::InitStandardHandlers() +void wxAnimationGenericImpl::InitStandardHandlers() { #if wxUSE_GIF AddHandler(new wxGIFDecoder); @@ -227,7 +229,7 @@ void wxGenericAnimation::InitStandardHandlers() #endif // wxUSE_ICO_CUR } -void wxGenericAnimation::CleanUpHandlers() +void wxAnimationGenericImpl::CleanUpHandlers() { wxAnimationDecoderList::compatibility_iterator node = sm_handlers.GetFirst(); while (node) @@ -251,8 +253,8 @@ class wxAnimationModule: public wxModule wxDECLARE_DYNAMIC_CLASS(wxAnimationModule); public: wxAnimationModule() {} - bool OnInit() wxOVERRIDE { wxGenericAnimation::InitStandardHandlers(); return true; } - void OnExit() wxOVERRIDE { wxGenericAnimation::CleanUpHandlers(); } + bool OnInit() wxOVERRIDE { wxAnimationGenericImpl::InitStandardHandlers(); return true; } + void OnExit() wxOVERRIDE { wxAnimationGenericImpl::CleanUpHandlers(); } }; wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationModule, wxModule); @@ -281,7 +283,7 @@ void wxGenericAnimationCtrl::Init() } bool wxGenericAnimationCtrl::Create(wxWindow *parent, wxWindowID id, - const wxGenericAnimation& animation, const wxPoint& pos, + const wxAnimation& animation, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { m_timer.SetOwner(this); @@ -312,7 +314,7 @@ bool wxGenericAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType bool wxGenericAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type) { - wxGenericAnimation anim; + wxAnimation anim(wxANIMATION_IMPL_TYPE_GENERIC); if ( !anim.Load(stream, type) || !anim.IsOk() ) return false; @@ -328,7 +330,7 @@ wxSize wxGenericAnimationCtrl::DoGetBestSize() const return FromDIP(wxSize(100, 100)); } -void wxGenericAnimationCtrl::SetAnimation(const wxGenericAnimation& animation) +void wxGenericAnimationCtrl::SetAnimation(const wxAnimation& animation) { if (IsPlaying()) Stop(); @@ -553,7 +555,7 @@ void wxGenericAnimationCtrl::DisplayStaticImage() if (!m_animation.IsOk() || !RebuildBackingStoreUpToFrame(0)) { - m_animation = wxNullGenericAnimation; + m_animation = wxNullAnimation; DisposeToBackground(); } }