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