From 30a7876593122b5185222d7e4bbe441e7e0c7cff Mon Sep 17 00:00:00 2001 From: "james.k.crook@gmail.com" Date: Fri, 4 May 2012 11:47:29 +0000 Subject: [PATCH] Ctrl-Wheel Zooming now behaves like zoom buttons, so we don't zoom into empty space. --- src/Menus.cpp | 19 +++++++++++++++---- src/Project.h | 2 ++ src/TrackPanel.cpp | 18 +++++++++--------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 6ed69953e..08e009c9f 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4757,10 +4757,15 @@ void AudacityProject::OnSelectAllTracks() // void AudacityProject::OnZoomIn() +{ + ZoomInByFactor( 2.0 ); +} + +void AudacityProject::ZoomInByFactor( double ZoomFactor ) { // LLL: Handling positioning differently when audio is active if (gAudioIO->IsStreamActive(GetAudioIOToken()) != 0) { - Zoom(mViewInfo.zoom * 2.0); + Zoom(mViewInfo.zoom * ZoomFactor); mTrackPanel->ScrollIntoView(gAudioIO->GetStreamTime()); mTrackPanel->Refresh(false); return; @@ -4791,7 +4796,7 @@ void AudacityProject::OnZoomIn() (mViewInfo.h + mViewInfo.screen - mViewInfo.sel0) / 2; // Zoom in - Zoom(mViewInfo.zoom *= 2.0); + Zoom(mViewInfo.zoom *= ZoomFactor); // Recenter on selCenter TP_ScrollWindow(selCenter - mViewInfo.screen / 2); @@ -4801,7 +4806,7 @@ void AudacityProject::OnZoomIn() double origLeft = mViewInfo.h; double origWidth = mViewInfo.screen; - Zoom(mViewInfo.zoom *= 2.0); + Zoom(mViewInfo.zoom *= ZoomFactor); double newh = origLeft + (origWidth - mViewInfo.screen) / 2; @@ -4823,11 +4828,17 @@ void AudacityProject::OnZoomIn() void AudacityProject::OnZoomOut() { + ZoomOutByFactor( 1 /2.0 ); +} + + +void AudacityProject::ZoomOutByFactor( double ZoomFactor ) +{ //Zoom() may change these, so record original values: double origLeft = mViewInfo.h; double origWidth = mViewInfo.screen; - Zoom(mViewInfo.zoom /= 2.0); + Zoom(mViewInfo.zoom *=ZoomFactor); double newh = origLeft + (origWidth - mViewInfo.screen) / 2; // newh = (newh > 0) ? newh : 0; diff --git a/src/Project.h b/src/Project.h index 706d3e235..09b293668 100644 --- a/src/Project.h +++ b/src/Project.h @@ -275,6 +275,8 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame, void HandleResize(); void UpdateLayout(); + void ZoomInByFactor( double ZoomFactor ); + void ZoomOutByFactor( double ZoomFactor ); // Other commands static TrackList *GetClipboardTracks(); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index d9aa600dd..f0d178af1 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -4659,16 +4659,16 @@ void TrackPanel::HandleWheelRotation(wxMouseEvent & event) 50.0 * -steps / mViewInfo->zoom); } else if (event.CmdDown()) { - // MM: Zoom in/out when used with Control key down - // MM: I don't understand what trackLeftEdge does - int trackLeftEdge = GetLeftOffset(); - - double center_h = PositionToTime(event.m_x, trackLeftEdge); - mViewInfo->zoom = wxMin(mViewInfo->zoom * pow(2.0, steps), gMaxZoom); + // JKC: Now using AudacityProject zooming, which is smarter, + // it keeps selections on screen and centred if it can, + // also this ensures mousewheel and zoom buttons give same result. + double ZoomFactor = pow(2.0, steps); + AudacityProject *p = GetProject(); + if( steps > 0 ) + p->ZoomInByFactor( ZoomFactor ); + else + p->ZoomOutByFactor( ZoomFactor ); - double new_center_h = PositionToTime(event.m_x, trackLeftEdge); - mViewInfo->h += (center_h - new_center_h); - MakeParentRedrawScrollbars(); Refresh(false); } else