From 2dd39d6b8c1023f8660e3e59e14d1815b7f351fd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Aug 2023 20:48:34 +0200 Subject: [PATCH] Stop using wxClientDC in wxGenericAnimationCtrl Just refresh the window and repaint it from OnPaint(). This was already effectively done under Mac and now this class can be also used in wxGTK (where it may be preferable to the native one as the latter one doesn't support high DPI animations yet). --- include/wx/generic/animate.h | 3 +++ src/generic/animateg.cpp | 37 ++++++++++++++---------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/include/wx/generic/animate.h b/include/wx/generic/animate.h index 1e2ca918fa..e673fa9928 100644 --- a/include/wx/generic/animate.h +++ b/include/wx/generic/animate.h @@ -140,6 +140,9 @@ protected: // on the screen private: + // True if we need to show the next frame after painting the current one. + bool m_needToShowNextFrame = false; + typedef wxAnimationCtrlBase base_type; wxDECLARE_DYNAMIC_CLASS(wxGenericAnimationCtrl); wxDECLARE_EVENT_TABLE(); diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index edebef5f87..365ffd0579 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -337,19 +337,9 @@ bool wxGenericAnimationCtrl::Play(bool looped) m_isPlaying = true; - // do a ClearBackground() to avoid that e.g. the custom static bitmap which - // was eventually shown previously remains partially drawn - ClearBackground(); + m_needToShowNextFrame = true; - // DrawCurrentFrame() will use our updated backing store - wxClientDC clientDC(this); - DrawCurrentFrame(clientDC); - - // start the timer - int delay = m_animation.GetDelay(0); - if (delay == 0) - delay = 1; // 0 is invalid timeout for wxTimer. - m_timer.StartOnce(delay); + Refresh(); return true; } @@ -562,6 +552,17 @@ void wxGenericAnimationCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) // clear then our area to the background colour DisposeToBackground(dc); } + + if ( m_needToShowNextFrame ) + { + m_needToShowNextFrame = false; + + // Set the timer for the next frame + int delay = m_animation.GetDelay(m_currentFrame); + if (delay == 0) + delay = 1; // 0 is invalid timeout for wxTimer. + m_timer.StartOnce(delay); + } } void wxGenericAnimationCtrl::OnTimer(wxTimerEvent &WXUNUSED(event)) @@ -581,19 +582,9 @@ void wxGenericAnimationCtrl::OnTimer(wxTimerEvent &WXUNUSED(event)) IncrementalUpdateBackingStore(); - wxClientDC dc(this); - DrawCurrentFrame(dc); + m_needToShowNextFrame = true; -#ifdef __WXMAC__ - // without this, the animation currently doesn't redraw under Mac Refresh(); -#endif // __WXMAC__ - - // Set the timer for the next frame - int delay = m_animation.GetDelay(m_currentFrame); - if (delay == 0) - delay = 1; // 0 is invalid timeout for wxTimer. - m_timer.StartOnce(delay); } void wxGenericAnimationCtrl::OnSize(wxSizeEvent &WXUNUSED(event))