Fixed screen scrolling on zooming in/out.
This commit is contained in:
parent
cd205db812
commit
f7fa0852b5
|
@ -153,10 +153,8 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
|
|||
|
||||
if( IsCursorWarpingEnabled() )
|
||||
{
|
||||
const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
|
||||
m_view->SetCenter( GetCursorPosition() );
|
||||
CenterOnCursor();
|
||||
m_view->SetScale( m_view->GetScale() * zoomScale );
|
||||
m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -383,6 +381,19 @@ void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordin
|
|||
}
|
||||
|
||||
|
||||
void WX_VIEW_CONTROLS::CenterOnCursor() const
|
||||
{
|
||||
const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
|
||||
VECTOR2I screenCenter( screenSize / 2 );
|
||||
|
||||
if( GetMousePosition() != screenCenter )
|
||||
{
|
||||
m_view->SetCenter( GetCursorPosition() );
|
||||
m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
|
||||
{
|
||||
VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
|
||||
|
|
|
@ -193,6 +193,13 @@ public:
|
|||
return m_warpCursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function CenterOnCursor()
|
||||
* Sets the viewport center to the current cursor position and warps the cursor to the
|
||||
* screen center.
|
||||
*/
|
||||
virtual void CenterOnCursor() const = 0;
|
||||
|
||||
protected:
|
||||
/// Pointer to controlled VIEW.
|
||||
VIEW* m_view;
|
||||
|
|
|
@ -95,6 +95,9 @@ public:
|
|||
void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
|
||||
bool aWarpView = false ) const;
|
||||
|
||||
/// @copydoc VIEW_CONTROLS::CenterOnCursor()
|
||||
void CenterOnCursor() const;
|
||||
|
||||
/// Adjusts the scrollbars position to match the current viewport.
|
||||
void UpdateScrollbars();
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ void PCBNEW_CONTROL::Reset( RESET_REASON aReason )
|
|||
int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
||||
double zoomScale = 1.0;
|
||||
|
||||
if( aEvent.IsAction( &COMMON_ACTIONS::zoomIn ) )
|
||||
|
@ -84,15 +85,10 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
|||
else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) )
|
||||
zoomScale = 0.7;
|
||||
|
||||
if( !getViewControls()->IsCursorWarpingEnabled() )
|
||||
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 );
|
||||
}
|
||||
|
||||
if( ctls->IsCursorWarpingEnabled() )
|
||||
ctls->CenterOnCursor();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -100,7 +96,7 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
|||
|
||||
int PCBNEW_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||
KIGFX::VIEW* view = getView();
|
||||
double zoomScale = 1.0;
|
||||
|
||||
if( aEvent.IsAction( &COMMON_ACTIONS::zoomInCenter ) )
|
||||
|
@ -116,14 +112,12 @@ int PCBNEW_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent )
|
|||
|
||||
int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||
view->SetCenter( getViewControls()->GetCursorPosition() );
|
||||
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
||||
|
||||
if( getViewControls()->IsCursorWarpingEnabled() )
|
||||
{
|
||||
const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();
|
||||
m_frame->GetGalCanvas()->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
||||
}
|
||||
if( ctls->IsCursorWarpingEnabled() )
|
||||
ctls->CenterOnCursor();
|
||||
else
|
||||
getView()->SetCenter( getViewControls()->GetCursorPosition() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -138,19 +132,18 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
|
|||
|
||||
BOX2I boardBBox = board->ViewBBox();
|
||||
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
|
||||
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
||||
|
||||
if( boardBBox.GetWidth() == 0 || boardBBox.GetHeight() == 0 )
|
||||
{
|
||||
// Empty view
|
||||
view->SetScale( 17.0 ); // works fine for the standard worksheet frame
|
||||
|
||||
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
||||
view->SetCenter( screenSize / 2.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
VECTOR2D vsize = boardBBox.GetSize();
|
||||
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
||||
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
|
||||
fabs( vsize.y / screenSize.y ) );
|
||||
|
||||
|
|
Loading…
Reference in New Issue