Audacity 3.2.0
CustomUpdaterPosition.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 CustomUpdaterPosition.cpp
6
7 Dominic Mazzoni
8 Michael Papadopoulos split from Ruler.cpp
9
10**********************************************************************/
11
12
14
16{
17 static CustomUpdaterPosition instance;
18 return instance;
19}
20
21bool CustomUpdaterPosition::TickCustom(wxDC& dc, int labelIdx, wxFont font,
22 // in/out:
23 TickOutputs outputs,
24 const RulerStruct& context) const
25{
26 const int mLeft = context.mLeft;
27 const int mTop = context.mTop;
28 const int mOrientation = context.mOrientation;
29
30 const RulerStruct::Fonts& mFonts = *context.mpFonts;
31 // legacy behavior
32 const int spacing = (mOrientation == wxHORIZONTAL) ? 6 : 2;
33 const bool mFlip = context.mFlip;
34 const TranslatableString mUnits = context.mUnits;
35
36 // FIXME: We don't draw a tick if of end of our label arrays
37 // But we shouldn't have an array of labels.
38 if (labelIdx >= outputs.labels.size())
39 return false;
40
41 Label lab;
42
43 lab.value = 0.0;
44 lab.pos = outputs.labels[labelIdx].pos;
45 // Custom is flexible with text format
46 // We can assume they use the right format, but still append the right units.
47 lab.text = outputs.labels[labelIdx].text;
48 lab.units = mUnits;
49
50 auto result = MakeTick(
51 lab,
52 dc, font,
53 outputs.bits,
54 mLeft, mTop, spacing, mFonts.lead,
55 mFlip,
56 mOrientation);
57
58 if (!result.second.text)
59 // Always a non-empty optional
60 result.second.text = { TranslatableString{} };
61
62 auto& rect = result.first;
63 outputs.box.Union(rect);
64 outputs.labels[labelIdx] = (result.second);
65 return !rect.IsEmpty();
66}
67
bool TickCustom(wxDC &dc, int labelIdx, wxFont font, TickOutputs outputs, const RulerStruct &context) const override
~CustomUpdaterPosition() override
static const CustomUpdaterPosition & Instance()
static std::pair< wxRect, Label > MakeTick(RulerUpdater::Label lab, wxDC &dc, wxFont font, std::vector< bool > &bits, int left, int top, int spacing, int lead, bool flip, int orientation)
Holds a msgid for the translation catalog; may also bind format arguments.
std::unique_ptr< Fonts > mpFonts
Definition: RulerUpdater.h:52
TranslatableString mUnits
Definition: RulerUpdater.h:53
int mOrientation
Definition: RulerUpdater.h:37
An array of these created by the Updater is used to determine what and where text annotations to the ...
Definition: RulerUpdater.h:60
std::optional< TranslatableString > text
Definition: RulerUpdater.h:67
TranslatableString units
Definition: RulerUpdater.h:69