added middle mouse button support (emulates double click)

This commit is contained in:
Thomas Jentzsch 2022-12-06 19:21:07 +01:00
parent dcc3eebab1
commit 43a67ef224
3 changed files with 17 additions and 5 deletions

View File

@ -124,19 +124,23 @@ void EventHandlerSDL2::pollEvent()
case SDL_MOUSEBUTTONUP:
{
// ToDo: check support of more buttons and double-click
MouseButton b{MouseButton::NONE};
switch(myEvent.button.button)
{
case SDL_BUTTON_LEFT:
handleMouseButtonEvent(MouseButton::LEFT, myEvent.button.type == SDL_MOUSEBUTTONDOWN,
myEvent.button.x, myEvent.button.y);
b = MouseButton::LEFT;
break;
case SDL_BUTTON_RIGHT:
handleMouseButtonEvent(MouseButton::RIGHT, myEvent.button.type == SDL_MOUSEBUTTONDOWN,
myEvent.button.x, myEvent.button.y);
b = MouseButton::RIGHT;
break;
case SDL_BUTTON_MIDDLE:
b = MouseButton::MIDDLE;
break;
default:
break;
}
handleMouseButtonEvent(b, myEvent.button.type == SDL_MOUSEBUTTONDOWN,
myEvent.button.x, myEvent.button.y);
break;
}

View File

@ -37,6 +37,7 @@ enum class EventHandlerState {
enum class MouseButton {
LEFT,
RIGHT,
MIDDLE,
WHEELDOWN,
WHEELUP,
NONE

View File

@ -256,6 +256,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed,
{
case MouseButton::LEFT:
case MouseButton::RIGHT:
case MouseButton::MIDDLE:
if(pressed)
{
// If more than two clicks have been recorded, we start over
@ -266,7 +267,13 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed,
myLastClick.count = 0;
}
if(myLastClick.count && (myTime < myLastClick.time + _DOUBLE_CLICK_DELAY)
if(b == MouseButton::MIDDLE)
{
// Middle mouse button emulates lef mouse button double click
myLastClick.count = 2;
b = MouseButton::LEFT;
}
else if(myLastClick.count && (myTime < myLastClick.time + _DOUBLE_CLICK_DELAY)
&& std::abs(myLastClick.x - x) < 3
&& std::abs(myLastClick.y - y) < 3)
{