[Scummvm-git-logs] scummvm master -> fa004835b313224f64e26e39dabbead6529c85ae

sev- noreply at scummvm.org
Wed Aug 9 16:51:46 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:
fa004835b3 GUI: Improve time difference checks in gui manager


Commit: fa004835b313224f64e26e39dabbead6529c85ae
    https://github.com/scummvm/scummvm/commit/fa004835b313224f64e26e39dabbead6529c85ae
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2023-08-09T18:51:42+02:00

Commit Message:
GUI: Improve time difference checks in gui manager

Basically using unsigned integer difference to address potential errors around the overflow point of getMillis()

Changed paths:
    gui/gui-manager.cpp
    gui/gui-manager.h


diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index 1398b633f34..30a22e358ad 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -539,11 +539,11 @@ void GuiManager::runLoop() {
 		//    then delay showing the tooltip based on the value of kTooltipSameWidgetDelay.
 		uint32 systemMillisNowForTooltipCheck = _system->getMillis(true);
 		if ((_lastTooltipShown.x != _lastMousePosition.x || _lastTooltipShown.y != _lastMousePosition.y)
-		    && _lastMousePosition.time + kTooltipDelay < systemMillisNowForTooltipCheck
+		    && systemMillisNowForTooltipCheck - _lastMousePosition.time > (uint32)kTooltipDelay
 		    && !activeDialog->isDragging()) {
 			Widget *wdg = activeDialog->findWidget(_lastMousePosition.x, _lastMousePosition.y);
 			if (wdg && wdg->hasTooltip() && !(wdg->getFlags() & WIDGET_PRESSED)
-			    && (_lastTooltipShown.wdg != wdg || _lastTooltipShown.time + kTooltipSameWidgetDelay < systemMillisNowForTooltipCheck)) {
+			    && (_lastTooltipShown.wdg != wdg || systemMillisNowForTooltipCheck - _lastTooltipShown.time > (uint32)kTooltipSameWidgetDelay)) {
 				_lastTooltipShown.time = systemMillisNowForTooltipCheck;
 				_lastTooltipShown.wdg  = wdg;
 				_lastTooltipShown.x = _lastMousePosition.x;
@@ -683,8 +683,8 @@ void GuiManager::setupCursor() {
 // very much. We could plug in a different cursor here if we like to.
 
 void GuiManager::animateCursor() {
-	int time = _system->getMillis(true);
-	if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
+	uint32 time = _system->getMillis(true);
+	if (time - _cursorAnimateTimer > (uint32)kCursorAnimateDelay) {
 		for (int i = 0; i < 15; i++) {
 			if ((i < 6) || (i > 8)) {
 				_cursor[16 * 7 + i] = _cursorAnimateCounter;
@@ -774,10 +774,10 @@ void GuiManager::processEvent(const Common::Event &event, Dialog *const activeDi
 	case Common::EVENT_RBUTTONDOWN:
 		button = (event.type == Common::EVENT_LBUTTONDOWN ? 1 : 2);
 		time = _system->getMillis(true);
-		if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
-			&& ABS(_lastClick.x - event.mouse.x) < 3
-			&& ABS(_lastClick.y - event.mouse.y) < 3) {
-				_lastClick.count++;
+		if (_lastClick.count && (time - _lastClick.time < (uint32)kDoubleClickDelay)
+		    && ABS(_lastClick.x - event.mouse.x) < 3
+		    && ABS(_lastClick.y - event.mouse.y) < 3) {
+			_lastClick.count++;
 		} else {
 			_lastClick.x = event.mouse.x;
 			_lastClick.y = event.mouse.y;
diff --git a/gui/gui-manager.h b/gui/gui-manager.h
index af5745273e3..92538379d38 100644
--- a/gui/gui-manager.h
+++ b/gui/gui-manager.h
@@ -194,8 +194,8 @@ protected:
 	} _lastTooltipShown;
 
 	// mouse cursor state
-	int		_cursorAnimateCounter;
-	int		_cursorAnimateTimer;
+	uint32	_cursorAnimateCounter;
+	uint32	_cursorAnimateTimer;
 	byte	_cursor[2048];
 
 	// delayed deletion of GuiObject




More information about the Scummvm-git-logs mailing list