Add centering cursor on zoom to GAL.

This commit is contained in:
Jon Neal 2015-07-09 10:18:27 +02:00 committed by Maciej Suminski
parent 901e96126d
commit fdf5b821f0
6 changed files with 55 additions and 4 deletions

View File

@ -1062,6 +1062,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
// Transfer EDA_DRAW_PANEL settings
GetGalCanvas()->GetViewControls()->SetEnableZoomNoCenter( m_canvas->GetEnableZoomNoCenter() );
GetToolManager()->RunAction( "pcbnew.Control.switchCursor" ); GetToolManager()->RunAction( "pcbnew.Control.switchCursor" );
} }
else if( m_galCanvasActive ) else if( m_galCanvasActive )

View File

@ -38,6 +38,7 @@
#include <class_draw_panel_gal.h> #include <class_draw_panel_gal.h>
#include <class_base_screen.h> #include <class_base_screen.h>
#include <draw_frame.h> #include <draw_frame.h>
#include <view/view_controls.h>
#include <kicad_device_context.h> #include <kicad_device_context.h>
@ -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 ) void EDA_DRAW_PANEL::DrawBackGround( wxDC* DC )
{ {
EDA_COLOR_T axis_color = BLUE; EDA_COLOR_T axis_color = BLUE;

View File

@ -151,8 +151,18 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
zoomScale = ( rotation > 0 ) ? 1.05 : 0.95; zoomScale = ( rotation > 0 ) ? 1.05 : 0.95;
} }
VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); if( GetEnableZoomNoCenter() )
m_view->SetScale( m_view->GetScale() * zoomScale, anchor ); {
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(); aEvent.Skip();

View File

@ -148,7 +148,7 @@ public:
bool GetEnableZoomNoCenter() const { return m_enableZoomNoCenter; } bool GetEnableZoomNoCenter() const { return m_enableZoomNoCenter; }
void SetEnableZoomNoCenter( bool aEnable ) { m_enableZoomNoCenter = aEnable; } void SetEnableZoomNoCenter( bool aEnable );
bool GetMiddleButtonPanLimited() const { return m_panScrollbarLimits; } bool GetMiddleButtonPanLimited() const { return m_panScrollbarLimits; }

View File

@ -161,6 +161,23 @@ public:
return m_forceCursorPosition; 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: protected:
/// Pointer to controlled VIEW. /// Pointer to controlled VIEW.
VIEW* m_view; VIEW* m_view;
@ -191,6 +208,9 @@ protected:
/// How fast is panning when in auto mode /// How fast is panning when in auto mode
float m_autoPanSpeed; float m_autoPanSpeed;
/// If the cursor should be warped to the center of the view area when zooming
bool m_enableZoomNoCenter;
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -84,7 +84,15 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) ) else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) )
zoomScale = 0.7; 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; return 0;
} }