From 033b25de326442d60fa01014fe39f425e9ccd186 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 16:46:02 +0200 Subject: [PATCH] Reenabled snapping for tools. --- common/tool/tool_dispatcher.cpp | 14 +++----------- common/view/wx_view_controls.cpp | 23 ++++++++++++++++++----- include/tool/tool_dispatcher.h | 2 -- include/view/view_controls.h | 24 ++---------------------- include/view/wx_view_controls.h | 6 ++++++ 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 03ff9ef9b3..ad3a38c857 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -122,15 +123,6 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const } -wxPoint TOOL_DISPATCHER::getCurrentMousePos() const -{ - wxPoint msp = wxGetMousePosition(); - wxPoint winp = m_editFrame->GetGalCanvas()->GetScreenPosition(); - - return wxPoint( msp.x - winp.x, msp.y - winp.y ); -} - - bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ) { ButtonState* st = m_buttons[aIndex]; @@ -208,7 +200,6 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) { bool motion = false, buttonEvents = false; - VECTOR2D pos; optional evt; int type = aEvent.GetEventType(); @@ -220,7 +211,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || type == EVT_REFRESH_MOUSE ) { - pos = getView()->ToWorld ( getCurrentMousePos() ); + VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetCursorPosition(); + VECTOR2D pos = getView()->ToWorld( screenPos ); if( pos != m_lastMousePos || type == EVT_REFRESH_MOUSE ) { motion = true; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 1349948501..9776710676 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -65,11 +65,6 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) m_mousePosition.x = aEvent.GetX(); m_mousePosition.y = aEvent.GetY(); - if( m_snappingEnabled ) - m_cursorPosition = m_view->GetGAL()->GetGridPoint( m_mousePosition ); - else - m_cursorPosition = m_mousePosition; - bool isAutoPanning = false; if( m_autoPanEnabled ) @@ -222,6 +217,24 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) } +const VECTOR2D WX_VIEW_CONTROLS::GetMousePosition() const +{ + wxPoint msp = wxGetMousePosition(); + wxPoint winp = m_parentPanel->GetScreenPosition(); + + return VECTOR2D( msp.x - winp.x, msp.y - winp.y ); +} + + +const VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const +{ + if( m_snappingEnabled ) + return m_view->GetGAL()->GetGridPoint( GetMousePosition() ); + else + return GetMousePosition(); +} + + bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) { VECTOR2D p( aEvent.GetX(), aEvent.GetY() ); diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index f5b7bacae0..cb3273f744 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -76,8 +76,6 @@ private: bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handlePopupMenu( wxEvent& aEvent ); - wxPoint getCurrentMousePos() const; - int decodeModifiers( const wxKeyboardState* aState ) const; struct ButtonState; diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 3b686d966c..ca539f467c 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -110,10 +110,7 @@ public: * * @return The current mouse pointer position. */ - virtual const VECTOR2D& GetMousePosition() const - { - return m_mousePosition; - } + virtual const VECTOR2D GetMousePosition() const = 0; /** * Function GetCursorPosition() @@ -122,21 +119,7 @@ public: * * @return The current cursor position in screen coordinates. */ - virtual const VECTOR2D& GetCursorPosition() const - { - return m_cursorPosition; - } - - /** - * Function SetCursorPosition() - * Allows to move the cursor to a different location. - * - * @param aPosition is the new location expressed in screen coordinates. - */ - virtual void SetCursorPosition( const VECTOR2D& aPosition ) - { - m_cursorPosition = aPosition; - } + virtual const VECTOR2D GetCursorPosition() const = 0; protected: /// Pointer to controlled VIEW. @@ -145,9 +128,6 @@ protected: /// Current mouse position VECTOR2D m_mousePosition; - /// Current cursor position - VECTOR2D m_cursorPosition; - /// Should the cursor snap to grid or move freely bool m_snappingEnabled; diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 7c905f2f9c..8562afbb82 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -78,6 +78,12 @@ public: m_state = IDLE; } + /// @copydoc VIEW_CONTROLS::GetMousePosition() + virtual const VECTOR2D GetMousePosition() const; + + /// @copydoc VIEW_CONTROLS::GetCursorPosition() + virtual const VECTOR2D GetCursorPosition() const; + private: /// Possible states for WX_VIEW_CONTROLS enum State {