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_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;
}

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
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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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);

View File

@ -31,10 +31,8 @@ enum class EventHandlerState {
};
enum class MouseButton {
LBUTTONDOWN,
LBUTTONUP,
RBUTTONDOWN,
RBUTTONUP,
LEFT,
RIGHT,
WHEELDOWN,
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())
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:

View File

@ -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.