Remove the generic-specific methods from the wxAnimation API

This commit is contained in:
Robin Dunn
2020-04-01 13:30:49 -07:00
parent cd74255da3
commit 085f08aefe
4 changed files with 54 additions and 59 deletions

View File

@@ -57,13 +57,6 @@ public:
virtual bool Load(wxInputStream& stream, virtual bool Load(wxInputStream& stream,
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0; wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
// extended interface used only by the generic implementation of wxAnimationCtrl
virtual wxPoint GetFramePosition(unsigned int frame) const = 0;
virtual wxSize GetFrameSize(unsigned int frame) const = 0;
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const = 0;
virtual wxColour GetTransparentColour(unsigned int frame) const = 0;
virtual wxColour GetBackgroundColour() const = 0;
protected: protected:
wxDECLARE_ABSTRACT_CLASS(wxAnimationImpl); wxDECLARE_ABSTRACT_CLASS(wxAnimationImpl);
}; };
@@ -95,13 +88,6 @@ public:
bool LoadFile(const wxString& name, wxAnimationType type = wxANIMATION_TYPE_ANY); bool LoadFile(const wxString& name, wxAnimationType type = wxANIMATION_TYPE_ANY);
bool Load(wxInputStream& stream, 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: protected:
wxDECLARE_DYNAMIC_CLASS(wxAnimation); wxDECLARE_DYNAMIC_CLASS(wxAnimation);
}; };

View File

@@ -158,6 +158,15 @@ protected: // internal utilities
virtual void DisplayStaticImage() wxOVERRIDE; virtual void DisplayStaticImage() wxOVERRIDE;
virtual wxSize DoGetBestSize() const wxOVERRIDE; virtual wxSize DoGetBestSize() const wxOVERRIDE;
// Helpers to safely access methods in the wxAnimationGenericImpl that are
// specific to the generic implementation
wxPoint animation_GetFramePosition(unsigned int frame) const;
wxSize animation_GetFrameSize(unsigned int frame) const;
wxAnimationDisposal animation_GetDisposalMethod(unsigned int frame) const;
wxColour animation_GetTransparentColour(unsigned int frame) const;
wxColour animation_GetBackgroundColour() const;
protected: protected:
unsigned int m_currentFrame; // Current frame unsigned int m_currentFrame; // Current frame
bool m_looped; // Looped, or not bool m_looped; // Looped, or not

View File

@@ -101,36 +101,6 @@ bool wxAnimation::Load(wxInputStream& stream, wxAnimationType type)
return GetImpl()->Load(stream, type); 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 // wxAnimationCtrlBase

View File

@@ -335,9 +335,6 @@ void wxGenericAnimationCtrl::SetAnimation(const wxAnimation& animation)
if (IsPlaying()) if (IsPlaying())
Stop(); Stop();
wxCHECK_RET(animation.GetImpl()->GetImplType() == wxANIMATION_IMPL_TYPE_GENERIC,
wxT("incorrect animation implementation type provided") );
// set new animation even if it's wxNullAnimation // set new animation even if it's wxNullAnimation
m_animation = animation; m_animation = animation;
if (!m_animation.IsOk()) if (!m_animation.IsOk())
@@ -349,7 +346,7 @@ void wxGenericAnimationCtrl::SetAnimation(const wxAnimation& animation)
wxCHECK_RET(animation.GetImpl()->GetImplType() == wxANIMATION_IMPL_TYPE_GENERIC, wxCHECK_RET(animation.GetImpl()->GetImplType() == wxANIMATION_IMPL_TYPE_GENERIC,
wxT("incorrect animation implementation type provided") ); wxT("incorrect animation implementation type provided") );
if (m_animation.GetBackgroundColour() == wxNullColour) if (animation_GetBackgroundColour() == wxNullColour)
SetUseWindowBackgroundColour(); SetUseWindowBackgroundColour();
if (!this->HasFlag(wxAC_NO_AUTORESIZE)) if (!this->HasFlag(wxAC_NO_AUTORESIZE))
FitToAnimation(); FitToAnimation();
@@ -465,14 +462,14 @@ bool wxGenericAnimationCtrl::RebuildBackingStoreUpToFrame(unsigned int frame)
// Draw all intermediate frames that haven't been removed from the animation // Draw all intermediate frames that haven't been removed from the animation
for (unsigned int i = 0; i < frame; i++) for (unsigned int i = 0; i < frame; i++)
{ {
if (m_animation.GetDisposalMethod(i) == wxANIM_DONOTREMOVE || if (animation_GetDisposalMethod(i) == wxANIM_DONOTREMOVE ||
m_animation.GetDisposalMethod(i) == wxANIM_UNSPECIFIED) animation_GetDisposalMethod(i) == wxANIM_UNSPECIFIED)
{ {
DrawFrame(dc, i); DrawFrame(dc, i);
} }
else if (m_animation.GetDisposalMethod(i) == wxANIM_TOBACKGROUND) else if (animation_GetDisposalMethod(i) == wxANIM_TOBACKGROUND)
DisposeToBackground(dc, m_animation.GetFramePosition(i), DisposeToBackground(dc, animation_GetFramePosition(i),
m_animation.GetFrameSize(i)); animation_GetFrameSize(i));
} }
// finally draw this frame // finally draw this frame
@@ -500,11 +497,11 @@ void wxGenericAnimationCtrl::IncrementalUpdateBackingStore()
} }
else else
{ {
switch (m_animation.GetDisposalMethod(m_currentFrame-1)) switch (animation_GetDisposalMethod(m_currentFrame-1))
{ {
case wxANIM_TOBACKGROUND: case wxANIM_TOBACKGROUND:
DisposeToBackground(dc, m_animation.GetFramePosition(m_currentFrame-1), DisposeToBackground(dc, animation_GetFramePosition(m_currentFrame-1),
m_animation.GetFrameSize(m_currentFrame-1)); animation_GetFrameSize(m_currentFrame-1));
break; break;
case wxANIM_TOPREVIOUS: case wxANIM_TOPREVIOUS:
@@ -578,7 +575,7 @@ void wxGenericAnimationCtrl::DrawFrame(wxDC &dc, unsigned int frame)
// If wxAnimationDecoder had a function to convert directly from its // If wxAnimationDecoder had a function to convert directly from its
// internal format to a port-specific wxBitmap, it would be somewhat faster. // internal format to a port-specific wxBitmap, it would be somewhat faster.
wxBitmap bmp(m_animation.GetFrame(frame)); wxBitmap bmp(m_animation.GetFrame(frame));
dc.DrawBitmap(bmp, m_animation.GetFramePosition(frame), dc.DrawBitmap(bmp, animation_GetFramePosition(frame),
true /* use mask */); true /* use mask */);
} }
@@ -603,7 +600,7 @@ void wxGenericAnimationCtrl::DisposeToBackground(wxDC& dc)
{ {
wxColour col = IsUsingWindowBackgroundColour() wxColour col = IsUsingWindowBackgroundColour()
? GetBackgroundColour() ? GetBackgroundColour()
: m_animation.GetBackgroundColour(); : animation_GetBackgroundColour();
wxBrush brush(col); wxBrush brush(col);
dc.SetBackground(brush); dc.SetBackground(brush);
@@ -614,7 +611,7 @@ void wxGenericAnimationCtrl::DisposeToBackground(wxDC& dc, const wxPoint &pos, c
{ {
wxColour col = IsUsingWindowBackgroundColour() wxColour col = IsUsingWindowBackgroundColour()
? GetBackgroundColour() ? GetBackgroundColour()
: m_animation.GetBackgroundColour(); : animation_GetBackgroundColour();
wxBrush brush(col); wxBrush brush(col);
dc.SetBrush(brush); // SetBrush and not SetBackground !! dc.SetBrush(brush); // SetBrush and not SetBackground !!
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
@@ -698,4 +695,37 @@ void wxGenericAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event))
} }
} }
// helpers to safely access wxAnimationGenericImpl methods
#define ANIMATION (static_cast<wxAnimationGenericImpl*>(m_animation.GetImpl()))
wxPoint wxGenericAnimationCtrl::animation_GetFramePosition(unsigned int frame) const
{
wxCHECK_MSG( m_animation.IsOk(), wxDefaultPosition, wxT("invalid animation") );
return ANIMATION->GetFramePosition(frame);
}
wxSize wxGenericAnimationCtrl::animation_GetFrameSize(unsigned int frame) const
{
wxCHECK_MSG( m_animation.IsOk(), wxDefaultSize, wxT("invalid animation") );
return ANIMATION->GetFrameSize(frame);
}
wxAnimationDisposal wxGenericAnimationCtrl::animation_GetDisposalMethod(unsigned int frame) const
{
wxCHECK_MSG( m_animation.IsOk(), wxANIM_UNSPECIFIED, wxT("invalid animation") );
return ANIMATION->GetDisposalMethod(frame);
}
wxColour wxGenericAnimationCtrl::animation_GetTransparentColour(unsigned int frame) const
{
wxCHECK_MSG( m_animation.IsOk(), wxNullColour, wxT("invalid animation") );
return ANIMATION->GetTransparentColour(frame);
}
wxColour wxGenericAnimationCtrl::animation_GetBackgroundColour() const
{
wxCHECK_MSG( m_animation.IsOk(), wxNullColour, wxT("invalid animation") );
return ANIMATION->GetBackgroundColour();
}
#endif // wxUSE_ANIMATIONCTRL #endif // wxUSE_ANIMATIONCTRL