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 209 of file RulerUpdater.cpp.

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

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