Audacity 3.2.0
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
RulerUpdater Class Referenceabstract

Used to update a Ruler. More...

#include <RulerUpdater.h>

Inheritance diagram for RulerUpdater:
[legend]

Classes

class  Label
 An array of these created by the Updater is used to determine what and where text annotations to the numbers on the Ruler get drawn. More...
 
struct  TickOutputs
 
struct  TickSizes
 
struct  UpdateOutputs
 

Public Types

using Labels = std::vector< Label >
 
using Bits = std::vector< bool >
 

Public Member Functions

 RulerUpdater ()
 
virtual ~RulerUpdater ()=0
 
virtual void Update (wxDC &dc, const Envelope *envelope, UpdateOutputs &allOutputs, const RulerStruct &context) const =0
 

Protected Member Functions

void BoxAdjust (UpdateOutputs &allOutputs, const RulerStruct &context) const
 

Static Protected Member Functions

static std::pair< wxRect, LabelMakeTick (RulerUpdater::Label lab, wxDC &dc, wxFont font, std::vector< bool > &bits, int left, int top, int spacing, int lead, bool flip, int orientation)
 

Detailed Description

Used to update a Ruler.

This is a pure virtual class which sets how a ruler will generate its values.

Definition at line 58 of file RulerUpdater.h.

Member Typedef Documentation

◆ Bits

using RulerUpdater::Bits = std::vector< bool >

Definition at line 76 of file RulerUpdater.h.

◆ Labels

using RulerUpdater::Labels = std::vector<Label>

Definition at line 74 of file RulerUpdater.h.

Constructor & Destructor Documentation

◆ RulerUpdater()

RulerUpdater::RulerUpdater ( )
inline

Definition at line 84 of file RulerUpdater.h.

84{}

◆ ~RulerUpdater()

RulerUpdater::~RulerUpdater ( )
pure virtualdefault

Member Function Documentation

◆ BoxAdjust()

void RulerUpdater::BoxAdjust ( UpdateOutputs allOutputs,
const RulerStruct context 
) const
protected

Definition at line 213 of file RulerUpdater.cpp.

218{
219 const int mLeft = context.mLeft;
220 const int mTop = context.mTop;
221 const int mBottom = context.mBottom;
222 const int mRight = context.mRight;
223 const int mOrientation = context.mOrientation;
224 const bool mFlip = context.mFlip;
225
226 int displacementx = 0, displacementy = 0;
227 auto& box = allOutputs.box;
228 if (!mFlip) {
229 if (mOrientation == wxHORIZONTAL) {
230 int d = mTop + box.GetHeight() + 5;
231 box.Offset(0, d);
232 box.Inflate(0, 5);
233 displacementx = 0;
234 displacementy = d;
235 }
236 else {
237 int d = mLeft - box.GetLeft() + 5;
238 box.Offset(d, 0);
239 box.Inflate(5, 0);
240 displacementx = d;
241 displacementy = 0;
242 }
243 }
244 else {
245 if (mOrientation == wxHORIZONTAL) {
246 box.Inflate(0, 5);
247 displacementx = 0;
248 displacementy = 0;
249 }
250 }
251 auto update = [=](Label& label) {
252 label.lx += displacementx;
253 label.ly += displacementy;
254 };
255 for (auto& label : allOutputs.majorLabels)
256 update(label);
257 for (auto& label : allOutputs.minorLabels)
258 update(label);
259 for (auto& label : allOutputs.minorMinorLabels)
260 update(label);
261}
TranslatableString label
Definition: TagsEditor.cpp:164
int mOrientation
Definition: RulerUpdater.h:37

References RulerUpdater::UpdateOutputs::box, label, RulerUpdater::UpdateOutputs::majorLabels, RulerStruct::mBottom, RulerStruct::mFlip, RulerUpdater::UpdateOutputs::minorLabels, RulerUpdater::UpdateOutputs::minorMinorLabels, RulerStruct::mLeft, RulerStruct::mOrientation, RulerStruct::mRight, and RulerStruct::mTop.

Referenced by CustomUpdater::Update(), LinearUpdater::Update(), and LogarithmicUpdater::Update().

Here is the caller graph for this function:

◆ MakeTick()

auto RulerUpdater::MakeTick ( RulerUpdater::Label  lab,
wxDC &  dc,
wxFont  font,
std::vector< bool > &  bits,
int  left,
int  top,
int  spacing,
int  lead,
bool  flip,
int  orientation 
)
staticprotected

Definition at line 115 of file RulerUpdater.cpp.

122{
123 lab.lx = left - 1000; // don't display
124 lab.ly = top - 1000; // don't display
125
126 auto length = bits.size() - 1;
127 auto pos = lab.pos;
128
129 dc.SetFont(font);
130
131 wxCoord strW, strH, strD, strL;
132 auto strText = lab.text;
133 auto strUnits = lab.units;
134 auto str = (strText ? *strText : TranslatableString{}) + strUnits;
135 // Do not put the text into results until we are sure it does not overlap
136 lab.text = {};
137 lab.units = {};
138 dc.GetTextExtent(str.Translation(), &strW, &strH, &strD, &strL);
139
140 int strPos, strLen, strLeft, strTop;
141 if (orientation == wxHORIZONTAL) {
142 strLen = strW;
143 strPos = pos - strW / 2;
144 if (strPos < 0)
145 strPos = 0;
146 if (strPos + strW >= length)
147 strPos = length - strW;
148 strLeft = left + strPos;
149 if (flip)
150 strTop = top + 4;
151 else
152 strTop = -strH - lead;
153 // strTop = top - lead + 4;// More space was needed...
154 }
155 else {
156 strLen = strH;
157 strPos = pos - strH / 2;
158 if (strPos < 0)
159 strPos = 0;
160 if (strPos + strH >= length)
161 strPos = length - strH;
162 strTop = top + strPos;
163 if (flip)
164 strLeft = left + 5;
165 else
166 strLeft = -strW - 6;
167 }
168
169 // FIXME: we shouldn't even get here if strPos < 0.
170 // Ruler code currently does not handle very small or
171 // negative sized windows (i.e. don't draw) properly.
172 if (strPos < 0)
173 return { {}, lab };
174
175 // See if any of the pixels we need to draw this
176 // label is already covered
177
178 int i;
179 for (i = 0; i < strLen; i++)
180 if (bits[strPos + i])
181 return { {}, lab };
182
183 // If not, position the label
184
185 lab.lx = strLeft;
186 lab.ly = strTop;
187
188 // And mark these pixels, plus some surrounding
189 // ones (the spacing between labels), as covered
190 int leftMargin = spacing;
191 if (strPos < leftMargin)
192 leftMargin = strPos;
193 strPos -= leftMargin;
194 strLen += leftMargin;
195
196 int rightMargin = spacing;
197 if (strPos + strLen > length - spacing)
198 rightMargin = length - strPos - strLen;
199 strLen += rightMargin;
200
201 for (i = 0; i < strLen; i++)
202 bits[strPos + i] = true;
203
204 // Good to display the text
205 lab.text = strText;
206 lab.units = strUnits;
207 return { { strLeft, strTop, strW, strH }, lab };
208}
#define str(a)
Holds a msgid for the translation catalog; may also bind format arguments.
std::optional< TranslatableString > text
Definition: RulerUpdater.h:67
TranslatableString units
Definition: RulerUpdater.h:69

References str.

Referenced by GeneratedUpdater::Tick(), CustomUpdaterPosition::TickCustom(), and CustomUpdaterValue::TickCustom().

Here is the caller graph for this function:

◆ Update()

virtual void RulerUpdater::Update ( wxDC &  dc,
const Envelope envelope,
UpdateOutputs allOutputs,
const RulerStruct context 
) const
pure virtual

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