From e1d390f8a0e6cac1b53417e225151fce5f557ce4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 15 Jul 2014 17:34:53 +0200 Subject: [PATCH] Alternative way to handle mouse buttons (GAL). --- common/tool/tool_dispatcher.cpp | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index cd416f7c50..7166f6596d 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -85,6 +85,30 @@ struct TOOL_DISPATCHER::BUTTON_STATE dragging = false; pressed = false; } + + ///> Checks the current state of the button. + bool GetState() const + { + wxMouseState mouseState = wxGetMouseState(); + + switch( button ) + { + case BUT_LEFT: + return mouseState.LeftIsDown(); + + case BUT_MIDDLE: + return mouseState.MiddleIsDown(); + + case BUT_RIGHT: + return mouseState.RightIsDown(); + + default: + assert( false ); + break; + } + + return false; + } }; @@ -129,9 +153,21 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti boost::optional evt; bool isClick = false; - bool up = type == st->upEvent; - bool down = type == st->downEvent; +// bool up = type == st->upEvent; +// bool down = type == st->downEvent; + bool up = false, down = false; bool dblClick = type == st->dblClickEvent; + bool state = st->GetState(); + + if( !dblClick ) + { + // Sometimes the dispatcher does not receive mouse button up event, so it stays + // in the dragging mode even if the mouse button is not held anymore + if( st->pressed && !state ) + up = true; + else if( !st->pressed && state ) + down = true; + } int mods = decodeModifiers( static_cast( &aEvent ) ); int args = st->button | mods;