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: case SDL_MOUSEBUTTONUP:
{ {
// ToDo: check support of more buttons and double-click // ToDo: check support of more buttons and double-click
MouseButton b{MouseButton::NONE};
switch(myEvent.button.button) switch(myEvent.button.button)
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
handleMouseButtonEvent(MouseButton::LEFT, myEvent.button.type == SDL_MOUSEBUTTONDOWN, b = MouseButton::LEFT;
myEvent.button.x, myEvent.button.y);
break; break;
case SDL_BUTTON_RIGHT: case SDL_BUTTON_RIGHT:
handleMouseButtonEvent(MouseButton::RIGHT, myEvent.button.type == SDL_MOUSEBUTTONDOWN, b = MouseButton::RIGHT;
myEvent.button.x, myEvent.button.y); break;
case SDL_BUTTON_MIDDLE:
b = MouseButton::MIDDLE;
break; break;
default: default:
break; break;
} }
handleMouseButtonEvent(b, myEvent.button.type == SDL_MOUSEBUTTONDOWN,
myEvent.button.x, myEvent.button.y);
break; break;
} }

View File

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

View File

@ -256,6 +256,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed,
{ {
case MouseButton::LEFT: case MouseButton::LEFT:
case MouseButton::RIGHT: case MouseButton::RIGHT:
case MouseButton::MIDDLE:
if(pressed) if(pressed)
{ {
// If more than two clicks have been recorded, we start over // 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; 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.x - x) < 3
&& std::abs(myLastClick.y - y) < 3) && std::abs(myLastClick.y - y) < 3)
{ {