diff --git a/src/common/EventHandlerSDL2.cxx b/src/common/EventHandlerSDL2.cxx index 0c5a38881..88b39020b 100644 --- a/src/common/EventHandlerSDL2.cxx +++ b/src/common/EventHandlerSDL2.cxx @@ -67,15 +67,14 @@ void EventHandlerSDL2::pollEvent() case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { - bool pressed = myEvent.button.type == SDL_MOUSEBUTTONDOWN; switch(myEvent.button.button) { case SDL_BUTTON_LEFT: - handleMouseButtonEvent(pressed ? MouseButton::LBUTTONDOWN : MouseButton::LBUTTONUP, + handleMouseButtonEvent(MouseButton::LEFT, myEvent.button.type == SDL_MOUSEBUTTONDOWN, myEvent.button.x, myEvent.button.y); break; case SDL_BUTTON_RIGHT: - handleMouseButtonEvent(pressed ? MouseButton::RBUTTONDOWN : MouseButton::RBUTTONUP, + handleMouseButtonEvent(MouseButton::RIGHT, myEvent.button.type == SDL_MOUSEBUTTONDOWN, myEvent.button.x, myEvent.button.y); break; } @@ -87,9 +86,9 @@ void EventHandlerSDL2::pollEvent() int x, y; SDL_GetMouseState(&x, &y); // we need mouse position too if(myEvent.wheel.y < 0) - handleMouseButtonEvent(MouseButton::WHEELDOWN, x, y); + handleMouseButtonEvent(MouseButton::WHEELDOWN, true, x, y); else if(myEvent.wheel.y > 0) - handleMouseButtonEvent(MouseButton::WHEELUP, x, y); + handleMouseButtonEvent(MouseButton::WHEELUP, true, x, y); break; } diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 019818b42..93ba77928 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -665,31 +665,26 @@ void EventHandler::handleMouseMotionEvent(int x, int y, int xrel, int yrel, int } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EventHandler::handleMouseButtonEvent(MouseButton b, int x, int y) +void EventHandler::handleMouseButtonEvent(MouseButton b, bool pressed, + int x, int y) { // Determine which mode we're in, then send the event to the appropriate place if(myState == EventHandlerState::EMULATION) { switch(b) { - case MouseButton::LBUTTONDOWN: - myEvent.set(Event::MouseButtonLeftValue, 1); + case MouseButton::LEFT: + myEvent.set(Event::MouseButtonLeftValue, int(pressed)); break; - case MouseButton::LBUTTONUP: - myEvent.set(Event::MouseButtonLeftValue, 0); - break; - case MouseButton::RBUTTONDOWN: - myEvent.set(Event::MouseButtonRightValue, 1); - break; - case MouseButton::RBUTTONUP: - myEvent.set(Event::MouseButtonRightValue, 0); + case MouseButton::RIGHT: + myEvent.set(Event::MouseButtonRightValue, int(pressed)); break; default: return; } } else if(myOverlay) - myOverlay->handleMouseButtonEvent(b, x, y); + myOverlay->handleMouseButtonEvent(b, pressed, x, y); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 33363f5e4..c77804cf7 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -305,7 +305,7 @@ class EventHandler void handleTextEvent(char text); void handleKeyEvent(StellaKey key, StellaMod mod, bool state); void handleMouseMotionEvent(int x, int y, int xrel, int yrel, int button); - void handleMouseButtonEvent(MouseButton b, int x, int y); + void handleMouseButtonEvent(MouseButton b, bool pressed, int x, int y); void handleJoyEvent(int stick, int button, uInt8 state); void handleJoyAxisEvent(int stick, int axis, int value); void handleJoyHatEvent(int stick, int hat, int value); diff --git a/src/emucore/EventHandlerConstants.hxx b/src/emucore/EventHandlerConstants.hxx index 7b799a33b..b4ab67aa3 100644 --- a/src/emucore/EventHandlerConstants.hxx +++ b/src/emucore/EventHandlerConstants.hxx @@ -31,10 +31,8 @@ enum class EventHandlerState { }; enum class MouseButton { - LBUTTONDOWN, - LBUTTONUP, - RBUTTONDOWN, - RBUTTONUP, + LEFT, + RIGHT, WHEELDOWN, WHEELUP }; diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index f9042b5f5..0cf962ddd 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -196,7 +196,8 @@ void DialogContainer::handleMouseMotionEvent(int x, int y, int button) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y) +void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed, + int x, int y) { if(myDialogStack.empty()) return; @@ -205,57 +206,59 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y) Dialog* activeDialog = myDialogStack.top(); activeDialog->surface().translateCoords(x, y); - int button = (b == MouseButton::LBUTTONDOWN || b == MouseButton::LBUTTONUP) ? 1 : 2; + int button = b == MouseButton::LEFT ? 1 : 2; switch(b) { - case MouseButton::LBUTTONDOWN: - case MouseButton::RBUTTONDOWN: - // If more than two clicks have been recorded, we start over - if(myLastClick.count == 2) + case MouseButton::LEFT: + case MouseButton::RIGHT: + if(pressed) { - myLastClick.x = myLastClick.y = 0; - myLastClick.time = 0; - myLastClick.count = 0; - } + // If more than two clicks have been recorded, we start over + if(myLastClick.count == 2) + { + myLastClick.x = myLastClick.y = 0; + myLastClick.time = 0; + myLastClick.count = 0; + } - if(myLastClick.count && (myTime < myLastClick.time + kDoubleClickDelay) - && std::abs(myLastClick.x - x) < 3 - && std::abs(myLastClick.y - y) < 3) - { - myLastClick.count++; + if(myLastClick.count && (myTime < myLastClick.time + kDoubleClickDelay) + && std::abs(myLastClick.x - x) < 3 + && std::abs(myLastClick.y - y) < 3) + { + myLastClick.count++; + } + else + { + myLastClick.x = x; + myLastClick.y = y; + myLastClick.count = 1; + } + myLastClick.time = myTime; + + // Now account for repeated mouse events (click and hold), but only + // if the dialog wants them + if(activeDialog->handleMouseClicks(x - activeDialog->_x, y - activeDialog->_y, + button)) + { + myCurrentMouseDown.x = x; + myCurrentMouseDown.y = y; + myCurrentMouseDown.button = button; + myClickRepeatTime = myTime + kRepeatInitialDelay; + } + else + myCurrentMouseDown.button = -1; + + activeDialog->handleMouseDown(x - activeDialog->_x, y - activeDialog->_y, + button, myLastClick.count); } else { - myLastClick.x = x; - myLastClick.y = y; - myLastClick.count = 1; - } - myLastClick.time = myTime; - - // Now account for repeated mouse events (click and hold), but only - // if the dialog wants them - if(activeDialog->handleMouseClicks(x - activeDialog->_x, y - activeDialog->_y, - button)) - { - myCurrentMouseDown.x = x; - myCurrentMouseDown.y = y; - myCurrentMouseDown.button = button; - myClickRepeatTime = myTime + kRepeatInitialDelay; - } - else - myCurrentMouseDown.button = -1; - - activeDialog->handleMouseDown(x - activeDialog->_x, y - activeDialog->_y, + activeDialog->handleMouseUp(x - activeDialog->_x, y - activeDialog->_y, button, myLastClick.count); - break; - case MouseButton::LBUTTONUP: - case MouseButton::RBUTTONUP: - activeDialog->handleMouseUp(x - activeDialog->_x, y - activeDialog->_y, - button, myLastClick.count); - - if(button == myCurrentMouseDown.button) - myCurrentMouseDown.button = -1; + if(button == myCurrentMouseDown.button) + myCurrentMouseDown.button = -1; + } break; case MouseButton::WHEELUP: diff --git a/src/gui/DialogContainer.hxx b/src/gui/DialogContainer.hxx index 6a6fa4fdd..f806cb43a 100644 --- a/src/gui/DialogContainer.hxx +++ b/src/gui/DialogContainer.hxx @@ -86,11 +86,12 @@ class DialogContainer /** Handle a mouse button event. - @param b The mouse button - @param x The x location - @param y The y location + @param b The mouse button + @param pressed Whether the button was pressed (true) or released (false) + @param x The x location + @param y The y location */ - void handleMouseButtonEvent(MouseButton b, int x, int y); + void handleMouseButtonEvent(MouseButton b, bool pressed, int x, int y); /** Handle a joystick button event.