TOOL_DISPATCHER: improve mouse handling

parent 6ac8188f
...@@ -55,6 +55,8 @@ struct TOOL_DISPATCHER::ButtonState ...@@ -55,6 +55,8 @@ struct TOOL_DISPATCHER::ButtonState
bool pressed; bool pressed;
VECTOR2D dragOrigin; VECTOR2D dragOrigin;
VECTOR2D downPosition;
double dragMaxDelta; double dragMaxDelta;
TOOL_MouseButtons button; TOOL_MouseButtons button;
...@@ -117,13 +119,21 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const ...@@ -117,13 +119,21 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const
return mods; 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 ) bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion )
{ {
ButtonState* st = m_buttons[aIndex]; ButtonState* st = m_buttons[aIndex];
wxEventType type = aEvent.GetEventType(); wxEventType type = aEvent.GetEventType();
optional<TOOL_EVENT> evt; optional<TOOL_EVENT> evt;
bool isClick = false;
bool up = type == st->upEvent; bool up = type == st->upEvent;
bool down = type == st->downEvent; bool down = type == st->downEvent;
...@@ -134,20 +144,20 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti ...@@ -134,20 +144,20 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
{ {
st->downTimestamp = wxGetLocalTimeMillis(); st->downTimestamp = wxGetLocalTimeMillis();
st->dragOrigin = m_lastMousePos; st->dragOrigin = m_lastMousePos;
st->downPosition = m_lastMousePos;
st->dragMaxDelta = 0; st->dragMaxDelta = 0;
st->pressed = true; st->pressed = true;
evt = TOOL_EVENT( TC_Mouse, TA_MouseDown, args ); evt = TOOL_EVENT( TC_Mouse, TA_MouseDown, args );
} }
else if( up ) else if( up )
{ {
bool isClick = false;
st->pressed = false; st->pressed = false;
if( st->dragging ) if( st->dragging )
{ {
wxLongLong t = wxGetLocalTimeMillis(); wxLongLong t = wxGetLocalTimeMillis();
if( t - st->downTimestamp < DragTimeThreshold && if( t - st->downTimestamp < DragTimeThreshold ||
st->dragMaxDelta < DragDistanceThreshold ) st->dragMaxDelta < DragDistanceThreshold )
isClick = true; isClick = true;
else else
...@@ -158,13 +168,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti ...@@ -158,13 +168,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
if( isClick ) if( isClick )
{ evt = TOOL_EVENT( TC_Mouse, TA_MouseClick, args );
if( st->triggerContextMenu && !mods )
{}
// evt = TOOL_EVENT( TC_Command, TA_ContextMenu );
else
evt = TOOL_EVENT( TC_Mouse, TA_MouseClick, args );
}
st->dragging = false; st->dragging = false;
} }
...@@ -177,7 +181,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti ...@@ -177,7 +181,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
wxLongLong t = wxGetLocalTimeMillis(); 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 = TOOL_EVENT( TC_Mouse, TA_MouseDrag, args );
evt->SetMouseDragOrigin( st->dragOrigin ); evt->SetMouseDragOrigin( st->dragOrigin );
...@@ -187,7 +191,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti ...@@ -187,7 +191,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
if( evt ) if( evt )
{ {
evt->SetMousePosition( m_lastMousePos ); evt->SetMousePosition( isClick ? st->downPosition : m_lastMousePos );
m_toolMgr->ProcessEvent( *evt ); m_toolMgr->ProcessEvent( *evt );
return true; return true;
...@@ -212,7 +216,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) ...@@ -212,7 +216,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ) type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP )
{ {
wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent ); wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
pos = getView()->ToWorld( VECTOR2D( me->GetX(), me->GetY() ) );
pos = getView()->ToWorld ( getCurrentMousePos() );
if( pos != m_lastMousePos ) if( pos != m_lastMousePos )
{ {
motion = true; motion = true;
......
...@@ -73,6 +73,8 @@ private: ...@@ -73,6 +73,8 @@ private:
bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
bool handlePopupMenu( wxEvent& aEvent ); bool handlePopupMenu( wxEvent& aEvent );
wxPoint getCurrentMousePos();
int decodeModifiers( const wxKeyboardState* aState ) const; int decodeModifiers( const wxKeyboardState* aState ) const;
struct ButtonState; struct ButtonState;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment