From 717887939703fdb9d45ae97c35c4675836a7cb0b Mon Sep 17 00:00:00 2001 From: James Crook Date: Fri, 13 Apr 2018 09:01:31 +0100 Subject: [PATCH] Flicker-Free Grabbers and Mic/Speaker icons. Previously we were clearing in Erase Background, giving lots of flicker when resizing some toolbar. Also fixed a mac Slider background painting issue. --- src/toolbars/DeviceToolBar.cpp | 5 +++-- src/toolbars/MixerToolBar.cpp | 5 +++-- src/toolbars/ToolBar.cpp | 4 ++-- src/widgets/ASlider.cpp | 4 ++-- src/widgets/Grabber.cpp | 14 ++++++++++++++ src/widgets/Grabber.h | 30 ++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index ff1a360e0..1140b917a 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -44,6 +44,7 @@ #include "../widgets/Grabber.h" #include "../DeviceManager.h" #include "../widgets/ErrorDialog.h" +#include "../widgets/Grabber.h" #if wxUSE_ACCESSIBILITY #include "../widgets/WindowAccessible.h" @@ -104,7 +105,7 @@ void DeviceToolBar::Populate() Add(mHost, 0, wxALIGN_CENTER); // Input device - Add(safenew wxStaticBitmap(this, + Add(safenew AStaticBitmap(this, wxID_ANY, theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER); mInput = safenew wxChoice(this, @@ -128,7 +129,7 @@ void DeviceToolBar::Populate() Add(mInputChannels, 0, wxALIGN_CENTER); // Output device - Add(safenew wxStaticBitmap(this, + Add(safenew AStaticBitmap(this, wxID_ANY, theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER); mOutput = safenew wxChoice(this, diff --git a/src/toolbars/MixerToolBar.cpp b/src/toolbars/MixerToolBar.cpp index dd0d32c6e..4091dec2c 100644 --- a/src/toolbars/MixerToolBar.cpp +++ b/src/toolbars/MixerToolBar.cpp @@ -39,6 +39,7 @@ #include "../Project.h" #include "../Theme.h" #include "../widgets/ASlider.h" +#include "../widgets/Grabber.h" IMPLEMENT_CLASS(MixerToolBar, ToolBar); @@ -74,7 +75,7 @@ void MixerToolBar::Populate() { SetBackgroundColour( theTheme.Colour( clrMedium ) ); // Recording icon and slider - Add(safenew wxStaticBitmap(this, + Add(safenew AStaticBitmap(this, wxID_ANY, theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER); mInputSlider = safenew ASlider(this, wxID_ANY, _("Recording Volume"), @@ -83,7 +84,7 @@ void MixerToolBar::Populate() Add(mInputSlider, 0, wxALIGN_CENTER); // Playback icon and slider - Add(safenew wxStaticBitmap(this, + Add(safenew AStaticBitmap(this, wxID_ANY, theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER); mOutputSlider = safenew ASlider(this, wxID_ANY, _("Playback Volume"), diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp index 273b420a5..ab1e6ff21 100644 --- a/src/toolbars/ToolBar.cpp +++ b/src/toolbars/ToolBar.cpp @@ -860,8 +860,8 @@ void ToolBar::OnErase( wxEraseEvent & WXUNUSED(event) ) // void ToolBar::OnPaint( wxPaintEvent & event ) { - wxPaintDC dc( (wxWindow *) event.GetEventObject() ); - + //wxPaintDC dc( (wxWindow *) event.GetEventObject() ); + wxPaintDC dc( this ); // Start with a clean background // // Under GTK, we specifically set the toolbar background to the background diff --git a/src/widgets/ASlider.cpp b/src/widgets/ASlider.cpp index 931a682fe..7a25fa58b 100644 --- a/src/widgets/ASlider.cpp +++ b/src/widgets/ASlider.cpp @@ -573,12 +573,12 @@ void LWSlider::OnPaint(wxDC &dc, bool highlight) thumbPos += 8-mThumbHeight/2; } -#if !defined(__WXMAC__) + // Previously not done on mac, but with wx3.1.1. it + // needs to be. if( mHW ) { dc.Clear(); } -#endif dc.DrawBitmap(*mBitmap, mLeft, mTop, true); const auto &thumbBitmap = diff --git a/src/widgets/Grabber.cpp b/src/widgets/Grabber.cpp index dd0786ecf..eafa6e67a 100644 --- a/src/widgets/Grabber.cpp +++ b/src/widgets/Grabber.cpp @@ -45,6 +45,7 @@ BEGIN_EVENT_TABLE(Grabber, wxWindow) EVT_ENTER_WINDOW(Grabber::OnEnter) EVT_LEAVE_WINDOW(Grabber::OnLeave) EVT_LEFT_DOWN(Grabber::OnLeftDown) + EVT_ERASE_BACKGROUND( Grabber::OnErase ) EVT_PAINT(Grabber::OnPaint) EVT_KEY_DOWN(Grabber::OnKeyDown) END_EVENT_TABLE() @@ -238,6 +239,11 @@ void Grabber::OnLeave(wxMouseEvent & WXUNUSED(event)) } } +void Grabber::OnErase( wxEraseEvent & WXUNUSED(event) ) +{ + // Ignore it to prevent flashing +} + // // Handle the paint events // @@ -260,3 +266,11 @@ void Grabber::OnKeyDown(wxKeyEvent &event) SendEvent(EVT_GRABBER_CLICKED, wxPoint{ -1, -1 }, true); } } + +// Piggy back in same source file as Grabber. +// Audcaity Flicker-free StaticBitmap. +BEGIN_EVENT_TABLE(AStaticBitmap,wxStaticBitmap) + EVT_ERASE_BACKGROUND(AStaticBitmap::OnErase) +END_EVENT_TABLE() + + diff --git a/src/widgets/Grabber.h b/src/widgets/Grabber.h index 9d3acbfc0..53d23904d 100644 --- a/src/widgets/Grabber.h +++ b/src/widgets/Grabber.h @@ -30,6 +30,7 @@ around to NEW positions. #include "wx/event.h" #include "wx/gdicmn.h" #include "wx/window.h" +#include //////////////////////////////////////////////////////////// /// Grabber Class @@ -118,6 +119,7 @@ class Grabber final : public wxWindow void OnLeftDown(wxMouseEvent & event); void OnEnter(wxMouseEvent & event); void OnLeave(wxMouseEvent & event); + void OnErase(wxEraseEvent & event); void OnPaint(wxPaintEvent & event); void OnKeyDown(wxKeyEvent & event); @@ -135,4 +137,32 @@ class Grabber final : public wxWindow DECLARE_EVENT_TABLE() }; +// Piggy back in same source file as Grabber. +// Audcaity Flicker-free StaticBitmap. +class AStaticBitmap : public wxStaticBitmap { + public: + AStaticBitmap(wxWindow *parent, + wxWindowID id, + const wxBitmap& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxStaticBitmapNameStr) : + + wxStaticBitmap(parent, + id, + label, + pos , + size , + style, + name ) + {}; + void OnErase(wxEraseEvent& event) { + static_cast(event); + }; + DECLARE_EVENT_TABLE() +}; + + + #endif