From e3a03ff07ed534f6f67c2e1caa43bf6f46e20894 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 9 Jun 2015 19:46:03 -0400 Subject: [PATCH] Tick size on the time ruler will not jump when fisheye approaches ends --- src/widgets/Ruler.cpp | 43 +++++++++++++++++++++++++++++++++---------- src/widgets/Ruler.h | 12 ++++++++++-- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 49ce486f3..994e15fe8 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -98,8 +98,8 @@ using std::max; Ruler::Ruler() { - mMin = 0.0; - mMax = 100.0; + mMin = mHiddenMin = 0.0; + mMax = mHiddenMax = 100.0; mOrientation = wxHORIZONTAL; mSpacing = 6; mHasSetSpacing = false; @@ -233,14 +233,27 @@ void Ruler::SetOrientation(int orient) } void Ruler::SetRange(double min, double max) +{ + SetRange(min, max, min, max); +} + +void Ruler::SetRange + (double min, double max, double hiddenMin, double hiddenMax) { // For a horizontal ruler, // min is the value in the center of pixel "left", // max is the value in the center of pixel "right". - if (mMin != min || mMax != max) { + // In the special case of a time ruler, + // hiddenMin and hiddenMax are values that would be shown with the fisheye + // turned off. In other cases they equal min and max respectively. + + if (mMin != min || mMax != max || + mHiddenMin != hiddenMin || mHiddenMax != hiddenMax) { mMin = min; mMax = max; + mHiddenMin = hiddenMin; + mHiddenMax = hiddenMax; Invalidate(); } @@ -1070,7 +1083,11 @@ void Ruler::Update(TimeTrack* timetrack)// Envelope *speedEnv, long minSpeed, lo } else if(mLog==false) { - double UPP = (mMax-mMin)/mLength; // Units per pixel + // Use the "hidden" min and max to determine the tick size. + // That may make a difference with fisheye. + // Otherwise you may see the tick size for the whole ruler change + // when the fisheye approaches start or end. + double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel FindLinearTickSizes(UPP); // Left and Right Edges @@ -1148,7 +1165,7 @@ void Ruler::Update(TimeTrack* timetrack)// Envelope *speedEnv, long minSpeed, lo } else { // log case - mDigits=2; //TODO: implement dynamic digit computation + mDigits=2; //TODO: implement dynamic digit computation double loLog = log10(mMin); double hiLog = log10(mMax); double scale = mLength/(hiLog - loLog); @@ -1843,14 +1860,18 @@ void AdornedRulerPanel::OnSize(wxSizeEvent & WXUNUSED(evt)) Refresh( false ); } -double AdornedRulerPanel::Pos2Time(int p) +double AdornedRulerPanel::Pos2Time(int p, bool ignoreFisheye) { - return mViewInfo->PositionToTime(p, mLeftOffset); + return mViewInfo->PositionToTime(p, mLeftOffset + , ignoreFisheye + ); } -int AdornedRulerPanel::Time2Pos(double t) +int AdornedRulerPanel::Time2Pos(double t, bool ignoreFisheye) { - return mViewInfo->TimeToPosition(t, mLeftOffset); + return mViewInfo->TimeToPosition(t, mLeftOffset + , ignoreFisheye + ); } @@ -2360,10 +2381,12 @@ void AdornedRulerPanel::DoDrawBorder(wxDC * dc) void AdornedRulerPanel::DoDrawMarks(wxDC * dc, bool /*text */ ) { const double min = Pos2Time(0); + const double hiddenMin = Pos2Time(0, true); const double max = Pos2Time(mInner.width); + const double hiddenMax = Pos2Time(mInner.width, true); ruler.SetTickColour( theTheme.Colour( clrTrackPanelText ) ); - ruler.SetRange( min, max ); + ruler.SetRange( min, max, hiddenMin, hiddenMax ); ruler.Draw( *dc ); } diff --git a/src/widgets/Ruler.h b/src/widgets/Ruler.h index 5d52cda2b..935659e81 100644 --- a/src/widgets/Ruler.h +++ b/src/widgets/Ruler.h @@ -56,6 +56,13 @@ class AUDACITY_DLL_API Ruler { // (at the center of the pixel, in both cases) void SetRange(double min, double max); + // An overload needed for the special case of fisheye + // min is the value at (x, y) + // max is the value at (x+width, y+height) + // hiddenMin, hiddenMax are the values that would be shown without the fisheye. + // (at the center of the pixel, in both cases) + void SetRange(double min, double max, double hiddenMin, double hiddenMax); + // // Optional Ruler Parameters // @@ -167,6 +174,7 @@ private: bool mUserFonts; double mMin, mMax; + double mHiddenMin, mHiddenMax; double mMajor; double mMinor; @@ -305,8 +313,8 @@ private: void DrawQuickPlayIndicator(wxDC * dc, bool clear /*delete old only*/); void DoDrawPlayRegion(wxDC * dc); - double Pos2Time(int p); - int Time2Pos(double t); + double Pos2Time(int p, bool ignoreFisheye = false); + int Time2Pos(double t, bool ignoreFisheye = false); bool IsWithinMarker(int mousePosX, double markerTime);