From fdf5b821f0a337a25d04ab66c25d8b81cab374bc Mon Sep 17 00:00:00 2001 From: Jon Neal Date: Thu, 9 Jul 2015 10:18:27 +0200 Subject: [PATCH] Add centering cursor on zoom to GAL. --- common/draw_frame.cpp | 3 +++ common/draw_panel.cpp | 10 ++++++++++ common/view/wx_view_controls.cpp | 14 ++++++++++++-- include/class_drawpanel.h | 2 +- include/view/view_controls.h | 20 ++++++++++++++++++++ pcbnew/tools/pcbnew_control.cpp | 10 +++++++++- 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 485a5deff0..32cd93a111 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -1062,6 +1062,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); + // Transfer EDA_DRAW_PANEL settings + GetGalCanvas()->GetViewControls()->SetEnableZoomNoCenter( m_canvas->GetEnableZoomNoCenter() ); + GetToolManager()->RunAction( "pcbnew.Control.switchCursor" ); } else if( m_galCanvasActive ) diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp index 437324d1ed..74b4e1bcb7 100644 --- a/common/draw_panel.cpp +++ b/common/draw_panel.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -638,6 +639,15 @@ void EDA_DRAW_PANEL::ReDraw( wxDC* DC, bool erasebg ) } +void EDA_DRAW_PANEL::SetEnableZoomNoCenter( bool aEnable ) +{ + m_enableZoomNoCenter = aEnable; + + if( GetParent()->IsGalCanvasActive() ) + GetParent()->GetGalCanvas()->GetViewControls()->SetEnableZoomNoCenter( aEnable ); +} + + void EDA_DRAW_PANEL::DrawBackGround( wxDC* DC ) { EDA_COLOR_T axis_color = BLUE; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 061f88246d..7bb333004a 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -151,8 +151,18 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) zoomScale = ( rotation > 0 ) ? 1.05 : 0.95; } - VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); - m_view->SetScale( m_view->GetScale() * zoomScale, anchor ); + if( GetEnableZoomNoCenter() ) + { + VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); + m_view->SetScale( m_view->GetScale() * zoomScale, anchor ); + } + else + { + const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize(); + m_view->SetCenter( GetCursorPosition() ); + m_view->SetScale( m_view->GetScale() * zoomScale ); + m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 ); + } } aEvent.Skip(); diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index 738f19947d..f03e220997 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -148,7 +148,7 @@ public: bool GetEnableZoomNoCenter() const { return m_enableZoomNoCenter; } - void SetEnableZoomNoCenter( bool aEnable ) { m_enableZoomNoCenter = aEnable; } + void SetEnableZoomNoCenter( bool aEnable ); bool GetMiddleButtonPanLimited() const { return m_panScrollbarLimits; } diff --git a/include/view/view_controls.h b/include/view/view_controls.h index e0d3e31d98..74c3d64a17 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -161,6 +161,23 @@ public: return m_forceCursorPosition; } + /** + * Function SetEnableZoomNoCenter() + * Enables or Disables warping the cursor to the center of the drawing i + * panel area when zooming. + * @param aEnabled is true if the cursor should not be centered and false if + * the cursor should be centered. + */ + virtual void SetEnableZoomNoCenter( bool aEnable ) + { + m_enableZoomNoCenter = aEnable; + } + + virtual bool GetEnableZoomNoCenter() const + { + return m_enableZoomNoCenter; + } + protected: /// Pointer to controlled VIEW. VIEW* m_view; @@ -191,6 +208,9 @@ protected: /// How fast is panning when in auto mode float m_autoPanSpeed; + + /// If the cursor should be warped to the center of the view area when zooming + bool m_enableZoomNoCenter; }; } // namespace KIGFX diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 926a38d004..44f380297c 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -84,7 +84,15 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent ) else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) ) zoomScale = 0.7; - view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() ); + if( getViewControls()->GetEnableZoomNoCenter() ) + view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() ); + else + { + const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize(); + view->SetCenter( getViewControls()->GetCursorPosition() ); + view->SetScale( view->GetScale() * zoomScale ); + m_frame->GetGalCanvas()->WarpPointer( screenSize.x / 2, screenSize.y / 2 ); + } return 0; }