Audacity 3.2.0
RulerPanel.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 RulerPanel.cpp
6
7 Dominic Mazzoni
8
9 Michael Papadopoulos split from Ruler.cpp
10
11*******************************************************************//******************************************************************/
18
19#include "RulerPanel.h"
20
21#include "LinearUpdater.h"
22#include "LogarithmicUpdater.h"
23
24#include <wx/dcclient.h>
25
26
27BEGIN_EVENT_TABLE(RulerPanel, wxPanelWrapper)
28 EVT_ERASE_BACKGROUND(RulerPanel::OnErase)
29 EVT_PAINT(RulerPanel::OnPaint)
30 EVT_SIZE(RulerPanel::OnSize)
32
34
35RulerPanel::RulerPanel(wxWindow* parent, wxWindowID id,
36 wxOrientation orientation,
37 const wxSize& bounds,
38 const Range& range,
39 const RulerFormat &format,
40 const TranslatableString& units,
41 const Options& options,
42 const wxPoint& pos /*= wxDefaultPosition*/,
43 const wxSize& size /*= wxDefaultSize*/
44)
45 : wxPanelWrapper(parent, id, pos, size)
46 , ruler{
47 [&]() -> const RulerUpdater& {
48 if (options.log)
50 else
52 }(),
53 format
54 }
55{
56 ruler.SetBounds( 0, 0, bounds.x, bounds.y );
57 ruler.SetOrientation(orientation);
58 ruler.SetRange( range.first, range.second );
59 ruler.SetUnits(units);
60 ruler.SetFlip(options.flip);
61 ruler.SetLabelEdges(options.labelEdges);
62 ruler.mbTicksAtExtremes = options.ticksAtExtremes;
63 if (orientation == wxVERTICAL) {
64 wxCoord w;
65 ruler.GetMaxSize(&w, NULL);
66 SetMinSize(wxSize(w, 150)); // height needed for wxGTK
67 }
68 else if (orientation == wxHORIZONTAL) {
69 wxCoord h;
70 ruler.GetMaxSize(NULL, &h);
71 SetMinSize(wxSize(wxDefaultCoord, h));
72 }
73 if (options.hasTickColour)
74 ruler.SetTickColour( options.tickColour );
75}
76
78{
79}
80
81void RulerPanel::OnErase(wxEraseEvent & WXUNUSED(evt))
82{
83 // Ignore it to prevent flashing
84}
85
86void RulerPanel::OnPaint(wxPaintEvent & WXUNUSED(evt))
87{
88 wxPaintDC dc(this);
89
90#if defined(__WXMSW__)
91 dc.Clear();
92#endif
93
94 ruler.Draw(dc);
95}
96
97void RulerPanel::OnSize(wxSizeEvent & WXUNUSED(evt))
98{
99 Refresh();
100}
101
102// LL: We're overloading DoSetSize so that we can update the ruler bounds immediately
103// instead of waiting for a wxEVT_SIZE to come through. This is needed by (at least)
104// FrequencyPlotDialog since it needs to have an updated ruler before RulerPanel gets the
105// size event.
106void RulerPanel::DoSetSize(int x, int y,
107 int width, int height,
108 int sizeFlags)
109{
110 wxPanelWrapper::DoSetSize(x, y, width, height, sizeFlags);
111
112 int w, h;
113 GetClientSize(&w, &h);
114
115 ruler.SetBounds(0, 0, w-1, h-1);
116}
END_EVENT_TABLE()
IMPLEMENT_CLASS(cloud::ShareAudioToolbar, ToolBar)
static const LinearUpdater & Instance()
static const LogarithmicUpdater & Instance()
void SetTickColour(const wxColour &colour)
Definition: Ruler.h:135
void SetFlip(bool flip)
Definition: Ruler.cpp:192
void SetOrientation(int orient)
Definition: Ruler.cpp:141
void Draw(wxDC &dc) const
Definition: Ruler.cpp:441
void SetLabelEdges(bool labelEdges)
Definition: Ruler.cpp:179
bool mbTicksAtExtremes
Definition: Ruler.h:149
void GetMaxSize(wxCoord *width, wxCoord *height)
Definition: Ruler.cpp:616
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:304
void SetUnits(const TranslatableString &units)
Definition: Ruler.cpp:120
void SetRange(double min, double max)
Definition: Ruler.cpp:152
RulerPanel class allows you to work with a Ruler like any other wxWindow.
Definition: RulerPanel.h:19
Ruler ruler
Definition: RulerPanel.h:79
void DoSetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO) override
Definition: RulerPanel.cpp:106
void OnSize(wxSizeEvent &evt)
Definition: RulerPanel.cpp:97
std::pair< double, double > Range
Definition: RulerPanel.h:23
void OnPaint(wxPaintEvent &evt)
Definition: RulerPanel.cpp:86
void OnErase(wxEraseEvent &evt)
Definition: RulerPanel.cpp:81
Used to update a Ruler.
Definition: RulerUpdater.h:58
Holds a msgid for the translation catalog; may also bind format arguments.