diff --git a/include/wx/animate.h b/include/wx/animate.h index f024081600..f1dbe6fbb8 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -18,7 +18,7 @@ #include "wx/animdecod.h" #include "wx/control.h" #include "wx/timer.h" -#include "wx/bitmap.h" +#include "wx/bmpbndl.h" class WXDLLIMPEXP_FWD_CORE wxAnimation; class wxAnimationImpl; @@ -110,11 +110,11 @@ public: virtual bool IsPlaying() const = 0; - virtual void SetInactiveBitmap(const wxBitmap &bmp); + virtual void SetInactiveBitmap(const wxBitmapBundle &bmp); // always return the original bitmap set in this control wxBitmap GetInactiveBitmap() const - { return m_bmpStatic; } + { return m_bmpStatic.GetBitmapFor(this); } wxAnimation CreateAnimation() const { return MakeAnimFromImpl(DoCreateAnimationImpl()); } @@ -134,7 +134,7 @@ protected: wxAnimation m_animation; // the inactive bitmap as it was set by the user - wxBitmap m_bmpStatic; + wxBitmapBundle m_bmpStatic; // the inactive bitmap currently shown in the control // (may differ in the size from m_bmpStatic) diff --git a/include/wx/generic/animate.h b/include/wx/generic/animate.h index 46413e01dd..0ec40a217f 100644 --- a/include/wx/generic/animate.h +++ b/include/wx/generic/animate.h @@ -11,7 +11,7 @@ #ifndef _WX_GENERIC_ANIMATEH__ #define _WX_GENERIC_ANIMATEH__ -#include "wx/bitmap.h" +#include "wx/bmpbndl.h" // ---------------------------------------------------------------------------- @@ -59,7 +59,7 @@ public: void SetAnimation(const wxAnimation &animation) wxOVERRIDE; - virtual void SetInactiveBitmap(const wxBitmap &bmp) wxOVERRIDE; + virtual void SetInactiveBitmap(const wxBitmapBundle &bmp) wxOVERRIDE; // override base class method virtual bool SetBackgroundColour(const wxColour& col) wxOVERRIDE; @@ -110,6 +110,15 @@ protected: // internal utilities virtual void DisplayStaticImage() wxOVERRIDE; virtual wxSize DoGetBestSize() const wxOVERRIDE; + // This function can be used as event handler for wxEVT_DPI_CHANGED event + // and simply calls UpdateStaticImage() to refresh the m_bmpStaticReal when it happens. + void WXHandleDPIChanged(wxDPIChangedEvent& event) + { + UpdateStaticImage(); + + event.Skip(); + } + // Helpers to safely access methods in the wxAnimationGenericImpl that are // specific to the generic implementation wxPoint AnimationImplGetFramePosition(unsigned int frame) const; diff --git a/interface/wx/animate.h b/interface/wx/animate.h index 17c525a49f..e9bd8ec28b 100644 --- a/interface/wx/animate.h +++ b/interface/wx/animate.h @@ -192,7 +192,7 @@ public: Note that the inactive bitmap, if smaller than the control's size, will be centered in the control; if bigger, it will be stretched to fit it. */ - virtual void SetInactiveBitmap(const wxBitmap& bmp); + virtual void SetInactiveBitmap(const wxBitmapBundle& bmp); /** Stops playing the animation. diff --git a/src/common/animatecmn.cpp b/src/common/animatecmn.cpp index e37a67a981..ecb9ea5b2e 100644 --- a/src/common/animatecmn.cpp +++ b/src/common/animatecmn.cpp @@ -138,16 +138,19 @@ void wxAnimationCtrlBase::UpdateStaticImage() // if given bitmap is not of the right size, recreate m_bmpStaticReal accordingly const wxSize &sz = GetClientSize(); - if (sz.GetWidth() != m_bmpStaticReal.GetWidth() || - sz.GetHeight() != m_bmpStaticReal.GetHeight()) + if (sz.GetWidth() != m_bmpStaticReal.GetLogicalWidth() || + sz.GetHeight() != m_bmpStaticReal.GetLogicalHeight()) { + wxBitmap bmpCurrent = m_bmpStatic.GetBitmapFor(this); + if (!m_bmpStaticReal.IsOk() || - m_bmpStaticReal.GetWidth() != sz.GetWidth() || - m_bmpStaticReal.GetHeight() != sz.GetHeight()) + m_bmpStaticReal.GetLogicalWidth() != sz.GetWidth() || + m_bmpStaticReal.GetLogicalHeight() != sz.GetHeight()) { // need to (re)create m_bmpStaticReal - if (!m_bmpStaticReal.Create(sz.GetWidth(), sz.GetHeight(), - m_bmpStatic.GetDepth())) + if (!m_bmpStaticReal.CreateWithLogicalSize(sz, + bmpCurrent.GetScaleFactor(), + bmpCurrent.GetDepth())) { wxLogDebug(wxT("Cannot create the static bitmap")); m_bmpStatic = wxNullBitmap; @@ -155,8 +158,8 @@ void wxAnimationCtrlBase::UpdateStaticImage() } } - if (m_bmpStatic.GetWidth() <= sz.GetWidth() && - m_bmpStatic.GetHeight() <= sz.GetHeight()) + if (bmpCurrent.GetLogicalWidth() <= sz.GetWidth() && + bmpCurrent.GetLogicalHeight() <= sz.GetHeight()) { // clear the background of m_bmpStaticReal wxBrush brush(GetBackgroundColour()); @@ -166,25 +169,25 @@ void wxAnimationCtrlBase::UpdateStaticImage() dc.Clear(); // center the user-provided bitmap in m_bmpStaticReal - dc.DrawBitmap(m_bmpStatic, - (sz.GetWidth()-m_bmpStatic.GetWidth())/2, - (sz.GetHeight()-m_bmpStatic.GetHeight())/2, + dc.DrawBitmap(bmpCurrent, + (sz.GetWidth()-bmpCurrent.GetLogicalWidth())/2, + (sz.GetHeight()-bmpCurrent.GetLogicalHeight())/2, true /* use mask */ ); } else { // the user-provided bitmap is bigger than our control, strech it - wxImage temp(m_bmpStatic.ConvertToImage()); + wxImage temp(bmpCurrent.ConvertToImage()); temp.Rescale(sz.GetWidth(), sz.GetHeight(), wxIMAGE_QUALITY_HIGH); m_bmpStaticReal = wxBitmap(temp); } } } -void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap &bmp) +void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmapBundle &bmp) { m_bmpStatic = bmp; - m_bmpStaticReal = bmp; + m_bmpStaticReal = bmp.GetBitmapFor(this); // if not playing, update the control now // NOTE: DisplayStaticImage() will call UpdateStaticImage automatically diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index 6b62e362c2..0262abfa5b 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -178,6 +178,8 @@ void wxGenericAnimationCtrl::Init() // use the window background colour by default to be consistent // with the GTK+ native version m_useWinBackgroundColour = true; + + Bind(wxEVT_DPI_CHANGED, &wxGenericAnimationCtrl::WXHandleDPIChanged, this); } bool wxGenericAnimationCtrl::Create(wxWindow *parent, wxWindowID id, @@ -263,14 +265,14 @@ void wxGenericAnimationCtrl::SetAnimation(const wxAnimation& animation) DisplayStaticImage(); } -void wxGenericAnimationCtrl::SetInactiveBitmap(const wxBitmap &bmp) +void wxGenericAnimationCtrl::SetInactiveBitmap(const wxBitmapBundle &bmp) { // if the bitmap has an associated mask, we need to set our background to // the colour of our parent otherwise when calling DrawCurrentFrame() // (which uses the bitmap's mask), our background colour would be used for // transparent areas - and that's not what we want (at least for // consistency with the GTK version) - if ( bmp.IsOk() && bmp.GetMask() != NULL && GetParent() != NULL ) + if ( bmp.IsOk() && bmp.GetBitmapFor(this).GetMask() != NULL && GetParent() != NULL ) SetBackgroundColour(GetParent()->GetBackgroundColour()); wxAnimationCtrlBase::SetInactiveBitmap(bmp);