Collapsed MouseButton enum into just buttons, removing state (pressed or released).

- By itself, this first patch doesn't seem to accomplish much, but it leads into patch 2
 - Patch 2 will extend usage of MouseButton enum all throughout the GUI core
This commit is contained in:
Stephen Anthony 2017-12-29 16:05:07 -03:30
parent 1a89150d27
commit 542fed69ed
6 changed files with 65 additions and 69 deletions

View File

@ -67,15 +67,14 @@ void EventHandlerSDL2::pollEvent()
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
{ {
bool pressed = myEvent.button.type == SDL_MOUSEBUTTONDOWN;
switch(myEvent.button.button) switch(myEvent.button.button)
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
handleMouseButtonEvent(pressed ? MouseButton::LBUTTONDOWN : MouseButton::LBUTTONUP, handleMouseButtonEvent(MouseButton::LEFT, myEvent.button.type == SDL_MOUSEBUTTONDOWN,
myEvent.button.x, myEvent.button.y); myEvent.button.x, myEvent.button.y);
break; break;
case SDL_BUTTON_RIGHT: case SDL_BUTTON_RIGHT:
handleMouseButtonEvent(pressed ? MouseButton::RBUTTONDOWN : MouseButton::RBUTTONUP, handleMouseButtonEvent(MouseButton::RIGHT, myEvent.button.type == SDL_MOUSEBUTTONDOWN,
myEvent.button.x, myEvent.button.y); myEvent.button.x, myEvent.button.y);
break; break;
} }
@ -87,9 +86,9 @@ void EventHandlerSDL2::pollEvent()
int x, y; int x, y;
SDL_GetMouseState(&x, &y); // we need mouse position too SDL_GetMouseState(&x, &y); // we need mouse position too
if(myEvent.wheel.y < 0) if(myEvent.wheel.y < 0)
handleMouseButtonEvent(MouseButton::WHEELDOWN, x, y); handleMouseButtonEvent(MouseButton::WHEELDOWN, true, x, y);
else if(myEvent.wheel.y > 0) else if(myEvent.wheel.y > 0)
handleMouseButtonEvent(MouseButton::WHEELUP, x, y); handleMouseButtonEvent(MouseButton::WHEELUP, true, x, y);
break; break;
} }

View File

@ -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 // Determine which mode we're in, then send the event to the appropriate place
if(myState == EventHandlerState::EMULATION) if(myState == EventHandlerState::EMULATION)
{ {
switch(b) switch(b)
{ {
case MouseButton::LBUTTONDOWN: case MouseButton::LEFT:
myEvent.set(Event::MouseButtonLeftValue, 1); myEvent.set(Event::MouseButtonLeftValue, int(pressed));
break; break;
case MouseButton::LBUTTONUP: case MouseButton::RIGHT:
myEvent.set(Event::MouseButtonLeftValue, 0); myEvent.set(Event::MouseButtonRightValue, int(pressed));
break;
case MouseButton::RBUTTONDOWN:
myEvent.set(Event::MouseButtonRightValue, 1);
break;
case MouseButton::RBUTTONUP:
myEvent.set(Event::MouseButtonRightValue, 0);
break; break;
default: default:
return; return;
} }
} }
else if(myOverlay) else if(myOverlay)
myOverlay->handleMouseButtonEvent(b, x, y); myOverlay->handleMouseButtonEvent(b, pressed, x, y);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -305,7 +305,7 @@ class EventHandler
void handleTextEvent(char text); void handleTextEvent(char text);
void handleKeyEvent(StellaKey key, StellaMod mod, bool state); void handleKeyEvent(StellaKey key, StellaMod mod, bool state);
void handleMouseMotionEvent(int x, int y, int xrel, int yrel, int button); 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 handleJoyEvent(int stick, int button, uInt8 state);
void handleJoyAxisEvent(int stick, int axis, int value); void handleJoyAxisEvent(int stick, int axis, int value);
void handleJoyHatEvent(int stick, int hat, int value); void handleJoyHatEvent(int stick, int hat, int value);

View File

@ -31,10 +31,8 @@ enum class EventHandlerState {
}; };
enum class MouseButton { enum class MouseButton {
LBUTTONDOWN, LEFT,
LBUTTONUP, RIGHT,
RBUTTONDOWN,
RBUTTONUP,
WHEELDOWN, WHEELDOWN,
WHEELUP WHEELUP
}; };

View File

@ -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()) if(myDialogStack.empty())
return; return;
@ -205,57 +206,59 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y)
Dialog* activeDialog = myDialogStack.top(); Dialog* activeDialog = myDialogStack.top();
activeDialog->surface().translateCoords(x, y); activeDialog->surface().translateCoords(x, y);
int button = (b == MouseButton::LBUTTONDOWN || b == MouseButton::LBUTTONUP) ? 1 : 2; int button = b == MouseButton::LEFT ? 1 : 2;
switch(b) switch(b)
{ {
case MouseButton::LBUTTONDOWN: case MouseButton::LEFT:
case MouseButton::RBUTTONDOWN: case MouseButton::RIGHT:
// If more than two clicks have been recorded, we start over if(pressed)
if(myLastClick.count == 2)
{ {
myLastClick.x = myLastClick.y = 0; // If more than two clicks have been recorded, we start over
myLastClick.time = 0; if(myLastClick.count == 2)
myLastClick.count = 0; {
} myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0;
myLastClick.count = 0;
}
if(myLastClick.count && (myTime < myLastClick.time + kDoubleClickDelay) if(myLastClick.count && (myTime < myLastClick.time + kDoubleClickDelay)
&& std::abs(myLastClick.x - x) < 3 && std::abs(myLastClick.x - x) < 3
&& std::abs(myLastClick.y - y) < 3) && std::abs(myLastClick.y - y) < 3)
{ {
myLastClick.count++; 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 else
{ {
myLastClick.x = x; activeDialog->handleMouseUp(x - activeDialog->_x, y - activeDialog->_y,
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); button, myLastClick.count);
break;
case MouseButton::LBUTTONUP: if(button == myCurrentMouseDown.button)
case MouseButton::RBUTTONUP: myCurrentMouseDown.button = -1;
activeDialog->handleMouseUp(x - activeDialog->_x, y - activeDialog->_y, }
button, myLastClick.count);
if(button == myCurrentMouseDown.button)
myCurrentMouseDown.button = -1;
break; break;
case MouseButton::WHEELUP: case MouseButton::WHEELUP:

View File

@ -86,11 +86,12 @@ class DialogContainer
/** /**
Handle a mouse button event. Handle a mouse button event.
@param b The mouse button @param b The mouse button
@param x The x location @param pressed Whether the button was pressed (true) or released (false)
@param y The y location @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. Handle a joystick button event.