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

#include <OverlayPanel.h>

Inheritance diagram for OverlayPanel:
BackedPanel wxPanelWrapper wxTabTraversalWrapper< wxPanel > CellularPanel AdornedRulerPanel TrackPanel

Public Member Functions

 OverlayPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style=wxTAB_TRAVERSAL|wxNO_BORDER)
 
void AddOverlay (Overlay *pOverlay)
 
bool RemoveOverlay (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 wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- 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 Attributes

std::vector< Overlay * > mOverlays
 

Friends

class GetInfoCommand
 

Detailed Description

Definition at line 17 of file OverlayPanel.h.

Constructor & Destructor Documentation

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

Definition at line 16 of file OverlayPanel.cpp.

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

Member Function Documentation

void OverlayPanel::AddOverlay ( Overlay pOverlay)

Definition at line 23 of file OverlayPanel.cpp.

References mOverlays.

Referenced by AdornedRulerPanel::QuickPlayIndicatorOverlay::QuickPlayIndicatorOverlay(), and AdornedRulerPanel::QuickPlayRulerOverlay::QuickPlayRulerOverlay().

24 {
25  mOverlays.push_back(pOverlay);
26 }
std::vector< Overlay * > mOverlays
Definition: OverlayPanel.h:44
void OverlayPanel::ClearOverlays ( )

Definition at line 35 of file OverlayPanel.cpp.

References mOverlays.

36 {
37  mOverlays.clear();
38 }
std::vector< Overlay * > mOverlays
Definition: OverlayPanel.h:44
void OverlayPanel::DrawOverlays ( bool  repaint_all,
wxDC *  pDC = nullptr 
)

Definition at line 40 of file OverlayPanel.cpp.

References Maybe< X >::create(), BackedPanel::GetBackingDC(), and mOverlays.

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

41 {
42  size_t n_pairs = mOverlays.size();
43 
44  std::vector< std::pair<wxRect, bool /*out of date?*/> > pairs;
45  pairs.reserve(n_pairs);
46 
47  // Find out the rectangles and outdatedness for each overlay
48  wxSize size(GetBackingDC().GetSize());
49  for (const auto pOverlay : mOverlays)
50  pairs.push_back(pOverlay->GetRectangle(size));
51 
52  // See what requires redrawing. If repainting, all.
53  // If not, then whatever is outdated, and whatever will be damaged by
54  // undrawing.
55  // By redrawing only what needs it, we avoid flashing things like
56  // the cursor that are drawn with invert, and also avoid
57  // unnecessary work.
58  bool some_overlays_need_repainting = repaint_all;
59  if (!repaint_all) {
60  bool done;
61  do {
62  done = true;
63  for (size_t ii = 0; ii < n_pairs; ++ii) {
64  some_overlays_need_repainting |= pairs[ii].second;
65  for (size_t jj = ii + 1; jj < n_pairs; ++jj) {
66  if (pairs[ii].second != pairs[jj].second &&
67  pairs[ii].first.Intersects(pairs[jj].first)) {
68  done = false;
69  pairs[ii].second = pairs[jj].second = true;
70  }
71  }
72  }
73  } while (!done);
74  }
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  Maybe<wxClientDC> myDC;
85  auto &dc = pDC ? *pDC : (myDC.create(this), *myDC);
86 
87  // Erase
88  bool done = true;
89  auto it2 = pairs.begin();
90  for (auto pOverlay : mOverlays) {
91  if (repaint_all || it2->second) {
92  done = false;
93  pOverlay->Erase(dc, GetBackingDC());
94  }
95  ++it2;
96  }
97 
98  // Draw
99  if (!done) {
100  it2 = pairs.begin();
101  for (auto pOverlay : mOverlays) {
102  if (repaint_all || it2->second) {
103  // Guarantee a clean state of the dc each pass:
104  ADCChanger changer{ &dc };
105 
106  pOverlay->Draw(*this, dc);
107  }
108  ++it2;
109  }
110  }
111 }
std::vector< Overlay * > mOverlays
Definition: OverlayPanel.h:44
Like a smart pointer, allows for object to not exist (nullptr)
Definition: MemoryX.h:209
wxDC & GetBackingDC()
Definition: BackedPanel.cpp:30
void create(Args &&...args)
Definition: MemoryX.h:256
Makes temporary drawing context changes that you back out of, RAII style.
Definition: AColor.h:42
bool OverlayPanel::RemoveOverlay ( Overlay pOverlay)

Definition at line 28 of file OverlayPanel.cpp.

References mOverlays.

Referenced by AudacityProject::~AudacityProject(), EditCursorOverlay::~EditCursorOverlay(), PlayIndicatorOverlay::~PlayIndicatorOverlay(), and AdornedRulerPanel::QuickPlayIndicatorOverlay::~QuickPlayIndicatorOverlay().

29 {
30  const size_t oldSize = mOverlays.size();
31  mOverlays.erase(std::remove(mOverlays.begin(), mOverlays.end(), pOverlay), mOverlays.end());
32  return oldSize != mOverlays.size();
33 }
std::vector< Overlay * > mOverlays
Definition: OverlayPanel.h:44

Friends And Related Function Documentation

friend class GetInfoCommand
friend

Definition at line 48 of file OverlayPanel.h.

Member Data Documentation

std::vector<Overlay*> OverlayPanel::mOverlays
private

Definition at line 44 of file OverlayPanel.h.

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


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