Cursor warps to the drag origin (GAL).
This commit is contained in:
parent
5fb7c211f9
commit
36d3d9f78e
|
@ -1063,7 +1063,7 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
|
||||||
gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
|
gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
|
||||||
|
|
||||||
// Transfer EDA_DRAW_PANEL settings
|
// Transfer EDA_DRAW_PANEL settings
|
||||||
GetGalCanvas()->GetViewControls()->SetEnableZoomNoCenter( m_canvas->GetEnableZoomNoCenter() );
|
GetGalCanvas()->GetViewControls()->EnableCursorWarping( !m_canvas->GetEnableZoomNoCenter() );
|
||||||
|
|
||||||
GetToolManager()->RunAction( "pcbnew.Control.switchCursor" );
|
GetToolManager()->RunAction( "pcbnew.Control.switchCursor" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -644,7 +644,7 @@ void EDA_DRAW_PANEL::SetEnableZoomNoCenter( bool aEnable )
|
||||||
m_enableZoomNoCenter = aEnable;
|
m_enableZoomNoCenter = aEnable;
|
||||||
|
|
||||||
if( GetParent()->IsGalCanvasActive() )
|
if( GetParent()->IsGalCanvasActive() )
|
||||||
GetParent()->GetGalCanvas()->GetViewControls()->SetEnableZoomNoCenter( aEnable );
|
GetParent()->GetGalCanvas()->GetViewControls()->EnableCursorWarping( !aEnable );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -151,18 +151,18 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
|
||||||
zoomScale = ( rotation > 0 ) ? 1.05 : 0.95;
|
zoomScale = ( rotation > 0 ) ? 1.05 : 0.95;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( GetEnableZoomNoCenter() )
|
if( IsCursorWarpingEnabled() )
|
||||||
{
|
|
||||||
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();
|
const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
|
||||||
m_view->SetCenter( GetCursorPosition() );
|
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 );
|
m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
|
||||||
|
m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aEvent.Skip();
|
aEvent.Skip();
|
||||||
|
@ -339,7 +339,9 @@ VECTOR2D WX_VIEW_CONTROLS::GetMousePosition() const
|
||||||
VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const
|
VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const
|
||||||
{
|
{
|
||||||
if( m_forceCursorPosition )
|
if( m_forceCursorPosition )
|
||||||
|
{
|
||||||
return m_forcedPosition;
|
return m_forcedPosition;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VECTOR2D mousePosition = GetMousePosition();
|
VECTOR2D mousePosition = GetMousePosition();
|
||||||
|
@ -352,6 +354,35 @@ VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates,
|
||||||
|
bool aWarpView ) const
|
||||||
|
{
|
||||||
|
if( aWorldCoordinates )
|
||||||
|
{
|
||||||
|
const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
|
||||||
|
BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
|
||||||
|
VECTOR2D screenPos = m_view->ToScreen( aPosition );
|
||||||
|
|
||||||
|
if( !screen.Contains( screenPos ) )
|
||||||
|
{
|
||||||
|
if( aWarpView )
|
||||||
|
{
|
||||||
|
m_view->SetCenter( aPosition );
|
||||||
|
m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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() );
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ),
|
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ),
|
||||||
m_forceCursorPosition( false ), m_cursorCaptured( false ), m_snappingEnabled( false ),
|
m_forceCursorPosition( false ), m_cursorCaptured( false ), m_snappingEnabled( false ),
|
||||||
m_grabMouse( false ), m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ),
|
m_grabMouse( false ), m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ),
|
||||||
m_autoPanSpeed( 0.15 ), m_enableZoomNoCenter( false )
|
m_autoPanSpeed( 0.15 ), m_warpCursor( false )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public:
|
||||||
virtual void SetAutoPanMargin( float aMargin )
|
virtual void SetAutoPanMargin( float aMargin )
|
||||||
{
|
{
|
||||||
m_autoPanMargin = aMargin;
|
m_autoPanMargin = aMargin;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetMousePosition()
|
* Function GetMousePosition()
|
||||||
|
@ -131,7 +131,7 @@ public:
|
||||||
* Function ForceCursorPosition()
|
* Function ForceCursorPosition()
|
||||||
* Places the cursor immediately at a given point. Mouse movement is ignored.
|
* Places the cursor immediately at a given point. Mouse movement is ignored.
|
||||||
* @param aEnabled enable forced cursor position
|
* @param aEnabled enable forced cursor position
|
||||||
* @param aPosition the position
|
* @param aPosition the position (world coordinates).
|
||||||
*/
|
*/
|
||||||
virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
|
virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
|
||||||
{
|
{
|
||||||
|
@ -162,20 +162,35 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetEnableZoomNoCenter()
|
* Function WarpCursor()
|
||||||
* Enables or Disables warping the cursor to the center of the drawing i
|
* If enabled (@see SetEnableCursorWarping(), warps the cursor to the specified position,
|
||||||
* panel area when zooming.
|
* expressed either in the screen coordinates or the world coordinates.
|
||||||
* @param aEnabled is true if the cursor should not be centered and false if
|
* @param aPosition is the position where the cursor should be warped.
|
||||||
* the cursor should be centered.
|
* @param aWorldCoordinates if true treats aPosition as the world coordinates, otherwise it
|
||||||
|
* uses it as the screen coordinates.
|
||||||
|
* @param aWarpView determines if the view can be warped too (only matters if the position is
|
||||||
|
* specified in the world coordinates and its not visible in the current viewport).
|
||||||
*/
|
*/
|
||||||
virtual void SetEnableZoomNoCenter( bool aEnable )
|
virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
|
||||||
|
bool aWarpView = false ) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function EnableCursorWarping()
|
||||||
|
* Enables or disables warping the cursor.
|
||||||
|
* @param aEnabled is true if the cursor is allowed to be warped.
|
||||||
|
*/
|
||||||
|
void EnableCursorWarping( bool aEnable )
|
||||||
{
|
{
|
||||||
m_enableZoomNoCenter = aEnable;
|
m_warpCursor = aEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool GetEnableZoomNoCenter() const
|
/**
|
||||||
|
* Function IsCursorWarpingEnabled()
|
||||||
|
* Returns the current setting for cursor warping.
|
||||||
|
*/
|
||||||
|
bool IsCursorWarpingEnabled() const
|
||||||
{
|
{
|
||||||
return m_enableZoomNoCenter;
|
return m_warpCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -209,8 +224,8 @@ 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
|
/// If the cursor is allowed to be warped
|
||||||
bool m_enableZoomNoCenter;
|
bool m_warpCursor;
|
||||||
};
|
};
|
||||||
} // namespace KIGFX
|
} // namespace KIGFX
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,10 @@ public:
|
||||||
/// @copydoc VIEW_CONTROLS::GetCursorPosition()
|
/// @copydoc VIEW_CONTROLS::GetCursorPosition()
|
||||||
VECTOR2D GetCursorPosition() const;
|
VECTOR2D GetCursorPosition() const;
|
||||||
|
|
||||||
|
/// @copydoc VIEW_CONTROLS::CursorWarp()
|
||||||
|
void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
|
||||||
|
bool aWarpView = false ) const;
|
||||||
|
|
||||||
/// Adjusts the scrollbars position to match the current viewport.
|
/// Adjusts the scrollbars position to match the current viewport.
|
||||||
void UpdateScrollbars();
|
void UpdateScrollbars();
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
if( m_dragging && evt->Category() == TC_MOUSE )
|
if( m_dragging && evt->Category() == TC_MOUSE )
|
||||||
{
|
{
|
||||||
m_cursor = grid.BestSnapAnchor( evt->Position(), item );
|
m_cursor = grid.BestSnapAnchor( evt->Position(), item );
|
||||||
getViewControls()->ForceCursorPosition( true, m_cursor );
|
controls->ForceCursorPosition( true, m_cursor );
|
||||||
|
|
||||||
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) - item->GetPosition();
|
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) - item->GetPosition();
|
||||||
totalMovement += movement;
|
totalMovement += movement;
|
||||||
|
@ -222,7 +222,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cursor = getViewControls()->GetCursorPosition();
|
m_cursor = controls->GetCursorPosition();
|
||||||
|
|
||||||
if( selection.Size() == 1 )
|
if( selection.Size() == 1 )
|
||||||
{
|
{
|
||||||
|
@ -232,7 +232,9 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
grid.SetAuxAxes( true, m_cursor );
|
grid.SetAuxAxes( true, m_cursor );
|
||||||
}
|
}
|
||||||
|
|
||||||
getViewControls()->ForceCursorPosition( true, m_cursor );
|
controls->ForceCursorPosition( true, m_cursor );
|
||||||
|
controls->WarpCursor( m_cursor, true );
|
||||||
|
|
||||||
VECTOR2I o = VECTOR2I( item->GetPosition() );
|
VECTOR2I o = VECTOR2I( item->GetPosition() );
|
||||||
m_offset.x = o.x - m_cursor.x;
|
m_offset.x = o.x - m_cursor.x;
|
||||||
m_offset.y = o.y - m_cursor.y;
|
m_offset.y = o.y - m_cursor.y;
|
||||||
|
|
|
@ -84,7 +84,7 @@ 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()->GetEnableZoomNoCenter() )
|
if( !getViewControls()->IsCursorWarpingEnabled() )
|
||||||
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
|
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,7 @@ int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent )
|
||||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||||
view->SetCenter( getViewControls()->GetCursorPosition() );
|
view->SetCenter( getViewControls()->GetCursorPosition() );
|
||||||
|
|
||||||
if( !getViewControls()->GetEnableZoomNoCenter() )
|
if( getViewControls()->IsCursorWarpingEnabled() )
|
||||||
{
|
{
|
||||||
const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();
|
const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();
|
||||||
m_frame->GetGalCanvas()->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
m_frame->GetGalCanvas()->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
|
||||||
|
|
Loading…
Reference in New Issue