mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-17 16:50:26 +02:00
Make Ruler::Tick and TickCustom const member functions...
... on the way to making them not (direct) member functions of Ruler. Hoist the choice of font and destination label array out of them, and group other outputs into an argument.
This commit is contained in:
parent
2c0afdd77a
commit
8cf7d0b8e9
@ -843,9 +843,10 @@ auto Ruler::MakeTick(
|
|||||||
return { { strLeft, strTop, strW, strH }, lab };
|
return { { strLeft, strTop, strW, strH }, lab };
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ruler::Tick(
|
bool Ruler::Tick( wxDC &dc,
|
||||||
wxDC &dc,
|
int pos, double d, const TickSizes &tickSizes, wxFont font,
|
||||||
int pos, double d, bool major, bool minor, const TickSizes &tickSizes )
|
// in/out:
|
||||||
|
TickOutputs outputs ) const
|
||||||
{
|
{
|
||||||
// Bug 521. dB view for waveforms needs a 2-sided scale.
|
// Bug 521. dB view for waveforms needs a 2-sided scale.
|
||||||
if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue ))
|
if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue ))
|
||||||
@ -853,11 +854,7 @@ bool Ruler::Tick(
|
|||||||
|
|
||||||
// FIXME: We don't draw a tick if off end of our label arrays
|
// FIXME: We don't draw a tick if off end of our label arrays
|
||||||
// But we shouldn't have an array of labels.
|
// But we shouldn't have an array of labels.
|
||||||
if( mMinorMinorLabels.size() >= mLength )
|
if( outputs.labels.size() >= mLength )
|
||||||
return false;
|
|
||||||
if( mMinorLabels.size() >= mLength )
|
|
||||||
return false;
|
|
||||||
if( mMajorLabels.size() >= mLength )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Label lab;
|
Label lab;
|
||||||
@ -867,37 +864,28 @@ bool Ruler::Tick(
|
|||||||
|
|
||||||
const auto result = MakeTick(
|
const auto result = MakeTick(
|
||||||
lab,
|
lab,
|
||||||
dc,
|
dc, font,
|
||||||
(major? mFonts.major: minor? mFonts.minor : mFonts.minorMinor),
|
outputs.bits,
|
||||||
mBits,
|
|
||||||
mLeft, mTop, mSpacing, mFonts.lead,
|
mLeft, mTop, mSpacing, mFonts.lead,
|
||||||
mFlip,
|
mFlip,
|
||||||
mOrientation );
|
mOrientation );
|
||||||
|
|
||||||
auto &rect = result.first;
|
auto &rect = result.first;
|
||||||
mRect.Union( rect );
|
outputs.box.Union( rect );
|
||||||
|
outputs.labels.emplace_back( result.second );
|
||||||
Labels *pLabels = major
|
|
||||||
? &mMajorLabels
|
|
||||||
: minor
|
|
||||||
? &mMinorLabels
|
|
||||||
: &mMinorMinorLabels;
|
|
||||||
pLabels->emplace_back( result.second );
|
|
||||||
return !rect.IsEmpty();
|
return !rect.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ruler::TickCustom( wxDC &dc, int labelIdx, bool major, bool minor )
|
bool Ruler::TickCustom( wxDC &dc, int labelIdx, wxFont font,
|
||||||
|
// in/out:
|
||||||
|
TickOutputs outputs ) const
|
||||||
{
|
{
|
||||||
// FIXME: We don't draw a tick if of end of our label arrays
|
// FIXME: We don't draw a tick if of end of our label arrays
|
||||||
// But we shouldn't have an array of labels.
|
// But we shouldn't have an array of labels.
|
||||||
if( mMinorLabels.size() >= mLength )
|
if( labelIdx >= outputs.labels.size() )
|
||||||
return false;
|
|
||||||
if( mMajorLabels.size() >= mLength )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//This should only used in the mCustom case
|
//This should only used in the mCustom case
|
||||||
// Many code comes from 'Tick' method: this should
|
|
||||||
// be optimized.
|
|
||||||
|
|
||||||
Label lab;
|
Label lab;
|
||||||
lab.value = 0.0;
|
lab.value = 0.0;
|
||||||
@ -905,22 +893,15 @@ bool Ruler::TickCustom( wxDC &dc, int labelIdx, bool major, bool minor )
|
|||||||
const auto result = MakeTick(
|
const auto result = MakeTick(
|
||||||
lab,
|
lab,
|
||||||
|
|
||||||
dc,
|
dc, font,
|
||||||
(major? mFonts.major: minor? mFonts.minor : mFonts.minorMinor),
|
outputs.bits,
|
||||||
mBits,
|
|
||||||
mLeft, mTop, mSpacing, mFonts.lead,
|
mLeft, mTop, mSpacing, mFonts.lead,
|
||||||
mFlip,
|
mFlip,
|
||||||
mOrientation );
|
mOrientation );
|
||||||
|
|
||||||
auto &rect = result.first;
|
auto &rect = result.first;
|
||||||
mRect.Union( rect );
|
outputs.box.Union( rect );
|
||||||
|
outputs.labels[labelIdx] = ( result.second );
|
||||||
Labels *pLabels = major
|
|
||||||
? &mMajorLabels
|
|
||||||
: minor
|
|
||||||
? &mMinorLabels
|
|
||||||
: &mMinorMinorLabels;
|
|
||||||
(*pLabels)[labelIdx] = ( result.second );
|
|
||||||
return !rect.IsEmpty();
|
return !rect.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1011,6 +992,8 @@ void Ruler::Update(
|
|||||||
mBits = mUserBits;
|
mBits = mUserBits;
|
||||||
mBits.resize( static_cast<size_t>(mLength + 1), false );
|
mBits.resize( static_cast<size_t>(mLength + 1), false );
|
||||||
|
|
||||||
|
TickOutputs majorOutputs{ mMajorLabels, mBits, mRect };
|
||||||
|
|
||||||
// *************** Label calculation routine **************
|
// *************** Label calculation routine **************
|
||||||
if( mCustom ) {
|
if( mCustom ) {
|
||||||
|
|
||||||
@ -1020,7 +1003,7 @@ void Ruler::Update(
|
|||||||
int numLabel = mMajorLabels.size();
|
int numLabel = mMajorLabels.size();
|
||||||
|
|
||||||
for( int i = 0; (i<numLabel) && (i<=mLength); ++i )
|
for( int i = 0; (i<numLabel) && (i<=mLength); ++i )
|
||||||
TickCustom( dc, i, true, false );
|
TickCustom( dc, i, mFonts.major, majorOutputs );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( !mLog ) {
|
else if( !mLog ) {
|
||||||
@ -1032,7 +1015,8 @@ void Ruler::Update(
|
|||||||
double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel
|
double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel
|
||||||
TickSizes tickSizes{ UPP, mOrientation, mFormat, false };
|
TickSizes tickSizes{ UPP, mOrientation, mFormat, false };
|
||||||
|
|
||||||
auto TickAtValue = [this, zoomInfo, &tickSizes, &dc]( double value ) -> int {
|
auto TickAtValue = [this, zoomInfo, &tickSizes, &dc, &majorOutputs]
|
||||||
|
( double value ) -> int {
|
||||||
// Make a tick only if the value is strictly between the bounds
|
// Make a tick only if the value is strictly between the bounds
|
||||||
if ( value <= std::min( mMin, mMax ) )
|
if ( value <= std::min( mMin, mMax ) )
|
||||||
return -1;
|
return -1;
|
||||||
@ -1051,7 +1035,7 @@ void Ruler::Update(
|
|||||||
|
|
||||||
const int iMaxPos = (mOrientation == wxHORIZONTAL) ? mRight : mBottom - 5;
|
const int iMaxPos = (mOrientation == wxHORIZONTAL) ? mRight : mBottom - 5;
|
||||||
if (mid >= 0 && mid < iMaxPos)
|
if (mid >= 0 && mid < iMaxPos)
|
||||||
Tick( dc, mid, value, true, false, tickSizes );
|
Tick( dc, mid, value, tickSizes, mFonts.major, majorOutputs );
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -1074,8 +1058,8 @@ void Ruler::Update(
|
|||||||
|
|
||||||
// Extreme values
|
// Extreme values
|
||||||
if (mLabelEdges) {
|
if (mLabelEdges) {
|
||||||
Tick( dc, 0, mMin, true, false, tickSizes );
|
Tick( dc, 0, mMax, tickSizes, mFonts.major, majorOutputs );
|
||||||
Tick( dc, mLength, mMax, true, false, tickSizes );
|
Tick( dc, mLength, mMax, tickSizes, mFonts.major, majorOutputs );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !mDbMirrorValue ) {
|
if ( !mDbMirrorValue ) {
|
||||||
@ -1089,6 +1073,11 @@ void Ruler::Update(
|
|||||||
// Major and minor ticks
|
// Major and minor ticks
|
||||||
for (int jj = 0; jj < 2; ++jj) {
|
for (int jj = 0; jj < 2; ++jj) {
|
||||||
const double denom = jj == 0 ? tickSizes.mMajor : tickSizes.mMinor;
|
const double denom = jj == 0 ? tickSizes.mMajor : tickSizes.mMinor;
|
||||||
|
auto font = jj == 0 ? mFonts.major : mFonts.minor;
|
||||||
|
TickOutputs outputs{
|
||||||
|
(jj == 0 ? mMajorLabels : mMinorLabels),
|
||||||
|
mBits, mRect
|
||||||
|
};
|
||||||
int ii = -1, j = 0;
|
int ii = -1, j = 0;
|
||||||
double d, warpedD, nextD;
|
double d, warpedD, nextD;
|
||||||
|
|
||||||
@ -1129,7 +1118,8 @@ void Ruler::Update(
|
|||||||
step = floor(sg * warpedD / denom);
|
step = floor(sg * warpedD / denom);
|
||||||
bool major = jj == 0;
|
bool major = jj == 0;
|
||||||
tickSizes.useMajor = major;
|
tickSizes.useMajor = major;
|
||||||
bool ticked = Tick( dc, ii, sg * step * denom, major, !major, tickSizes );
|
bool ticked = Tick( dc, ii, sg * step * denom, tickSizes,
|
||||||
|
font, outputs );
|
||||||
if( !major && !ticked ){
|
if( !major && !ticked ){
|
||||||
nDroppedMinorLabels++;
|
nDroppedMinorLabels++;
|
||||||
}
|
}
|
||||||
@ -1152,8 +1142,8 @@ void Ruler::Update(
|
|||||||
|
|
||||||
// Left and Right Edges
|
// Left and Right Edges
|
||||||
if (mLabelEdges) {
|
if (mLabelEdges) {
|
||||||
Tick( dc, 0, mMin, true, false, tickSizes );
|
Tick( dc, 0, mMin, tickSizes, mFonts.major, majorOutputs );
|
||||||
Tick( dc, mLength, mMax, true, false, tickSizes );
|
Tick( dc, mLength, mMax, tickSizes, mFonts.major, majorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1186,7 +1176,7 @@ void Ruler::Update(
|
|||||||
{ val = decade;
|
{ val = decade;
|
||||||
if(val >= rMin && val < rMax) {
|
if(val >= rMin && val < rMax) {
|
||||||
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
||||||
Tick( dc, pos, val, true, false, tickSizes );
|
Tick( dc, pos, val, tickSizes, mFonts.major, majorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decade *= step;
|
decade *= step;
|
||||||
@ -1202,12 +1192,13 @@ void Ruler::Update(
|
|||||||
}
|
}
|
||||||
steps++;
|
steps++;
|
||||||
tickSizes.useMajor = false;
|
tickSizes.useMajor = false;
|
||||||
|
TickOutputs minorOutputs{ mMinorLabels, mBits, mRect };
|
||||||
for(int i=0; i<=steps; i++) {
|
for(int i=0; i<=steps; i++) {
|
||||||
for(int j=start; j!=end; j+=mstep) {
|
for(int j=start; j!=end; j+=mstep) {
|
||||||
val = decade * j;
|
val = decade * j;
|
||||||
if(val >= rMin && val < rMax) {
|
if(val >= rMin && val < rMax) {
|
||||||
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
||||||
Tick( dc, pos, val, false, true, tickSizes );
|
Tick( dc, pos, val, tickSizes, mFonts.minor, minorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decade *= step;
|
decade *= step;
|
||||||
@ -1221,6 +1212,7 @@ void Ruler::Update(
|
|||||||
{ start=100; end= 10; mstep=-1;
|
{ start=100; end= 10; mstep=-1;
|
||||||
}
|
}
|
||||||
steps++;
|
steps++;
|
||||||
|
TickOutputs minorMinorOutputs{ mMinorMinorLabels, mBits, mRect };
|
||||||
for (int i = 0; i <= steps; i++) {
|
for (int i = 0; i <= steps; i++) {
|
||||||
// PRL: Bug1038. Don't label 1.6, rounded, as a duplicate tick for "2"
|
// PRL: Bug1038. Don't label 1.6, rounded, as a duplicate tick for "2"
|
||||||
if (!(mFormat == IntFormat && decade < 10.0)) {
|
if (!(mFormat == IntFormat && decade < 10.0)) {
|
||||||
@ -1229,7 +1221,8 @@ void Ruler::Update(
|
|||||||
val = decade * f / 10;
|
val = decade * f / 10;
|
||||||
if (val >= rMin && val < rMax) {
|
if (val >= rMin && val < rMax) {
|
||||||
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
||||||
Tick( dc, pos, val, false, false, tickSizes );
|
Tick( dc, pos, val, tickSizes,
|
||||||
|
mFonts.minorMinor, minorMinorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,14 +157,33 @@ class AUDACITY_DLL_API Ruler {
|
|||||||
private:
|
private:
|
||||||
struct TickSizes;
|
struct TickSizes;
|
||||||
|
|
||||||
|
class Label {
|
||||||
|
public:
|
||||||
|
double value;
|
||||||
|
int pos;
|
||||||
|
int lx, ly;
|
||||||
|
TranslatableString text;
|
||||||
|
|
||||||
|
void Draw(wxDC &dc, bool twoTone, wxColour c) const;
|
||||||
|
};
|
||||||
|
using Labels = std::vector<Label>;
|
||||||
|
|
||||||
|
using Bits = std::vector< bool >;
|
||||||
|
|
||||||
static void ChooseFonts( Fonts &fonts, wxDC &dc, int desiredPixelHeight );
|
static void ChooseFonts( Fonts &fonts, wxDC &dc, int desiredPixelHeight );
|
||||||
void Update( wxDC &dc, const Envelope* envelope );
|
void Update( wxDC &dc, const Envelope* envelope );
|
||||||
|
|
||||||
|
struct TickOutputs{ Labels &labels; Bits &bits; wxRect &box; };
|
||||||
|
|
||||||
bool Tick( wxDC &dc,
|
bool Tick( wxDC &dc,
|
||||||
int pos, double d, bool major, bool minor, const TickSizes &tickSizes );
|
int pos, double d, const TickSizes &tickSizes, wxFont font,
|
||||||
|
TickOutputs outputs
|
||||||
|
) const;
|
||||||
|
|
||||||
// Another tick generator for custom ruler case (noauto) .
|
// Another tick generator for custom ruler case (noauto) .
|
||||||
bool TickCustom( wxDC &dc, int labelIdx, bool major, bool minor );
|
bool TickCustom( wxDC &dc, int labelIdx, wxFont font,
|
||||||
|
TickOutputs outputs
|
||||||
|
) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool mbTicksOnly; // true => no line the length of the ruler
|
bool mbTicksOnly; // true => no line the length of the ruler
|
||||||
@ -184,22 +203,11 @@ private:
|
|||||||
double mMin, mMax;
|
double mMin, mMax;
|
||||||
double mHiddenMin, mHiddenMax;
|
double mHiddenMin, mHiddenMax;
|
||||||
|
|
||||||
using Bits = std::vector< bool >;
|
|
||||||
Bits mUserBits;
|
Bits mUserBits;
|
||||||
Bits mBits;
|
Bits mBits;
|
||||||
|
|
||||||
bool mValid;
|
bool mValid;
|
||||||
|
|
||||||
class Label {
|
|
||||||
public:
|
|
||||||
double value;
|
|
||||||
int pos;
|
|
||||||
int lx, ly;
|
|
||||||
TranslatableString text;
|
|
||||||
|
|
||||||
void Draw(wxDC &dc, bool twoTone, wxColour c) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::pair< wxRect, Label > MakeTick(
|
static std::pair< wxRect, Label > MakeTick(
|
||||||
Label lab,
|
Label lab,
|
||||||
wxDC &dc, wxFont font,
|
wxDC &dc, wxFont font,
|
||||||
@ -207,7 +215,6 @@ private:
|
|||||||
int left, int top, int spacing, int lead,
|
int left, int top, int spacing, int lead,
|
||||||
bool flip, int orientation );
|
bool flip, int orientation );
|
||||||
|
|
||||||
using Labels = std::vector<Label>;
|
|
||||||
Labels mMajorLabels;
|
Labels mMajorLabels;
|
||||||
Labels mMinorLabels;
|
Labels mMinorLabels;
|
||||||
Labels mMinorMinorLabels;
|
Labels mMinorMinorLabels;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user