From fa3f91b38d1512e42fba4d2cff2db8a5dd9daf69 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 26 May 2015 21:28:22 -0400 Subject: [PATCH] Horizontal scrolling snaps 0 to left edge and guarantees it is reachable --- src/Project.cpp | 41 +++++++++++++++++++++++++++-------------- src/Project.h | 2 ++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 3ac1d05db..e2c073cb9 100755 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1455,11 +1455,7 @@ void AudacityProject::OnScrollRightButton(wxScrollEvent & event) } -// -// This method, like the other methods prefaced with TP, handles TrackPanel -// 'callback'. -// -void AudacityProject::TP_ScrollWindow(double scrollto) +void AudacityProject::SetHorizontalThumb(double scrollto) { double timeOffset = 0; #ifdef EXPERIMENTAL_SCROLLING_LIMITS @@ -1476,6 +1472,15 @@ void AudacityProject::TP_ScrollWindow(double scrollto) pos = 0; mHsbar->SetThumbPosition(pos); +} + +// +// This method, like the other methods prefaced with TP, handles TrackPanel +// 'callback'. +// +void AudacityProject::TP_ScrollWindow(double scrollto) +{ + SetHorizontalThumb(scrollto); // Call our Scroll method which updates our ViewInfo variables // to reflect the positions of the scrollbars @@ -1526,22 +1531,25 @@ void AudacityProject::FixScrollbars() int panelWidth, panelHeight; mTrackPanel->GetTracksUsableArea(&panelWidth, &panelHeight); + double LastTime = + std::max(mTracks->GetEndTime(), mViewInfo.selectedRegion.t1()); + mViewInfo.screen = ((double) panelWidth) / mViewInfo.zoom; + const double halfScreen = mViewInfo.screen / 2.0; double additional, lowerBound; #ifdef EXPERIMENTAL_SCROLLING_LIMITS // Add 1/2 of a screen of blank space to the end // and another 1/2 screen before the beginning // so that any point within the union of the selection and the track duration // may be scrolled to the midline. - additional = mViewInfo.screen; - lowerBound = - additional / 2.0; + // May add even more to the end, so that you can always scroll the starting time to zero. + additional = halfScreen + std::max(halfScreen, mViewInfo.screen - LastTime); + lowerBound = - halfScreen; #else // Formerly just added 1/4 screen at the end additional = mViewInfo.screen / 4.0; lowerBound = 0.0; #endif - double LastTime = - std::max( mTracks->GetEndTime(), mViewInfo.selectedRegion.t1() ); mViewInfo.total = LastTime + additional; // Don't remove time from total that's still on the screen @@ -1625,11 +1633,7 @@ void AudacityProject::FixScrollbars() int scaledSbarScreen = (int)(mViewInfo.sbarScreen * mViewInfo.sbarScale); int scaledSbarTotal = (int)(mViewInfo.sbarTotal * mViewInfo.sbarScale); int offset; -#ifdef EXPERIMENTAL_SCROLLING_LIMITS - offset = scaledSbarScreen / 2; -#else - offset = 0; -#endif + offset = -lowerBound * mViewInfo.zoom * mViewInfo.sbarScale; mHsbar->SetScrollbar(scaledSbarH + offset, scaledSbarScreen, scaledSbarTotal, scaledSbarScreen, TRUE); @@ -1842,6 +1846,15 @@ void AudacityProject::OnScroll(wxScrollEvent & WXUNUSED(event)) mViewInfo.h = lowerBound; } +#ifdef EXPERIMENTAL_SCROLLING_LIMITS + enum { SCROLL_PIXEL_TOLERANCE = 10 }; + if (fabs(mViewInfo.h * mViewInfo.zoom) < SCROLL_PIXEL_TOLERANCE) { + // Snap the scrollbar to 0 + mViewInfo.h = 0; + SetHorizontalThumb(0.0); + } +#endif + int lastv = mViewInfo.vpos; mViewInfo.vpos = mVsbar->GetThumbPosition() * mViewInfo.scrollStep; diff --git a/src/Project.h b/src/Project.h index 06e9f835d..ca2b8d50e 100755 --- a/src/Project.h +++ b/src/Project.h @@ -348,6 +348,8 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame, void SafeDisplayStatusMessage(const wxChar *msg); + void SetHorizontalThumb(double scrollto); + // TrackPanel access virtual wxSize GetTPTracksUsableArea(); virtual void RefreshTPTrack(Track* pTrk, bool refreshbacking = true);