1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 17:09:26 +02:00

Horizontal scrolling snaps 0 to left edge and guarantees it is reachable

This commit is contained in:
Paul Licameli 2015-05-26 21:28:22 -04:00
parent 41abedf09c
commit fa3f91b38d
2 changed files with 29 additions and 14 deletions

View File

@ -1455,11 +1455,7 @@ void AudacityProject::OnScrollRightButton(wxScrollEvent & event)
} }
// void AudacityProject::SetHorizontalThumb(double scrollto)
// This method, like the other methods prefaced with TP, handles TrackPanel
// 'callback'.
//
void AudacityProject::TP_ScrollWindow(double scrollto)
{ {
double timeOffset = 0; double timeOffset = 0;
#ifdef EXPERIMENTAL_SCROLLING_LIMITS #ifdef EXPERIMENTAL_SCROLLING_LIMITS
@ -1476,6 +1472,15 @@ void AudacityProject::TP_ScrollWindow(double scrollto)
pos = 0; pos = 0;
mHsbar->SetThumbPosition(pos); 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 // Call our Scroll method which updates our ViewInfo variables
// to reflect the positions of the scrollbars // to reflect the positions of the scrollbars
@ -1526,22 +1531,25 @@ void AudacityProject::FixScrollbars()
int panelWidth, panelHeight; int panelWidth, panelHeight;
mTrackPanel->GetTracksUsableArea(&panelWidth, &panelHeight); mTrackPanel->GetTracksUsableArea(&panelWidth, &panelHeight);
double LastTime =
std::max(mTracks->GetEndTime(), mViewInfo.selectedRegion.t1());
mViewInfo.screen = ((double) panelWidth) / mViewInfo.zoom; mViewInfo.screen = ((double) panelWidth) / mViewInfo.zoom;
const double halfScreen = mViewInfo.screen / 2.0;
double additional, lowerBound; double additional, lowerBound;
#ifdef EXPERIMENTAL_SCROLLING_LIMITS #ifdef EXPERIMENTAL_SCROLLING_LIMITS
// Add 1/2 of a screen of blank space to the end // Add 1/2 of a screen of blank space to the end
// and another 1/2 screen before the beginning // and another 1/2 screen before the beginning
// so that any point within the union of the selection and the track duration // so that any point within the union of the selection and the track duration
// may be scrolled to the midline. // may be scrolled to the midline.
additional = mViewInfo.screen; // May add even more to the end, so that you can always scroll the starting time to zero.
lowerBound = - additional / 2.0; additional = halfScreen + std::max(halfScreen, mViewInfo.screen - LastTime);
lowerBound = - halfScreen;
#else #else
// Formerly just added 1/4 screen at the end // Formerly just added 1/4 screen at the end
additional = mViewInfo.screen / 4.0; additional = mViewInfo.screen / 4.0;
lowerBound = 0.0; lowerBound = 0.0;
#endif #endif
double LastTime =
std::max( mTracks->GetEndTime(), mViewInfo.selectedRegion.t1() );
mViewInfo.total = LastTime + additional; mViewInfo.total = LastTime + additional;
// Don't remove time from total that's still on the screen // 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 scaledSbarScreen = (int)(mViewInfo.sbarScreen * mViewInfo.sbarScale);
int scaledSbarTotal = (int)(mViewInfo.sbarTotal * mViewInfo.sbarScale); int scaledSbarTotal = (int)(mViewInfo.sbarTotal * mViewInfo.sbarScale);
int offset; int offset;
#ifdef EXPERIMENTAL_SCROLLING_LIMITS offset = -lowerBound * mViewInfo.zoom * mViewInfo.sbarScale;
offset = scaledSbarScreen / 2;
#else
offset = 0;
#endif
mHsbar->SetScrollbar(scaledSbarH + offset, scaledSbarScreen, scaledSbarTotal, mHsbar->SetScrollbar(scaledSbarH + offset, scaledSbarScreen, scaledSbarTotal,
scaledSbarScreen, TRUE); scaledSbarScreen, TRUE);
@ -1842,6 +1846,15 @@ void AudacityProject::OnScroll(wxScrollEvent & WXUNUSED(event))
mViewInfo.h = lowerBound; 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; int lastv = mViewInfo.vpos;
mViewInfo.vpos = mVsbar->GetThumbPosition() * mViewInfo.scrollStep; mViewInfo.vpos = mVsbar->GetThumbPosition() * mViewInfo.scrollStep;

View File

@ -348,6 +348,8 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
void SafeDisplayStatusMessage(const wxChar *msg); void SafeDisplayStatusMessage(const wxChar *msg);
void SetHorizontalThumb(double scrollto);
// TrackPanel access // TrackPanel access
virtual wxSize GetTPTracksUsableArea(); virtual wxSize GetTPTracksUsableArea();
virtual void RefreshTPTrack(Track* pTrk, bool refreshbacking = true); virtual void RefreshTPTrack(Track* pTrk, bool refreshbacking = true);