From f47cb3d5282627215c9a3545af794ebfecad4eff Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 28 Jan 2016 10:36:48 -0500 Subject: [PATCH] Bug1197, yet again: extreme zoom-in behavior, now Mac specific: ... ...fix differing results on Mac by calculating only in double, so that selection remains centered at extreme zoom-in for long projects (about 20 min.) and selection after about 15 min. --- src/Project.cpp | 24 ++++++++++++------------ src/Project.h | 3 ++- src/ViewInfo.cpp | 7 +++++++ src/ViewInfo.h | 4 ++++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index ccab3cd25..8dd1a0837 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1513,24 +1513,23 @@ double AudacityProject::ScrollingLowerBoundTime() const return std::min(mTracks->GetStartTime(), -screen / 2.0); } -wxInt64 AudacityProject::PixelWidthBeforeTime(double scrollto) const +// PRL: Bug1197: we seem to need to compute all in double, to avoid differing results on Mac +// That's why ViewInfo::TimeRangeToPixelWidth was defined, with some regret. +double AudacityProject::PixelWidthBeforeTime(double scrollto) const { const double lowerBound = ScrollingLowerBoundTime(); return - mViewInfo.TimeToPosition(scrollto, 0 - , true - ) - - mViewInfo.TimeToPosition(lowerBound, 0 - , true - ); + // Ignoring fisheye is correct here + mViewInfo.TimeRangeToPixelWidth(scrollto - lowerBound); } void AudacityProject::SetHorizontalThumb(double scrollto) { - wxInt64 max = mHsbar->GetRange() - mHsbar->GetThumbSize(); - int pos = std::min(max, - std::max(wxInt64(0), - wxInt64(PixelWidthBeforeTime(scrollto) * mViewInfo.sbarScale))); + const int max = mHsbar->GetRange() - mHsbar->GetThumbSize(); + const int pos = + std::min(max, + std::max(0, + int(floor(0.5 + PixelWidthBeforeTime(scrollto) * mViewInfo.sbarScale)))); mHsbar->SetThumbPosition(pos); } @@ -1704,7 +1703,8 @@ void AudacityProject::FixScrollbars() int scaledSbarH = (int)(mViewInfo.sbarH * mViewInfo.sbarScale); int scaledSbarScreen = (int)(mViewInfo.sbarScreen * mViewInfo.sbarScale); int scaledSbarTotal = (int)(mViewInfo.sbarTotal * mViewInfo.sbarScale); - const int offset = mViewInfo.sbarScale * PixelWidthBeforeTime(0.0); + const int offset = + int(floor(0.5 + mViewInfo.sbarScale * PixelWidthBeforeTime(0.0))); mHsbar->SetScrollbar(scaledSbarH + offset, scaledSbarScreen, scaledSbarTotal, scaledSbarScreen, TRUE); diff --git a/src/Project.h b/src/Project.h index 7a212eacd..a66819fc5 100644 --- a/src/Project.h +++ b/src/Project.h @@ -384,7 +384,8 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame, double ScrollingLowerBoundTime() const; // How many pixels are covered by the period from lowermost scrollable time, to the given time: - wxInt64 PixelWidthBeforeTime(double scrollto) const; + // PRL: Bug1197: we seem to need to compute all in double, to avoid differing results on Mac + double PixelWidthBeforeTime(double scrollto) const; void SetHorizontalThumb(double scrollto); // TrackPanel access diff --git a/src/ViewInfo.cpp b/src/ViewInfo.cpp index 6f659563b..25132ba20 100644 --- a/src/ViewInfo.cpp +++ b/src/ViewInfo.cpp @@ -63,6 +63,13 @@ wxInt64 ZoomInfo::TimeToPosition(double projectTime, ); } +// This always ignores the fisheye. Use with caution! +// You should prefer to call TimeToPosition twice, for endpoints, and take the difference! +double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const +{ + return timeRange * zoom; +} + bool ZoomInfo::ZoomInAvailable() const { return zoom < gMaxZoom; diff --git a/src/ViewInfo.h b/src/ViewInfo.h index 2c8d82943..134b6e41a 100644 --- a/src/ViewInfo.h +++ b/src/ViewInfo.h @@ -62,6 +62,10 @@ public: , bool ignoreFisheye = false ) const; + // This always ignores the fisheye. Use with caution! + // You should prefer to call TimeToPosition twice, for endpoints, and take the difference! + double TimeRangeToPixelWidth(double timeRange) const; + double OffsetTimeByPixels(double time, wxInt64 offset, bool ignoreFisheye = false) const { return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);