1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 16:39:30 +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)
}
//
// 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;

View File

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