[Scummvm-git-logs] scummvm master -> 31cfac5d6f2daf532481010582abbebd096d149a

criezy noreply at scummvm.org
Wed Feb 16 22:15:47 UTC 2022


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ca2405ed05 SDL: Fix mouse clip to game area in HiDPI mode
31cfac5d6f SDL: Fix SDL_SetWindowMouseRect in HiDPI mode


Commit: ca2405ed05e303b876d8a80ae8137656d0dae920
    https://github.com/scummvm/scummvm/commit/ca2405ed05e303b876d8a80ae8137656d0dae920
Author: Kalle Kietavainen (1026741+kalkie at users.noreply.github.com)
Date: 2022-02-16T22:15:43Z

Commit Message:
SDL: Fix mouse clip to game area in HiDPI mode

The mouse position is set in window coordinates, but it's clipped to the
game area in drawable area coordinates. Previously, the scaling between
these two was not taken into account when calculating the right/bottom
edges of the game area. When the clipped mouse position was converted
back to window coordinates and rounded to the nearest integer, it could
end up on the edge of the game area, not inside of it. This leads to a
loop in which the clipped mouse position is outside of the game area and
needs to be clipped again.

This fixes bug #12646.

Changed paths:
    backends/graphics/sdl/sdl-graphics.cpp


diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index bd02b6149f1..dca66c26c9d 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -221,8 +221,14 @@ bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
 	if (_activeArea.drawRect.contains(mouse)) {
 		_cursorLastInActiveArea = true;
 	} else {
-		mouse.x = CLIP<int>(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right - 1);
-		mouse.y = CLIP<int>(mouse.y, _activeArea.drawRect.top, _activeArea.drawRect.bottom - 1);
+		// The right/bottom edges are not part of the drawRect. As the clipping
+		// is done in drawable area coordinates, but the mouse position is set
+		// in window coordinates, we need to subtract as many pixels from the
+		// edges as corresponds to one pixel in the window coordinates.
+		mouse.x = CLIP<int>(mouse.x, _activeArea.drawRect.left,
+							_activeArea.drawRect.right - (int)(1 * dpiScale + 0.5f));
+		mouse.y = CLIP<int>(mouse.y, _activeArea.drawRect.top,
+							_activeArea.drawRect.bottom - (int)(1 * dpiScale + 0.5f));
 
 		if (_window->mouseIsGrabbed() ||
 			// Keep the mouse inside the game area during dragging to prevent an


Commit: 31cfac5d6f2daf532481010582abbebd096d149a
    https://github.com/scummvm/scummvm/commit/31cfac5d6f2daf532481010582abbebd096d149a
Author: Kalle Kietavainen (1026741+kalkie at users.noreply.github.com)
Date: 2022-02-16T22:15:43Z

Commit Message:
SDL: Fix SDL_SetWindowMouseRect in HiDPI mode

In HiDPI mode, the window coordinates and the drawable area coordinates
might be on a different scale. The allowed mouse area needs to be scaled
accordingly before passing it to SDL_SetWindowMouseRect().

This fixes bug #13152.

Changed paths:
    backends/platform/sdl/sdl-window.cpp


diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index d156a16a141..2dbab9027ae 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -168,10 +168,11 @@ void SdlWindow::grabMouse(bool grab) {
 }
 
 void SdlWindow::setMouseRect(const Common::Rect &rect) {
-	grabRect.x = rect.left;
-	grabRect.y = rect.top;
-	grabRect.w = rect.width();
-	grabRect.h = rect.height();
+	float dpiScale = getSdlDpiScalingFactor();
+	grabRect.x = (int)(rect.left / dpiScale + 0.5f);
+	grabRect.y = (int)(rect.top / dpiScale + 0.5f);
+	grabRect.w = (int)(rect.width() / dpiScale + 0.5f);
+	grabRect.h = (int)(rect.height() / dpiScale + 0.5f);
 
 #if SDL_VERSION_ATLEAST(2, 0, 18)
 	if (_inputGrabState || _lastFlags & fullscreenMask) {




More information about the Scummvm-git-logs mailing list