1 // 2 // OverlayPanel.h 3 // Audacity 4 // 5 // Created by Paul Licameli on 5/1/16. 6 // 7 // 8 9 #ifndef __AUDACITY_OVERLAY_PANEL__ 10 #define __AUDACITY_OVERLAY_PANEL__ 11 12 #include <memory> 13 #include <vector> 14 #include "BackedPanel.h" // to inherit 15 16 class Overlay; 17 18 class AUDACITY_DLL_API OverlayPanel /* not final */ : public BackedPanel { 19 public: 20 OverlayPanel(wxWindow * parent, wxWindowID id, 21 const wxPoint & pos, 22 const wxSize & size, 23 // default as for wxPanel: 24 long style = wxTAB_TRAVERSAL | wxNO_BORDER); 25 26 // Registers overlay objects. 27 // The sequence in which they were registered is the sequence in 28 // which they are painted. 29 // OverlayPanel is not responsible for their memory management. 30 void AddOverlay( const std::weak_ptr<Overlay> &pOverlay ); 31 void ClearOverlays(); 32 33 // Erases and redraws to the client area the overlays that have 34 // been previously added with AddOverlay(). If "repaint_all" is 35 // true, all overlays will be erased and re-drawn. Otherwise, only 36 // the ones that are out-of-date, as well as the intersecting ones, 37 // will be erased and re-drawn. 38 // pDC can be null, in which case, DrawOverlays() will create a 39 // wxClientDC internally when necessary. 40 void DrawOverlays(bool repaint_all, wxDC *pDC = nullptr); 41 42 private: 43 using OverlayPtr = std::weak_ptr<Overlay>; 44 45 void Compress(); 46 std::vector< OverlayPtr > mOverlays; 47 48 49 DECLARE_EVENT_TABLE() 50 friend class GetInfoCommand; 51 }; 52 53 /// Used to restore pen, brush and logical-op in a DC back to what they were. 54 struct AUDACITY_DLL_API DCUnchanger { 55 public: DCUnchangerDCUnchanger56 DCUnchanger() {} 57 DCUnchangerDCUnchanger58 DCUnchanger(const wxBrush &brush_, const wxPen &pen_, long logicalOperation_) 59 : brush(brush_), pen(pen_), logicalOperation(logicalOperation_) 60 {} 61 62 void operator () (wxDC *pDC) const; 63 64 wxBrush brush {}; 65 wxPen pen {}; 66 long logicalOperation {}; 67 }; 68 69 /// Makes temporary drawing context changes that you back out of, RAII style 70 // It's like wxDCPenChanger, etc., but simple and general 71 class AUDACITY_DLL_API ADCChanger : public std::unique_ptr<wxDC, ::DCUnchanger> 72 { 73 using Base = std::unique_ptr<wxDC, ::DCUnchanger>; 74 public: ADCChanger()75 ADCChanger() : Base{} {} 76 ADCChanger(wxDC *pDC); 77 }; 78 79 #endif 80