Added mouse position refresh event WX_VIEW_CONTROLS::WarpCursor()

This commit is contained in:
Maciej Suminski 2017-09-22 11:13:26 +02:00
parent da037027fb
commit df472e6426
3 changed files with 38 additions and 19 deletions

View File

@ -323,22 +323,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
dir = m_view->ToWorld( dir, false );
m_view->SetCenter( m_view->GetCenter() + dir * m_settings.m_autoPanSpeed );
// Notify tools that the cursor position has changed in the world coordinates
wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
// Set the modifiers state
#if wxCHECK_VERSION( 3, 0, 0 )
moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
#else
// wx <3.0 do not have accessors, but the fields are exposed
moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
#endif
wxPostEvent( m_parentPanel, moveEvent );
refreshMouse();
}
break;
@ -477,6 +462,8 @@ void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordin
{
m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
}
refreshMouse();
}
@ -554,6 +541,27 @@ bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
}
void WX_VIEW_CONTROLS::refreshMouse() const
{
// Notify tools that the cursor position has changed in the world coordinates
wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
// Set the modifiers state
#if wxCHECK_VERSION( 3, 0, 0 )
moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
#else
// wx <3.0 do not have accessors, but the fields are exposed
moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
#endif
wxPostEvent( m_parentPanel, moveEvent );
}
void WX_VIEW_CONTROLS::UpdateScrollbars()
{
const BOX2D viewport = m_view->GetViewport();

View File

@ -113,6 +113,13 @@ private:
*/
bool handleAutoPanning( const wxMouseEvent& aEvent );
/**
* Sends an event to refresh mouse position. It is mostly used for notifying the tools
* that the cursor position in the world coordinates has changed, whereas the screen coordinates
* remained the same (e.g. frame edge autopanning).
*/
void refreshMouse() const;
/// Current state of VIEW_CONTROLS
STATE m_state;

View File

@ -1096,17 +1096,21 @@ int SELECTION_TOOL::findMove( const TOOL_EVENT& aEvent )
if( module )
{
KIGFX::VIEW_CONTROLS* viewCtrls = getViewControls();
clearSelection();
toggleSelection( module );
auto cursorPosition = viewCtrls->GetCursorPosition( false );
// Place event on module origin first, so the generic anchor snap
// doesn't just choose the closest pin for us
// Don't warp the view - we want the component to
// "teleport" to cursor, not move to the components position
getViewControls()->ForceCursorPosition( true, module->GetPosition() );
viewCtrls->ForceCursorPosition( true, module->GetPosition() );
// pick the component up and start moving
m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" );
// restore the previous cursor position
viewCtrls->SetCursorPosition( cursorPosition, false );
}
return 0;