1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-11 14:17:43 +02:00

Nix Ruler member vars used only for grid drawing; more const methods

This commit is contained in:
Paul Licameli 2020-01-22 15:47:12 -05:00
parent ef44143cbf
commit fe4db0dd8e
2 changed files with 21 additions and 30 deletions

View File

@ -119,10 +119,6 @@ Ruler::Ruler()
mCustom = false; mCustom = false;
mbMinor = true; mbMinor = true;
mGridLineLength = 0;
mMajorGrid = false;
mMinorGrid = false;
mTwoTone = false; mTwoTone = false;
mUseZoomInfo = NULL; mUseZoomInfo = NULL;
@ -1412,46 +1408,44 @@ void Ruler::Draw(wxDC& dc, const Envelope* envelope)
} }
// ********** Draw grid *************************** // ********** Draw grid ***************************
void Ruler::DrawGrid(wxDC& dc, int length, bool minor, bool major, int xOffset, int yOffset) void Ruler::DrawGrid(wxDC& dc,
const int gridLineLength,
const bool minorGrid, const bool majorGrid, int xOffset, int yOffset)
{ {
mGridLineLength = length;
mMajorGrid = major;
mMinorGrid = minor;
if ( !mValid ) if ( !mValid )
Update( dc, nullptr ); Update( dc, nullptr );
int gridPos; int gridPos;
wxPen gridPen; wxPen gridPen;
if(mbMinor && (mMinorGrid && (mGridLineLength != 0 ))) { if(mbMinor && (minorGrid && (gridLineLength != 0 ))) {
gridPen.SetColour(178, 178, 178); // very light grey gridPen.SetColour(178, 178, 178); // very light grey
dc.SetPen(gridPen); dc.SetPen(gridPen);
for( const auto &label : mMinorLabels ) { for( const auto &label : mMinorLabels ) {
gridPos = label.pos; gridPos = label.pos;
if(mOrientation == wxHORIZONTAL) { if(mOrientation == wxHORIZONTAL) {
if((gridPos != 0) && (gridPos != mGridLineLength)) if((gridPos != 0) && (gridPos != gridLineLength))
AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, mGridLineLength-1+yOffset); AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, gridLineLength-1+yOffset);
} }
else { else {
if((gridPos != 0) && (gridPos != mGridLineLength)) if((gridPos != 0) && (gridPos != gridLineLength))
AColor::Line(dc, xOffset, gridPos+yOffset, mGridLineLength-1+xOffset, gridPos+yOffset); AColor::Line(dc, xOffset, gridPos+yOffset, gridLineLength-1+xOffset, gridPos+yOffset);
} }
} }
} }
if(mMajorGrid && (mGridLineLength != 0 )) { if(majorGrid && (gridLineLength != 0 )) {
gridPen.SetColour(127, 127, 127); // light grey gridPen.SetColour(127, 127, 127); // light grey
dc.SetPen(gridPen); dc.SetPen(gridPen);
for( const auto &label : mMajorLabels ) { for( const auto &label : mMajorLabels ) {
gridPos = label.pos; gridPos = label.pos;
if(mOrientation == wxHORIZONTAL) { if(mOrientation == wxHORIZONTAL) {
if((gridPos != 0) && (gridPos != mGridLineLength)) if((gridPos != 0) && (gridPos != gridLineLength))
AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, mGridLineLength-1+yOffset); AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, gridLineLength-1+yOffset);
} }
else { else {
if((gridPos != 0) && (gridPos != mGridLineLength)) if((gridPos != 0) && (gridPos != gridLineLength))
AColor::Line(dc, xOffset, gridPos+yOffset, mGridLineLength-1+xOffset, gridPos+yOffset); AColor::Line(dc, xOffset, gridPos+yOffset, gridLineLength-1+xOffset, gridPos+yOffset);
} }
} }
@ -1460,18 +1454,18 @@ void Ruler::DrawGrid(wxDC& dc, int length, bool minor, bool major, int xOffset,
// Draw 'zero' grid line in black // Draw 'zero' grid line in black
dc.SetPen(*wxBLACK_PEN); dc.SetPen(*wxBLACK_PEN);
if(mOrientation == wxHORIZONTAL) { if(mOrientation == wxHORIZONTAL) {
if(zeroPosition != mGridLineLength) if(zeroPosition != gridLineLength)
AColor::Line(dc, zeroPosition+xOffset, yOffset, zeroPosition+xOffset, mGridLineLength-1+yOffset); AColor::Line(dc, zeroPosition+xOffset, yOffset, zeroPosition+xOffset, gridLineLength-1+yOffset);
} }
else { else {
if(zeroPosition != mGridLineLength) if(zeroPosition != gridLineLength)
AColor::Line(dc, xOffset, zeroPosition+yOffset, mGridLineLength-1+xOffset, zeroPosition+yOffset); AColor::Line(dc, xOffset, zeroPosition+yOffset, gridLineLength-1+xOffset, zeroPosition+yOffset);
} }
} }
} }
} }
int Ruler::FindZero( const Labels &labels ) int Ruler::FindZero( const Labels &labels ) const
{ {
auto begin = labels.begin(), end = labels.end(), auto begin = labels.begin(), end = labels.end(),
iter = std::find_if( begin, end, []( const Label &label ){ iter = std::find_if( begin, end, []( const Label &label ){
@ -1484,7 +1478,7 @@ int Ruler::FindZero( const Labels &labels )
return iter->pos; return iter->pos;
} }
int Ruler::GetZeroPosition() int Ruler::GetZeroPosition() const
{ {
int zero; int zero;
if( (zero = FindZero( mMajorLabels ) ) < 0) if( (zero = FindZero( mMajorLabels ) ) < 0)

View File

@ -211,10 +211,10 @@ private:
Labels mMinorMinorLabels; Labels mMinorMinorLabels;
// Returns 'zero' label coordinate (for grid drawing) // Returns 'zero' label coordinate (for grid drawing)
int FindZero( const Labels &labels ); int FindZero( const Labels &labels ) const;
public: public:
int GetZeroPosition(); int GetZeroPosition() const;
private: private:
int mOrientation; int mOrientation;
@ -227,9 +227,6 @@ private:
bool mFlip; bool mFlip;
bool mCustom; bool mCustom;
bool mbMinor; bool mbMinor;
bool mMajorGrid; // for grid drawing
bool mMinorGrid; // .
int mGridLineLength; // end
TranslatableString mUnits; TranslatableString mUnits;
bool mTwoTone; bool mTwoTone;
const ZoomInfo *mUseZoomInfo; const ZoomInfo *mUseZoomInfo;