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

Drawing sequence for overlays independent of insertion call sequence

This commit is contained in:
Paul Licameli
2019-04-28 06:33:27 -04:00
parent f123ea5faa
commit 227fb315ea
11 changed files with 51 additions and 3 deletions

View File

@@ -93,6 +93,10 @@ class Overlay
public:
virtual ~Overlay() = 0;
///\brief This number determines an ordering of overlays, so that those
/// with higher numbers overpaint those with lower numbers that intersect
virtual unsigned SequenceNumber() const = 0;
// nonvirtual wrapper
std::pair<wxRect, bool> GetRectangle(wxSize size);

View File

@@ -23,7 +23,16 @@ OverlayPanel::OverlayPanel(wxWindow * parent, wxWindowID id,
void OverlayPanel::AddOverlay( const std::weak_ptr<Overlay> &pOverlay)
{
mOverlays.push_back(pOverlay);
if (pOverlay.expired())
return;
Compress();
auto iter = std::lower_bound( mOverlays.begin(), mOverlays.end(),
pOverlay.lock()->SequenceNumber(),
[]( const OverlayPtr &p, unsigned value ) {
return p.expired() || p.lock()->SequenceNumber() < value;
}
);
mOverlays.insert(iter, pOverlay);
}
void OverlayPanel::ClearOverlays()

View File

@@ -40,8 +40,10 @@ public:
void DrawOverlays(bool repaint_all, wxDC *pDC = nullptr);
private:
using OverlayPtr = std::weak_ptr<Overlay>;
void Compress();
std::vector< std::weak_ptr<Overlay> > mOverlays;
std::vector< OverlayPtr > mOverlays;
DECLARE_EVENT_TABLE()