Audacity 3.2.0
Ruler.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Ruler.h
6
7 Dominic Mazzoni
8
9**********************************************************************/
10
11#ifndef __AUDACITY_RULER__
12#define __AUDACITY_RULER__
13
14#include "RulerUpdater.h" // member variable
15#include "NumberScale.h" // member variable
16
17#include "Observer.h"
18
19#include <wx/colour.h> // member variable
20#include <wx/font.h> // member variable
21#include <wx/pen.h> // member variable
22
23class wxDC;
24
25class Envelope;
26class RulerFormat;
27
28#include "TranslatableString.h"
29
31
32class AUDACITY_DLL_API Ruler :
33 public Observer::Publisher<RulerInvalidatedMessage>
34{
35 public:
36
37 struct TickLengths {
38 int majorLength, minorLength, minorMinorLength;
39 };
40
41 //
42 // Constructor / Destructor
43 //
44
46 ~Ruler();
47
48 //
49 // Required Ruler Parameters
50 //
51
52 void SetBounds(int left, int top, int right, int bottom);
53
54 // wxHORIZONTAL || wxVERTICAL
55 void SetOrientation(int orient);
56
57 // min is the value at (x, y)
58 // max is the value at (x+width, y+height)
59 // (at the center of the pixel, in both cases)
60 void SetRange(double min, double max);
61
62 // An overload needed for the special case of fisheye
63 // min is the value at (x, y)
64 // max is the value at (x+width, y+height)
65 // hiddenMin, hiddenMax are the values that would be shown without the fisheye.
66 // (at the center of the pixel, in both cases)
67 void SetRange(double min, double max, double hiddenMin, double hiddenMax);
68
69 // Set the kind of updater the ruler will use (Linear, Logarithmic, Custom, etc.)
70 // Invalidates the ruler. However ruler doesn't invalidate automatically
71 // if the updater's state is mutated elsewhere.
72 void SetUpdater(const RulerUpdater *pUpdater);
73
74 //
75 // Optional Ruler Parameters
76 //
77
78 // If twoTone is true, cause zero and positive numbers to appear black, negative in another color.
79 void SetTwoTone(bool twoTone);
80
81 // Set the format to be used for generating tick labels and tick spacing for some updaters
82 // Invalidates the ruler. However ruler doesn't invalidate automatically
83 // if the formatter's state is mutated elsewhere.
84 void SetFormat(const RulerFormat *pFormat);
85
86 // Specify the name of the units (like "dB") if you
87 // want numbers like "1.6" formatted as "1.6 dB".
88 void SetUnits(const TranslatableString &units);
89 void SetDbMirrorValue( const double d );
90
91 // If this is true, the edges of the ruler will always
92 // receive a label. If not, the nearest round number is
93 // labeled (which may or may not be the edge).
94 void SetLabelEdges(bool labelEdges);
95
96 // Makes a vertical ruler hug the left side (instead of right)
97 // and a horizontal ruler hug the top (instead of bottom)
98 void SetFlip(bool flip);
99
100 // Set it to false if you don't want minor labels.
101 void SetMinor(bool value);
102
103 // Good defaults are provided, but you can override here
104 void SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont);
105 RulerStruct::Fonts GetFonts() const;
106
107 void SetNumberScale(const NumberScale &scale);
108
109 void SetTickLengths(const TickLengths& tLengths);
110
111 // The ruler will not draw text within this (pixel) range.
112 // Use this if you have another graphic object obscuring part
113 // of the ruler's area. The values start and end are interpreted
114 // relative to the Ruler's local coordinates.
115 void OfflimitsPixels(int start, int end);
116
117 //
118 // Calculates and returns the maximum size required by the ruler
119 //
120 void GetMaxSize(wxCoord *width, wxCoord *height);
121
122 //
123 // Drawing
124 //
125
126 // Note that it will not erase for you...
127 void Draw(wxDC& dc) const;
128 void Draw(wxDC& dc, const Envelope* envelope) const;
129 // If length <> 0, draws lines perpendiculars to ruler corresponding
130 // to selected ticks (major, minor, or both), in an adjacent window.
131 // You may need to use the offsets if you are using part of the dc for rulers, borders etc.
132 void DrawGrid(wxDC& dc, int length, bool minor = true, bool major = true, int xOffset = 0, int yOffset = 0) const;
133
134 // So we can have white ticks on black...
135 void SetTickColour( const wxColour & colour)
136 { mTickColour = colour; mPen.SetColour( colour );}
137
138 // Force regeneration of labels at next draw time
139 void Invalidate();
140
141 private:
142
143 void ChooseFonts( wxDC &dc ) const;
144
145 void UpdateCache( wxDC &dc, const Envelope* envelope ) const;
146
147public:
148 bool mbTicksOnly; // true => no line the length of the ruler
150
151private:
152
155
156 wxColour mTickColour;
157
158 wxPen mPen;
159
160 std::unique_ptr<RulerStruct::Fonts> mpUserFonts;
161
162 const RulerUpdater *mpUpdater{};
163
165
166 struct Cache;
167 mutable std::unique_ptr<Cache> mpCache;
168
169 // Returns 'zero' label coordinate (for grid drawing)
170 int FindZero( const RulerUpdater::Labels &labels ) const;
171
172 int GetZeroPosition() const;
173
176};
177
178#endif //define __AUDACITY_RULER__
int min(int a, int b)
static CustomUpdaterValue updater
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Used to display a Ruler.
Definition: Ruler.h:34
wxColour mTickColour
Definition: Ruler.h:156
RulerStruct mRulerStruct
Definition: Ruler.h:153
void SetTickColour(const wxColour &colour)
Definition: Ruler.h:135
wxPen mPen
Definition: Ruler.h:158
std::unique_ptr< Cache > mpCache
Definition: Ruler.h:166
RulerUpdater::Bits mUserBits
Definition: Ruler.h:164
TickLengths mTickLengths
Definition: Ruler.h:154
bool mbTicksOnly
Definition: Ruler.h:148
std::unique_ptr< RulerStruct::Fonts > mpUserFonts
Definition: Ruler.h:160
bool mbTicksAtExtremes
Definition: Ruler.h:149
bool mbMinor
Definition: Ruler.h:174
bool mTwoTone
Definition: Ruler.h:175
Used to update a Ruler.
Definition: RulerUpdater.h:58
std::vector< bool > Bits
Definition: RulerUpdater.h:76
std::vector< Label > Labels
Definition: RulerUpdater.h:74
Holds a msgid for the translation catalog; may also bind format arguments.
std::optional< LogWindowUpdater > pUpdater
Definition: LogWindow.cpp:53
const char * end(const char *str) noexcept
Definition: StringUtils.h:106