Make OverlayPanel independent of AColor

This commit is contained in:
Paul Licameli 2019-07-13 16:08:29 -04:00
parent fb713a5339
commit 3a1456bf53
5 changed files with 42 additions and 41 deletions

View File

@ -32,20 +32,6 @@ It is also a place to document colour usage policy in Audacity
#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];

View File

@ -22,32 +22,6 @@ class wxDC;
class wxGraphicsContext;
class wxRect;
/// Used to restore pen, brush and logical-op in a DC back to what they were.
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 {};
};
/// Makes temporary drawing context changes that you back out of, RAII style
// It's like wxDCPenChanger, etc., but simple and general
class ADCChanger : public std::unique_ptr<wxDC, ::DCUnchanger>
{
using Base = std::unique_ptr<wxDC, ::DCUnchanger>;
public:
ADCChanger() : Base{} {}
ADCChanger(wxDC *pDC);
};
class AColor {
public:

View File

@ -19,6 +19,7 @@ Paul Licameli split from TrackPanel.cpp
#include "TrackPanelMouseEvent.h"
#include "HitTestResult.h"
#include "ViewInfo.h"
#include "widgets/OverlayPanel.h"
#include "tracks/ui/TrackView.h"

View File

@ -10,7 +10,6 @@
#include "OverlayPanel.h"
#include "Overlay.h"
#include "../AColor.h"
#include <algorithm>
#include <wx/dcclient.h>
@ -134,3 +133,18 @@ void OverlayPanel::Compress()
BEGIN_EVENT_TABLE(OverlayPanel, BackedPanel)
END_EVENT_TABLE()
// Maybe this class needs a better home
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()) } }
{}

View File

@ -50,4 +50,30 @@ private:
friend class GetInfoCommand;
};
/// Used to restore pen, brush and logical-op in a DC back to what they were.
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 {};
};
/// Makes temporary drawing context changes that you back out of, RAII style
// It's like wxDCPenChanger, etc., but simple and general
class ADCChanger : public std::unique_ptr<wxDC, ::DCUnchanger>
{
using Base = std::unique_ptr<wxDC, ::DCUnchanger>;
public:
ADCChanger() : Base{} {}
ADCChanger(wxDC *pDC);
};
#endif