Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
CustomUpdaterValue Class Referencefinal

#include <CustomUpdaterValue.h>

Inheritance diagram for CustomUpdaterValue:
[legend]
Collaboration diagram for CustomUpdaterValue:
[legend]

Public Member Functions

 CustomUpdaterValue ()=default
 
 ~CustomUpdaterValue () override
 
- Public Member Functions inherited from CustomUpdater
 ~CustomUpdater () override
 
void Update (wxDC &dc, const Envelope *envelope, UpdateOutputs &allOutputs, const RulerStruct &context) const final
 
void SetData (RulerUpdater::Labels majorLabels, RulerUpdater::Labels minorLabels, RulerUpdater::Labels minorMinorLabels)
 
 RulerUpdater ()
 
- Public Member Functions inherited from RulerUpdater
 RulerUpdater ()
 
virtual ~RulerUpdater ()=0
 
virtual void Update (wxDC &dc, const Envelope *envelope, UpdateOutputs &allOutputs, const RulerStruct &context) const =0
 

Static Public Member Functions

static const CustomUpdaterValueInstance ()
 

Protected Member Functions

bool TickCustom (wxDC &dc, int labelIdx, wxFont font, TickOutputs outputs, const RulerStruct &context) const override
 
virtual bool TickCustom (wxDC &dc, int labelIdx, wxFont font, TickOutputs outputs, const RulerStruct &context) const =0
 
- Protected Member Functions inherited from RulerUpdater
void BoxAdjust (UpdateOutputs &allOutputs, const RulerStruct &context) const
 

Additional Inherited Members

- Public Types inherited from RulerUpdater
using Labels = std::vector< Label >
 
using Bits = std::vector< bool >
 
- Static Protected Member Functions inherited from RulerUpdater
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)
 
- Protected Attributes inherited from CustomUpdater
RulerUpdater::Labels mMajorLabels
 
RulerUpdater::Labels mMinorLabels
 
RulerUpdater::Labels mMinorMinorLabels
 

Detailed Description

Definition at line 17 of file CustomUpdaterValue.h.

Constructor & Destructor Documentation

◆ CustomUpdaterValue()

CustomUpdaterValue::CustomUpdaterValue ( )
default

◆ ~CustomUpdaterValue()

CustomUpdaterValue::~CustomUpdaterValue ( )
overridedefault

Member Function Documentation

◆ Instance()

const CustomUpdaterValue & CustomUpdaterValue::Instance ( )
static

Definition at line 15 of file CustomUpdaterValue.cpp.

16{
17 static CustomUpdaterValue instance;
18 return instance;
19}

◆ TickCustom()

bool CustomUpdaterValue::TickCustom ( wxDC &  dc,
int  labelIdx,
wxFont  font,
TickOutputs  outputs,
const RulerStruct context 
) const
overrideprotectedvirtual

Implements CustomUpdater.

Definition at line 21 of file CustomUpdaterValue.cpp.

25{
26 const double mMin = context.mMin;
27 const double mMax = context.mMax;
28
29 const int mLeft = context.mLeft;
30 const int mTop = context.mTop;
31 const int mRight = context.mRight;
32 const int mBottom = context.mBottom;
33 const int mLength = context.mLength;
34 const int mOrientation = context.mOrientation;
35
36 const RulerStruct::Fonts& mFonts = *context.mpFonts;
37 constexpr int spacing = 2;
38 const bool mFlip = context.mFlip;
39 const TranslatableString mUnits = context.mUnits;
40 const bool mLabelEdges = context.mLabelEdges;
41
42 auto TickAtValue =
43 [this, &dc, &mFonts, mOrientation, mLabelEdges,
44 mMin, mMax, mLength, mRight, mBottom, &context]
45 (double value, double *pos) -> bool {
46 // Make a tick only if the value is strictly between the bounds
47 double min = std::min(mMin, mMax);
48 double max = std::max(mMin, mMax);
49 if ((value <= min && !mLabelEdges) || value < min)
50 return false;
51 if ((value >= max && !mLabelEdges) || value > max)
52 return false;
53
54 int mid = (int)(mLength * ((mMin - value) / (mMin - mMax)) + 0.5);
55
56 const int iMaxPos = (mOrientation == wxHORIZONTAL) ? mRight : mBottom - 5;
57 if (mid >= 0 && mid < iMaxPos) {
58 *pos = mid;
59 return true;
60 }
61 return false;
62 };
63
64 // FIXME: We don't draw a tick if of end of our label arrays
65 // But we shouldn't have an array of labels.
66 if (labelIdx >= outputs.labels.size())
67 return false;
68
69 // Get the correct position based on value.
70 // Don't draw if the value is out of bounds.
71 double pos;
72 if (!TickAtValue(outputs.labels[labelIdx].value, &pos))
73 return false;
74
75 Label lab;
76 lab.value = 0.0;
77 lab.pos = pos;
78 // Custom is flexible with text format
79 // We can assume they use the right format, but still append the right units.
80 lab.text = outputs.labels[labelIdx].text;
81 lab.units = mUnits;
82
83 auto result = MakeTick(
84 lab,
85 dc, font,
86 outputs.bits,
87 mLeft, mTop, spacing, mFonts.lead,
88 mFlip,
89 mOrientation);
90
91 if (!result.second.text)
92 // Always a non-empty optional
93 result.second.text = { TranslatableString{} };
94
95 auto& rect = result.first;
96 outputs.box.Union(rect);
97 outputs.labels[labelIdx] = (result.second);
98 return !rect.IsEmpty();
99}
int min(int a, int b)
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
double mMax
Definition: RulerUpdater.h:34
TranslatableString mUnits
Definition: RulerUpdater.h:53
int mOrientation
Definition: RulerUpdater.h:37
bool mLabelEdges
Definition: RulerUpdater.h:39
double mMin
Definition: RulerUpdater.h:32

References RulerUpdater::TickOutputs::bits, RulerUpdater::TickOutputs::box, RulerUpdater::TickOutputs::labels, RulerStruct::Fonts::lead, RulerUpdater::MakeTick(), RulerStruct::mBottom, RulerStruct::mFlip, min(), RulerStruct::mLabelEdges, RulerStruct::mLeft, RulerStruct::mLength, RulerStruct::mMax, RulerStruct::mMin, RulerStruct::mOrientation, RulerStruct::mpFonts, RulerStruct::mRight, RulerStruct::mTop, RulerStruct::mUnits, RulerUpdater::Label::pos, RulerUpdater::Label::text, RulerUpdater::Label::units, and RulerUpdater::Label::value.

Here is the call graph for this function:

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