1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

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

@@ -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