From dcc803ecb17c984da8ae2fb7998eeb7737094a91 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 12 Jun 2017 15:27:10 +0200 Subject: [PATCH] VIEW_CONTROLS::GetMousePosition() returns the mouse position in world coordinates. --- common/tool/tool_dispatcher.cpp | 3 +-- common/view/wx_view_controls.cpp | 11 ++++++----- include/view/view_controls.h | 10 ++++++---- include/view/wx_view_controls.h | 2 +- pcbnew/router/pns_tool_base.cpp | 3 +-- pcbnew/tools/pcb_editor_control.cpp | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 7d8f80b1ea..167781c0c4 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -264,8 +264,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) wxMouseEvent* me = static_cast( &aEvent ); int mods = decodeModifiers( me ); - VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetMousePosition(); - VECTOR2D pos = getView()->ToWorld( screenPos ); + VECTOR2D pos = m_toolMgr->GetViewControls()->GetMousePosition(); if( pos != m_lastMousePos ) { diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 79863d687b..ffdcb12024 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -352,12 +352,13 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) } -VECTOR2I WX_VIEW_CONTROLS::GetMousePosition() const +VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const { wxPoint msp = wxGetMousePosition(); wxPoint winp = m_parentPanel->GetScreenPosition(); + VECTOR2D screenPos( msp.x - winp.x, msp.y - winp.y ); - return VECTOR2I( msp.x - winp.x, msp.y - winp.y ); + return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos; } @@ -372,9 +373,9 @@ VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const VECTOR2D mousePosition = GetMousePosition(); if( m_settings.m_snappingEnabled ) - return m_view->GetGAL()->GetGridPoint( m_view->ToWorld( mousePosition ) ); + return m_view->GetGAL()->GetGridPoint( mousePosition ); else - return m_view->ToWorld( mousePosition ); + return mousePosition; } } @@ -413,7 +414,7 @@ void WX_VIEW_CONTROLS::CenterOnCursor() const const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize(); VECTOR2I screenCenter( screenSize / 2 ); - if( GetMousePosition() != screenCenter ) + if( GetMousePosition( false ) != screenCenter ) { m_view->SetCenter( GetCursorPosition() ); m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) ); diff --git a/include/view/view_controls.h b/include/view/view_controls.h index cd7cb432e5..992dbacc93 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -156,18 +156,20 @@ public: /** * Function GetMousePosition() - * Returns the current mouse pointer position in screen coordinates. Note, that it may be + * Returns the current mouse pointer position. Note, that it may be * different from the cursor position if snapping is enabled (@see GetCursorPosition()). * - * @return The current mouse pointer position in the screen coordinates. + * @param aWorldCoordinates if true, the result is given in world coordinates, otherwise + * it is given in screen coordinates. + * @return The current mouse pointer position in either world or screen coordinates. */ - virtual VECTOR2I GetMousePosition() const = 0; + virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0; /** * Function GetCursorPosition() * Returns the current cursor position in world coordinates. Note, that it may be * different from the mouse pointer position if snapping is enabled or cursor position - * is forced to specific point. + * is forced to a specific point. * * @return The current cursor position in world coordinates. */ diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 5edf54b45d..41e80b3bd2 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -78,7 +78,7 @@ public: */ /// @copydoc VIEW_CONTROLS::GetMousePosition() - VECTOR2I GetMousePosition() const override; + VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override; /// @copydoc VIEW_CONTROLS::GetCursorPosition() VECTOR2D GetCursorPosition() const override; diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 26dd62ef86..d2b2f193ae 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -238,8 +238,7 @@ void TOOL_BASE::updateStartItem( TOOL_EVENT& aEvent ) void TOOL_BASE::updateEndItem( const TOOL_EVENT& aEvent ) { - VECTOR2I mp = m_ctls->GetMousePosition(); - VECTOR2I p = getView()->ToWorld( mp ); + VECTOR2I p = m_ctls->GetMousePosition(); int layer; bool snapEnabled = !aEvent.Modifier( MD_SHIFT ); diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 771f245181..9fe404b9b5 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -1032,7 +1032,7 @@ int PCB_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent ) else { // No net code specified, pick the net code belonging to the item under the cursor - highlightNet( m_toolMgr, getView()->ToWorld( getViewControls()->GetMousePosition() ) ); + highlightNet( m_toolMgr, getViewControls()->GetMousePosition() ); } return 0;