1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-26 00:58:37 +02:00

Tick size on the time ruler will not jump when fisheye approaches ends

This commit is contained in:
Paul Licameli 2015-06-09 19:46:03 -04:00
parent 79e9f2b5dd
commit e3a03ff07e
2 changed files with 43 additions and 12 deletions

View File

@ -98,8 +98,8 @@ using std::max;
Ruler::Ruler() Ruler::Ruler()
{ {
mMin = 0.0; mMin = mHiddenMin = 0.0;
mMax = 100.0; mMax = mHiddenMax = 100.0;
mOrientation = wxHORIZONTAL; mOrientation = wxHORIZONTAL;
mSpacing = 6; mSpacing = 6;
mHasSetSpacing = false; mHasSetSpacing = false;
@ -233,14 +233,27 @@ void Ruler::SetOrientation(int orient)
} }
void Ruler::SetRange(double min, double max) 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, // For a horizontal ruler,
// min is the value in the center of pixel "left", // min is the value in the center of pixel "left",
// max is the value in the center of pixel "right". // 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; mMin = min;
mMax = max; mMax = max;
mHiddenMin = hiddenMin;
mHiddenMax = hiddenMax;
Invalidate(); Invalidate();
} }
@ -1070,7 +1083,11 @@ void Ruler::Update(TimeTrack* timetrack)// Envelope *speedEnv, long minSpeed, lo
} else if(mLog==false) { } 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); FindLinearTickSizes(UPP);
// Left and Right Edges // Left and Right Edges
@ -1148,7 +1165,7 @@ void Ruler::Update(TimeTrack* timetrack)// Envelope *speedEnv, long minSpeed, lo
} }
else { else {
// log case // log case
mDigits=2; //TODO: implement dynamic digit computation mDigits=2; //TODO: implement dynamic digit computation
double loLog = log10(mMin); double loLog = log10(mMin);
double hiLog = log10(mMax); double hiLog = log10(mMax);
double scale = mLength/(hiLog - loLog); double scale = mLength/(hiLog - loLog);
@ -1843,14 +1860,18 @@ void AdornedRulerPanel::OnSize(wxSizeEvent & WXUNUSED(evt))
Refresh( false ); 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 */ ) void AdornedRulerPanel::DoDrawMarks(wxDC * dc, bool /*text */ )
{ {
const double min = Pos2Time(0); const double min = Pos2Time(0);
const double hiddenMin = Pos2Time(0, true);
const double max = Pos2Time(mInner.width); const double max = Pos2Time(mInner.width);
const double hiddenMax = Pos2Time(mInner.width, true);
ruler.SetTickColour( theTheme.Colour( clrTrackPanelText ) ); ruler.SetTickColour( theTheme.Colour( clrTrackPanelText ) );
ruler.SetRange( min, max ); ruler.SetRange( min, max, hiddenMin, hiddenMax );
ruler.Draw( *dc ); ruler.Draw( *dc );
} }

View File

@ -56,6 +56,13 @@ class AUDACITY_DLL_API Ruler {
// (at the center of the pixel, in both cases) // (at the center of the pixel, in both cases)
void SetRange(double min, double max); 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 // Optional Ruler Parameters
// //
@ -167,6 +174,7 @@ private:
bool mUserFonts; bool mUserFonts;
double mMin, mMax; double mMin, mMax;
double mHiddenMin, mHiddenMax;
double mMajor; double mMajor;
double mMinor; double mMinor;
@ -305,8 +313,8 @@ private:
void DrawQuickPlayIndicator(wxDC * dc, bool clear /*delete old only*/); void DrawQuickPlayIndicator(wxDC * dc, bool clear /*delete old only*/);
void DoDrawPlayRegion(wxDC * dc); void DoDrawPlayRegion(wxDC * dc);
double Pos2Time(int p); double Pos2Time(int p, bool ignoreFisheye = false);
int Time2Pos(double t); int Time2Pos(double t, bool ignoreFisheye = false);
bool IsWithinMarker(int mousePosX, double markerTime); bool IsWithinMarker(int mousePosX, double markerTime);