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.
This commit is contained in:
Paul Licameli 2016-01-28 10:36:48 -05:00
parent 4e335af91f
commit f47cb3d528
4 changed files with 25 additions and 13 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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);