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() )
|
if( IsCursorWarpingEnabled() )
|
||||||
{
|
{
|
||||||
const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
|
CenterOnCursor();
|
||||||
m_view->SetCenter( GetCursorPosition() );
|
|
||||||
m_view->SetScale( m_view->GetScale() * zoomScale );
|
m_view->SetScale( m_view->GetScale() * zoomScale );
|
||||||
m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
|
||||||
}
|
}
|
||||||
else
|
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 )
|
bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
|
||||||
{
|
{
|
||||||
VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
|
VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
|
||||||
|
|
|
@ -193,6 +193,13 @@ public:
|
||||||
return m_warpCursor;
|
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:
|
protected:
|
||||||
/// Pointer to controlled VIEW.
|
/// Pointer to controlled VIEW.
|
||||||
VIEW* m_view;
|
VIEW* m_view;
|
||||||
|
|
|
@ -95,6 +95,9 @@ public:
|
||||||
void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
|
void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
|
||||||
bool aWarpView = false ) const;
|
bool aWarpView = false ) const;
|
||||||
|
|
||||||
|
/// @copydoc VIEW_CONTROLS::CenterOnCursor()
|
||||||
|
void CenterOnCursor() const;
|
||||||
|
|
||||||
/// Adjusts the scrollbars position to match the current viewport.
|
/// Adjusts the scrollbars position to match the current viewport.
|
||||||
void UpdateScrollbars();
|
void UpdateScrollbars();
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ void PCBNEW_CONTROL::Reset( RESET_REASON aReason )
|
||||||
int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||||
|
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
||||||
double zoomScale = 1.0;
|
double zoomScale = 1.0;
|
||||||
|
|
||||||
if( aEvent.IsAction( &COMMON_ACTIONS::zoomIn ) )
|
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 ) )
|
else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) )
|
||||||
zoomScale = 0.7;
|
zoomScale = 0.7;
|
||||||
|
|
||||||
if( !getViewControls()->IsCursorWarpingEnabled() )
|
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
|
||||||
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
|
|
||||||
else
|
if( ctls->IsCursorWarpingEnabled() )
|
||||||
{
|
ctls->CenterOnCursor();
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +96,7 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
int PCBNEW_CONTROL::ZoomInOutCenter( 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;
|
double zoomScale = 1.0;
|
||||||
|
|
||||||
if( aEvent.IsAction( &COMMON_ACTIONS::zoomInCenter ) )
|
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 )
|
int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
||||||
view->SetCenter( getViewControls()->GetCursorPosition() );
|
|
||||||
|
|
||||||
if( getViewControls()->IsCursorWarpingEnabled() )
|
if( ctls->IsCursorWarpingEnabled() )
|
||||||
{
|
ctls->CenterOnCursor();
|
||||||
const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();
|
else
|
||||||
m_frame->GetGalCanvas()->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
getView()->SetCenter( getViewControls()->GetCursorPosition() );
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -138,19 +132,18 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
BOX2I boardBBox = board->ViewBBox();
|
BOX2I boardBBox = board->ViewBBox();
|
||||||
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
|
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
|
||||||
|
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
||||||
|
|
||||||
if( boardBBox.GetWidth() == 0 || boardBBox.GetHeight() == 0 )
|
if( boardBBox.GetWidth() == 0 || boardBBox.GetHeight() == 0 )
|
||||||
{
|
{
|
||||||
// Empty view
|
// Empty view
|
||||||
view->SetScale( 17.0 ); // works fine for the standard worksheet frame
|
view->SetScale( 17.0 ); // works fine for the standard worksheet frame
|
||||||
|
|
||||||
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
|
||||||
view->SetCenter( screenSize / 2.0 );
|
view->SetCenter( screenSize / 2.0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VECTOR2D vsize = boardBBox.GetSize();
|
VECTOR2D vsize = boardBBox.GetSize();
|
||||||
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
|
||||||
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
|
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
|
||||||
fabs( vsize.y / screenSize.y ) );
|
fabs( vsize.y / screenSize.y ) );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue