Audacity 3.2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
OverlayPanel Class Reference

#include <OverlayPanel.h>

Inheritance diagram for OverlayPanel:
[legend]
Collaboration diagram for OverlayPanel:
[legend]

Public Member Functions

 OverlayPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style=wxTAB_TRAVERSAL|wxNO_BORDER)
 
void AddOverlay (const std::weak_ptr< Overlay > &pOverlay)
 
void ClearOverlays ()
 
void DrawOverlays (bool repaint_all, wxDC *pDC=nullptr)
 
- Public Member Functions inherited from BackedPanel
 BackedPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
 
 ~BackedPanel ()
 
wxDC & GetBackingDC ()
 
wxDC & GetBackingDCForRepaint ()
 
void ResizeBacking ()
 
void RepairBitmap (wxDC &dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 
void DisplayBitmap (wxDC &dc)
 
void OnSize (wxSizeEvent &event)
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Types

using OverlayPtr = std::weak_ptr< Overlay >
 

Private Member Functions

void Compress ()
 

Private Attributes

std::vector< OverlayPtrmOverlays
 

Friends

class GetInfoCommand
 

Detailed Description

Definition at line 18 of file OverlayPanel.h.

Member Typedef Documentation

◆ OverlayPtr

using OverlayPanel::OverlayPtr = std::weak_ptr<Overlay>
private

Definition at line 43 of file OverlayPanel.h.

Constructor & Destructor Documentation

◆ OverlayPanel()

OverlayPanel::OverlayPanel ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos,
const wxSize &  size,
long  style = wxTAB_TRAVERSAL | wxNO_BORDER 
)

Definition at line 17 of file OverlayPanel.cpp.

21: BackedPanel(parent, id, pos, size, style)
22{}
BackedPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
Definition: BackedPanel.cpp:12

Member Function Documentation

◆ AddOverlay()

void OverlayPanel::AddOverlay ( const std::weak_ptr< Overlay > &  pOverlay)

Definition at line 24 of file OverlayPanel.cpp.

25{
26 if (pOverlay.expired())
27 return;
28 Compress();
29 auto iter = std::lower_bound( mOverlays.begin(), mOverlays.end(),
30 pOverlay.lock()->SequenceNumber(),
31 []( const OverlayPtr &p, unsigned value ) {
32 return p.expired() || p.lock()->SequenceNumber() < value;
33 }
34 );
35 mOverlays.insert(iter, pOverlay);
36}
std::weak_ptr< Overlay > OverlayPtr
Definition: OverlayPanel.h:43
std::vector< OverlayPtr > mOverlays
Definition: OverlayPanel.h:46

References Compress(), and mOverlays.

Referenced by AdornedRulerPanel::CreateOverlays().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearOverlays()

void OverlayPanel::ClearOverlays ( )

Definition at line 38 of file OverlayPanel.cpp.

39{
40 mOverlays.clear();
41}

References mOverlays.

◆ Compress()

void OverlayPanel::Compress ( )
private

Definition at line 126 of file OverlayPanel.cpp.

127{
128 // remove any expired pointers
129 auto begin = mOverlays.begin();
130 auto end = mOverlays.end();
131 auto newEnd = std::remove_if( begin, end,
132 []( const std::weak_ptr<Overlay> &pOverlay ){
133 return pOverlay.expired(); } );
134 if ( end != newEnd )
135 mOverlays.resize( newEnd - begin );
136}
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::begin(), details::end(), and mOverlays.

Referenced by AddOverlay(), and DrawOverlays().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawOverlays()

void OverlayPanel::DrawOverlays ( bool  repaint_all,
wxDC *  pDC = nullptr 
)

Definition at line 43 of file OverlayPanel.cpp.

44{
45 if ( !IsShownOnScreen() )
46 return;
47
48 size_t n_pairs = mOverlays.size();
49
50 using Pair = std::pair<wxRect, bool /*out of date?*/>;
51 std::vector< Pair > pairs;
52 pairs.reserve(n_pairs);
53
54 // First...
55 Compress();
56 // ... then assume pointers are not expired
57
58 // Find out the rectangles and outdatedness for each overlay
59 wxSize size(GetBackingDC().GetSize());
60 for (const auto& pOverlay : mOverlays)
61 pairs.push_back( pOverlay.lock()->GetRectangle(size) );
62
63 // See what requires redrawing. If repainting, all.
64 // If not, then whatever is outdated, and whatever will be damaged by
65 // undrawing.
66 // By redrawing only what needs it, we avoid flashing things like
67 // the cursor that are drawn with invert, and also avoid
68 // unnecessary work.
69
70 // But first, a quick exit test.
71 bool some_overlays_need_repainting =
72 repaint_all ||
73 std::any_of( pairs.begin(), pairs.end(),
74 []( const Pair &pair ){ return pair.second; } );
75
76 if (!some_overlays_need_repainting) {
77 // This function (OverlayPanel::DrawOverlays()) is called at
78 // fairly high frequency through a timer in TrackPanel. In case
79 // there is nothing to do, we exit early because creating the
80 // wxClientDC below is expensive, at least on Linux.
81 return;
82 }
83
84 if (!repaint_all) {
85 // For each overlay that needs update, any other overlay whose
86 // rectangle intersects it will also need update.
87 bool done;
88 do {
89 done = true;
90 for (size_t ii = 0; ii < n_pairs - 1; ++ii) {
91 for (size_t jj = ii + 1; jj < n_pairs; ++jj) {
92 if (pairs[ii].second != pairs[jj].second &&
93 pairs[ii].first.Intersects(pairs[jj].first)) {
94 done = false;
95 pairs[ii].second = pairs[jj].second = true;
96 }
97 }
98 }
99 } while (!done);
100 }
101
102 std::optional<wxClientDC> myDC;
103 auto &dc = pDC ? *pDC : (myDC.emplace(this), *myDC);
104
105 // Erase
106 auto it2 = pairs.begin();
107 for (auto pOverlay : mOverlays) {
108 if (repaint_all || it2->second)
109 pOverlay.lock()->Erase(dc, GetBackingDC());
110 ++it2;
111 }
112
113 // Draw
114 it2 = pairs.begin();
115 for (auto pOverlay : mOverlays) {
116 if (repaint_all || it2->second) {
117 // Guarantee a clean state of the dc each pass:
118 ADCChanger changer{ &dc };
119
120 pOverlay.lock()->Draw(*this, dc);
121 }
122 ++it2;
123 }
124}
Makes temporary drawing context changes that you back out of, RAII style.
Definition: OverlayPanel.h:72
wxDC & GetBackingDC()
Definition: BackedPanel.cpp:30
std::pair< const char *, const char * > Pair

References Compress(), BackedPanel::GetBackingDC(), mOverlays, and size.

Referenced by AdornedRulerPanel::DrawBothOverlays(), TrackPanel::OnPaint(), AdornedRulerPanel::OnPaint(), TrackPanel::OnTimer(), and TrackPanel::ProcessUIHandleResult().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ GetInfoCommand

friend class GetInfoCommand
friend

Definition at line 50 of file OverlayPanel.h.

Member Data Documentation

◆ mOverlays

std::vector< OverlayPtr > OverlayPanel::mOverlays
private

Definition at line 46 of file OverlayPanel.h.

Referenced by AddOverlay(), ClearOverlays(), Compress(), and DrawOverlays().


The documentation for this class was generated from the following files: