[Scummvm-git-logs] scummvm master -> 6af7acd319c5749ac0fe5a94d49243b352426c75
OMGPizzaGuy
noreply at scummvm.org
Sun Jun 11 14:53:55 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
6af7acd319 ULTIMA8: Clean up mouse button event handling
Commit: 6af7acd319c5749ac0fe5a94d49243b352426c75
https://github.com/scummvm/scummvm/commit/6af7acd319c5749ac0fe5a94d49243b352426c75
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-06-11T09:53:38-05:00
Commit Message:
ULTIMA8: Clean up mouse button event handling
Changed paths:
engines/ultima/ultima8/kernel/mouse.cpp
engines/ultima/ultima8/kernel/mouse.h
engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp
diff --git a/engines/ultima/ultima8/kernel/mouse.cpp b/engines/ultima/ultima8/kernel/mouse.cpp
index c61ac1c403b..9accca97a55 100644
--- a/engines/ultima/ultima8/kernel/mouse.cpp
+++ b/engines/ultima/ultima8/kernel/mouse.cpp
@@ -54,9 +54,6 @@ Mouse::~Mouse() {
bool Mouse::buttonDown(MouseButton button) {
assert(button != MOUSE_LAST);
bool handled = false;
- uint32 now = g_system->getMillis();
- uint32 timeout = g_system->getDoubleClickTime();
- timeout = timeout > 0 ? timeout : DOUBLE_CLICK_TIMEOUT;
MButton &mbutton = _mouseButton[button];
@@ -69,11 +66,13 @@ bool Mouse::buttonDown(MouseButton button) {
mbutton._downGump = 0;
}
- mbutton._curDown = now;
+ mbutton._lastDown = mbutton._curDown;
+ mbutton._curDown = g_system->getMillis();
mbutton._downPoint = _mousePos;
mbutton.setState(MBS_DOWN);
mbutton.clearState(MBS_HANDLED);
+ uint32 timeout = getDoubleClickTime();
if (mbutton.isUnhandledDoubleClick(timeout)) {
if (_dragging == Mouse::DRAG_NOT) {
Gump *gump = getGump(mbutton._downGump);
@@ -87,7 +86,6 @@ bool Mouse::buttonDown(MouseButton button) {
mbutton._lastDown = 0;
}
}
- mbutton._lastDown = now;
return handled;
}
@@ -516,14 +514,18 @@ void Mouse::stopDragging(int mx, int my) {
popMouseCursor();
}
+uint32 Mouse::getDoubleClickTime() const {
+ uint32 timeout = g_system->getDoubleClickTime();
+ return timeout > 0 ? timeout : 400;
+}
+
void Mouse::handleDelayedEvents() {
uint32 now = g_system->getMillis();
- uint32 timeout = g_system->getDoubleClickTime();
- timeout = timeout > 0 ? timeout : DOUBLE_CLICK_TIMEOUT;
+ uint32 timeout = getDoubleClickTime();
for (int button = 0; button < MOUSE_LAST; ++button) {
- if (!(_mouseButton[button]._state & (MBS_HANDLED | MBS_DOWN)) &&
- !_mouseButton[button].lastWithinDblClkTimeout(now, timeout)) {
+ if (!_mouseButton[button].isState(MBS_DOWN) &&
+ _mouseButton[button].isUnhandledPastTimeout(now, timeout)) {
Gump *gump = getGump(_mouseButton[button]._downGump);
if (gump) {
int32 mx = _mouseButton[button]._downPoint.x;
diff --git a/engines/ultima/ultima8/kernel/mouse.h b/engines/ultima/ultima8/kernel/mouse.h
index f97a5855aae..6e2244b8584 100644
--- a/engines/ultima/ultima8/kernel/mouse.h
+++ b/engines/ultima/ultima8/kernel/mouse.h
@@ -30,8 +30,6 @@
namespace Ultima {
namespace Ultima8 {
-const unsigned int DOUBLE_CLICK_TIMEOUT = 300;
-
enum MouseButtonState {
MBS_DOWN = 0x1,
MBS_HANDLED = 0x2 // Mousedown event handled
@@ -58,18 +56,14 @@ struct MButton {
_state &= ~state;
}
- bool curWithinDblClkTimeout(uint32 now, uint32 timeout) {
- return now - _curDown <= timeout;
- }
-
- bool lastWithinDblClkTimeout(uint32 now, uint32 timeout) {
- return now - _lastDown <= timeout;
+ //! True if the current state is unhandled and past the double click timeout.
+ bool isUnhandledPastTimeout(uint32 now, uint32 timeout) {
+ return !isState(MBS_HANDLED) && _curDown > 0 && (now - _curDown) > timeout;
}
- //! A convenience function - true if the current state is down, unhandled, and within the double click timeout.
+ //! True if the current state is unhandled and within the double click timeout.
bool isUnhandledDoubleClick(uint32 timeout) {
- return isState(MBS_DOWN) && !isState(MBS_HANDLED) &&
- (_curDown - _lastDown) <= timeout;
+ return !isState(MBS_HANDLED) && _lastDown > 0 && (_curDown - _lastDown) <= timeout;
}
};
@@ -210,6 +204,8 @@ public:
y = _draggingOffset.y;
}
+ uint32 getDoubleClickTime() const;
+
void handleDelayedEvents();
Gump *getMouseOverGump() const;
diff --git a/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp b/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp
index 0e61a68c0e7..535c3bf0d8b 100644
--- a/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp
+++ b/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp
@@ -52,20 +52,17 @@ void U8AvatarMoverProcess::handleHangingMode() {
if (stasis)
return;
+ Mouse *mouse = Mouse::get_instance();
uint32 now = g_system->getMillis();
- uint32 timeout = g_system->getDoubleClickTime();
- timeout = timeout > 0 ? timeout : DOUBLE_CLICK_TIMEOUT;
-
- bool m0clicked = false;
- //bool m1clicked = false;
- if (!_mouseButton[0].isState(MBS_HANDLED) &&
- !_mouseButton[0].curWithinDblClkTimeout(now, timeout)) {
- m0clicked = true;
+ uint32 timeout = mouse->getDoubleClickTime();
+
+ bool m0unhandled = _mouseButton[0].isUnhandledPastTimeout(now, timeout);
+ if (m0unhandled) {
_mouseButton[0].setState(MBS_HANDLED);
}
- if (!_mouseButton[1].isState(MBS_HANDLED) &&
- !_mouseButton[1].curWithinDblClkTimeout(now, timeout)) {
- //m1clicked = true;
+
+ bool m1unhandled = _mouseButton[1].isUnhandledPastTimeout(now, timeout);
+ if (m1unhandled) {
_mouseButton[1].setState(MBS_HANDLED);
}
@@ -73,9 +70,8 @@ void U8AvatarMoverProcess::handleHangingMode() {
clearMovementFlag(MOVE_MOUSE_DIRECTION);
}
- // if left mouse is down, try to climb up
- if (_mouseButton[0].isState(MBS_DOWN) &&
- (!_mouseButton[0].isState(MBS_HANDLED) || m0clicked)) {
+ // if left mouse was clicked or down unhandled, try to climb up
+ if (!_mouseButton[0].isState(MBS_HANDLED) || m0unhandled) {
_mouseButton[0].setState(MBS_HANDLED);
_mouseButton[0]._lastDown = 0;
setMovementFlag(MOVE_JUMP);
@@ -121,21 +117,15 @@ void U8AvatarMoverProcess::handleCombatMode() {
return;
uint32 now = g_system->getMillis();
- uint32 timeout = g_system->getDoubleClickTime();
- timeout = timeout > 0 ? timeout : DOUBLE_CLICK_TIMEOUT;
-
- bool m0clicked = false;
- bool m1clicked = false;
+ uint32 timeout = mouse->getDoubleClickTime();
- if (!_mouseButton[0].isState(MBS_HANDLED) &&
- !_mouseButton[0].curWithinDblClkTimeout(now, timeout)) {
- m0clicked = true;
+ bool m0unhandled = _mouseButton[0].isUnhandledPastTimeout(now, timeout);
+ if (m0unhandled) {
_mouseButton[0].setState(MBS_HANDLED);
}
- if (!_mouseButton[1].isState(MBS_HANDLED) &&
- !_mouseButton[1].curWithinDblClkTimeout(now, timeout)) {
- m1clicked = true;
+ bool m1unhandled = _mouseButton[1].isUnhandledPastTimeout(now, timeout);
+ if (m1unhandled) {
_mouseButton[1].setState(MBS_HANDLED);
}
@@ -250,7 +240,7 @@ void U8AvatarMoverProcess::handleCombatMode() {
}
// if clicked, turn in mouse direction
- if (m0clicked || m1clicked)
+ if (m0unhandled || m1unhandled)
if (checkTurn(mousedir, false))
return;
@@ -365,22 +355,15 @@ void U8AvatarMoverProcess::handleNormalMode() {
}
uint32 now = g_system->getMillis();
- uint32 timeout = g_system->getDoubleClickTime();
- timeout = timeout > 0 ? timeout : DOUBLE_CLICK_TIMEOUT;
-
- bool m0clicked = false;
- bool m1clicked = false;
+ uint32 timeout = mouse->getDoubleClickTime();
- // check mouse state to see what needs to be done
- if (!_mouseButton[0].isState(MBS_HANDLED) &&
- !_mouseButton[0].curWithinDblClkTimeout(now, timeout)) {
- m0clicked = true;
+ bool m0unhandled = _mouseButton[0].isUnhandledPastTimeout(now, timeout);
+ if (m0unhandled) {
_mouseButton[0].setState(MBS_HANDLED);
}
- if (!_mouseButton[1].isState(MBS_HANDLED) &&
- !_mouseButton[1].curWithinDblClkTimeout(now, timeout)) {
- m1clicked = true;
+ bool m1unhandled = _mouseButton[1].isUnhandledPastTimeout(now, timeout);
+ if (m1unhandled) {
_mouseButton[1].setState(MBS_HANDLED);
}
@@ -451,7 +434,7 @@ void U8AvatarMoverProcess::handleNormalMode() {
}
}
- if ((!_mouseButton[0].isState(MBS_HANDLED) || m0clicked) && hasMovementFlags(MOVE_ANY_DIRECTION | MOVE_STEP)) {
+ if ((!_mouseButton[0].isState(MBS_HANDLED) || m0unhandled) && hasMovementFlags(MOVE_ANY_DIRECTION | MOVE_STEP)) {
_mouseButton[0].setState(MBS_HANDLED);
// We got a left mouse down while already moving in any direction or holding the step button.
// CHECKME: check what needs to happen when keeping left pressed
@@ -552,7 +535,7 @@ void U8AvatarMoverProcess::handleNormalMode() {
return;
}
- if (m1clicked)
+ if (m1unhandled)
if (checkTurn(mousedir, false))
return;
More information about the Scummvm-git-logs
mailing list