From 9649e0bfe2741eee6e6f420c7b5233c8b399112f Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 3 May 2016 09:57:06 -0400 Subject: [PATCH] The ruler cursor (short vertical stroke at selection) should not change color... ... during play or record. That bug was introduced at b19ed258e963c9342f0a573a3f054d9a8336f7fa --- src/AColor.cpp | 18 +++++++++++++++++- src/AColor.h | 27 +++++++++++++++++++++++++++ src/widgets/Ruler.cpp | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/AColor.cpp b/src/AColor.cpp index f29e55e8e..b0f1d1241 100644 --- a/src/AColor.cpp +++ b/src/AColor.cpp @@ -17,16 +17,32 @@ It is also a place to document colour usage policy in Audacity *//********************************************************************/ +#include "Audacity.h" +#include "AColor.h" + #include #include #include #include -#include "AColor.h" #include "Theme.h" #include "Experimental.h" #include "AllThemeResources.h" +void DCUnchanger::operator () (wxDC *pDC) const +{ + if (pDC) { + pDC->SetPen(pen); + pDC->SetBrush(brush); + pDC->SetLogicalFunction(wxRasterOperationMode(logicalOperation)); + } +} + +ADCChanger::ADCChanger(wxDC *pDC) + : Base{ pDC, ::DCUnchanger{ pDC->GetBrush(), pDC->GetPen(), + long(pDC->GetLogicalFunction()) } } +{} + bool AColor::inited = false; wxBrush AColor::lightBrush[2]; wxBrush AColor::mediumBrush[2]; diff --git a/src/AColor.h b/src/AColor.h index bacbca786..5975db146 100644 --- a/src/AColor.h +++ b/src/AColor.h @@ -14,12 +14,39 @@ #ifndef __AUDACITY_COLOR__ #define __AUDACITY_COLOR__ +#include "MemoryX.h" #include #include class wxDC; class wxRect; +struct DCUnchanger { +public: + DCUnchanger() {} + + DCUnchanger(const wxBrush &brush_, const wxPen &pen_, long logicalOperation_) + : brush(brush_), pen(pen_), logicalOperation(logicalOperation_) + {} + + void operator () (wxDC *pDC) const; + + wxBrush brush {}; + wxPen pen {}; + long logicalOperation {}; +}; + +// Like wxDCPenChanger, etc., but simple and general +// Make temporary drawing context changes that you back out of, RAII style + +class ADCChanger : public std::unique_ptr +{ + using Base = std::unique_ptr; +public: + ADCChanger() : Base{} {} + ADCChanger(wxDC *pDC); +}; + class AColor { public: diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 5baf15f67..2cd02b2b6 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -3234,6 +3234,7 @@ void AdornedRulerPanel::DrawIndicator( double time, bool rec ) void AdornedRulerPanel::DoDrawIndicator (wxDC * dc, double time, bool playing, int width, bool scrub) { + ADCChanger changer(dc); // Undo pen and brush changes at function exit const int x = Time2Pos(time); AColor::IndicatorColor( dc, playing );