mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
Move Tick and TickCustom methods to temporary worker structure...
... which forces us to be more explicit about just what parts of the Ruler state are used in it (when we construct it) and be sure they don't modify it
This commit is contained in:
parent
8cf7d0b8e9
commit
b0154f89e0
@ -843,7 +843,37 @@ auto Ruler::MakeTick(
|
|||||||
return { { strLeft, strTop, strW, strH }, lab };
|
return { { strLeft, strTop, strW, strH }, lab };
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ruler::Tick( wxDC &dc,
|
struct Ruler::TickOutputs{ Labels &labels; Bits &bits; wxRect &box; };
|
||||||
|
struct Ruler::Updater {
|
||||||
|
const Ruler &mRuler;
|
||||||
|
|
||||||
|
const double mDbMirrorValue = mRuler.mDbMirrorValue;
|
||||||
|
const int mLength = mRuler.mLength;
|
||||||
|
const RulerFormat mFormat = mRuler.mFormat;
|
||||||
|
const TranslatableString mUnits = mRuler.mUnits;
|
||||||
|
const int mLeft = mRuler.mLeft;
|
||||||
|
const int mTop = mRuler.mTop;
|
||||||
|
const int mSpacing = mRuler.mSpacing;
|
||||||
|
const int mOrientation = mRuler.mOrientation;
|
||||||
|
const int mLead = mRuler.mFonts.lead;
|
||||||
|
const bool mFlip = mRuler.mFlip;
|
||||||
|
|
||||||
|
explicit Updater( const Ruler &ruler )
|
||||||
|
: mRuler( ruler )
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool Tick( wxDC &dc,
|
||||||
|
int pos, double d, const TickSizes &tickSizes, wxFont font,
|
||||||
|
TickOutputs outputs
|
||||||
|
) const;
|
||||||
|
|
||||||
|
// Another tick generator for custom ruler case (noauto) .
|
||||||
|
bool TickCustom( wxDC &dc, int labelIdx, wxFont font,
|
||||||
|
TickOutputs outputs
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Ruler::Updater::Tick( wxDC &dc,
|
||||||
int pos, double d, const TickSizes &tickSizes, wxFont font,
|
int pos, double d, const TickSizes &tickSizes, wxFont font,
|
||||||
// in/out:
|
// in/out:
|
||||||
TickOutputs outputs ) const
|
TickOutputs outputs ) const
|
||||||
@ -866,7 +896,7 @@ bool Ruler::Tick( wxDC &dc,
|
|||||||
lab,
|
lab,
|
||||||
dc, font,
|
dc, font,
|
||||||
outputs.bits,
|
outputs.bits,
|
||||||
mLeft, mTop, mSpacing, mFonts.lead,
|
mLeft, mTop, mSpacing, mLead,
|
||||||
mFlip,
|
mFlip,
|
||||||
mOrientation );
|
mOrientation );
|
||||||
|
|
||||||
@ -876,7 +906,7 @@ bool Ruler::Tick( wxDC &dc,
|
|||||||
return !rect.IsEmpty();
|
return !rect.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ruler::TickCustom( wxDC &dc, int labelIdx, wxFont font,
|
bool Ruler::Updater::TickCustom( wxDC &dc, int labelIdx, wxFont font,
|
||||||
// in/out:
|
// in/out:
|
||||||
TickOutputs outputs ) const
|
TickOutputs outputs ) const
|
||||||
{
|
{
|
||||||
@ -895,7 +925,7 @@ bool Ruler::TickCustom( wxDC &dc, int labelIdx, wxFont font,
|
|||||||
|
|
||||||
dc, font,
|
dc, font,
|
||||||
outputs.bits,
|
outputs.bits,
|
||||||
mLeft, mTop, mSpacing, mFonts.lead,
|
mLeft, mTop, mSpacing, mLead,
|
||||||
mFlip,
|
mFlip,
|
||||||
mOrientation );
|
mOrientation );
|
||||||
|
|
||||||
@ -992,6 +1022,10 @@ 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 );
|
||||||
|
|
||||||
|
// Keep Updater const! We want no hidden state changes affecting its
|
||||||
|
// computations.
|
||||||
|
const Updater updater{ *this };
|
||||||
|
|
||||||
TickOutputs majorOutputs{ mMajorLabels, mBits, mRect };
|
TickOutputs majorOutputs{ mMajorLabels, mBits, mRect };
|
||||||
|
|
||||||
// *************** Label calculation routine **************
|
// *************** Label calculation routine **************
|
||||||
@ -1003,7 +1037,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, mFonts.major, majorOutputs );
|
updater.TickCustom( dc, i, mFonts.major, majorOutputs );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( !mLog ) {
|
else if( !mLog ) {
|
||||||
@ -1015,7 +1049,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, &majorOutputs]
|
auto TickAtValue =
|
||||||
|
[this, zoomInfo, &tickSizes, &dc, &updater, &majorOutputs]
|
||||||
( double value ) -> int {
|
( 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 ) )
|
||||||
@ -1035,7 +1070,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, tickSizes, mFonts.major, majorOutputs );
|
updater.Tick( dc, mid, value, tickSizes, mFonts.major, majorOutputs );
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -1058,8 +1093,8 @@ void Ruler::Update(
|
|||||||
|
|
||||||
// Extreme values
|
// Extreme values
|
||||||
if (mLabelEdges) {
|
if (mLabelEdges) {
|
||||||
Tick( dc, 0, mMax, tickSizes, mFonts.major, majorOutputs );
|
updater.Tick( dc, 0, mMax, tickSizes, mFonts.major, majorOutputs );
|
||||||
Tick( dc, mLength, mMax, tickSizes, mFonts.major, majorOutputs );
|
updater.Tick( dc, mLength, mMax, tickSizes, mFonts.major, majorOutputs );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !mDbMirrorValue ) {
|
if ( !mDbMirrorValue ) {
|
||||||
@ -1118,7 +1153,7 @@ 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, tickSizes,
|
bool ticked = updater.Tick( dc, ii, sg * step * denom, tickSizes,
|
||||||
font, outputs );
|
font, outputs );
|
||||||
if( !major && !ticked ){
|
if( !major && !ticked ){
|
||||||
nDroppedMinorLabels++;
|
nDroppedMinorLabels++;
|
||||||
@ -1142,8 +1177,8 @@ void Ruler::Update(
|
|||||||
|
|
||||||
// Left and Right Edges
|
// Left and Right Edges
|
||||||
if (mLabelEdges) {
|
if (mLabelEdges) {
|
||||||
Tick( dc, 0, mMin, tickSizes, mFonts.major, majorOutputs );
|
updater.Tick( dc, 0, mMin, tickSizes, mFonts.major, majorOutputs );
|
||||||
Tick( dc, mLength, mMax, tickSizes, mFonts.major, majorOutputs );
|
updater.Tick( dc, mLength, mMax, tickSizes, mFonts.major, majorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1176,7 +1211,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, tickSizes, mFonts.major, majorOutputs );
|
updater.Tick( dc, pos, val, tickSizes, mFonts.major, majorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decade *= step;
|
decade *= step;
|
||||||
@ -1198,7 +1233,7 @@ void Ruler::Update(
|
|||||||
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, tickSizes, mFonts.minor, minorOutputs );
|
updater.Tick( dc, pos, val, tickSizes, mFonts.minor, minorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decade *= step;
|
decade *= step;
|
||||||
@ -1221,7 +1256,7 @@ 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, tickSizes,
|
updater.Tick( dc, pos, val, tickSizes,
|
||||||
mFonts.minorMinor, minorMinorOutputs );
|
mFonts.minorMinor, minorMinorOutputs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,18 +173,9 @@ class AUDACITY_DLL_API Ruler {
|
|||||||
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; };
|
struct TickOutputs;
|
||||||
|
struct Updater;
|
||||||
|
|
||||||
bool Tick( wxDC &dc,
|
|
||||||
int pos, double d, const TickSizes &tickSizes, wxFont font,
|
|
||||||
TickOutputs outputs
|
|
||||||
) const;
|
|
||||||
|
|
||||||
// Another tick generator for custom ruler case (noauto) .
|
|
||||||
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
|
||||||
bool mbTicksAtExtremes;
|
bool mbTicksAtExtremes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user