diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 89da297fa9..2bc544f686 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -55,6 +55,8 @@ struct TOOL_DISPATCHER::ButtonState bool pressed; VECTOR2D dragOrigin; + VECTOR2D downPosition; + double dragMaxDelta; TOOL_MouseButtons button; @@ -117,13 +119,21 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const return mods; } +wxPoint TOOL_DISPATCHER::getCurrentMousePos() +{ + 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]; wxEventType type = aEvent.GetEventType(); optional evt; - + bool isClick = false; + bool up = type == st->upEvent; bool down = type == st->downEvent; @@ -134,20 +144,20 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti { st->downTimestamp = wxGetLocalTimeMillis(); st->dragOrigin = m_lastMousePos; + st->downPosition = m_lastMousePos; st->dragMaxDelta = 0; st->pressed = true; evt = TOOL_EVENT( TC_Mouse, TA_MouseDown, args ); } else if( up ) { - bool isClick = false; st->pressed = false; if( st->dragging ) { wxLongLong t = wxGetLocalTimeMillis(); - if( t - st->downTimestamp < DragTimeThreshold && + if( t - st->downTimestamp < DragTimeThreshold || st->dragMaxDelta < DragDistanceThreshold ) isClick = true; else @@ -158,13 +168,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti if( isClick ) - { - if( st->triggerContextMenu && !mods ) - {} - // evt = TOOL_EVENT( TC_Command, TA_ContextMenu ); - else - evt = TOOL_EVENT( TC_Mouse, TA_MouseClick, args ); - } + evt = TOOL_EVENT( TC_Mouse, TA_MouseClick, args ); st->dragging = false; } @@ -177,7 +181,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti wxLongLong t = wxGetLocalTimeMillis(); - if( t - st->downTimestamp > DragTimeThreshold || st->dragMaxDelta > DragDistanceThreshold ) + if( t - st->downTimestamp > DragTimeThreshold && st->dragMaxDelta > DragDistanceThreshold ) { evt = TOOL_EVENT( TC_Mouse, TA_MouseDrag, args ); evt->SetMouseDragOrigin( st->dragOrigin ); @@ -187,7 +191,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti if( evt ) { - evt->SetMousePosition( m_lastMousePos ); + evt->SetMousePosition( isClick ? st->downPosition : m_lastMousePos ); m_toolMgr->ProcessEvent( *evt ); return true; @@ -212,7 +216,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ) { wxMouseEvent* me = static_cast( &aEvent ); - pos = getView()->ToWorld( VECTOR2D( me->GetX(), me->GetY() ) ); + + + pos = getView()->ToWorld ( getCurrentMousePos() ); if( pos != m_lastMousePos ) { motion = true; diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index 8072274dfe..1222291123 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -73,6 +73,8 @@ private: bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handlePopupMenu( wxEvent& aEvent ); + wxPoint getCurrentMousePos(); + int decodeModifiers( const wxKeyboardState* aState ) const; struct ButtonState;