[Scummvm-git-logs] scummvm master -> 9449e177f49f3d41d55911b3cad3aa2ead2c3736
criezy
criezy at scummvm.org
Thu Aug 19 23:25:51 UTC 2021
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:
feac996b50 SDL: Move code to handle cursor coordinate HiDPI scale to SdlWindow
9449e177f4 SDL: Fix warping mouse on macOS HiDPI screens
Commit: feac996b50deea79985a4868489aeed677d94877
https://github.com/scummvm/scummvm/commit/feac996b50deea79985a4868489aeed677d94877
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-08-20T00:12:51+01:00
Commit Message:
SDL: Move code to handle cursor coordinate HiDPI scale to SdlWindow
SDL handles HiDPI scaling differently depending on the system. On
macOS for example the SDL window size and SDL drawable area have a
different size (factor 2 usually) while on Windows they are the
same. When HiDPI is disabled (for the SDL Surface mode for example)
they are always the same.
We need to appl this scaling when converting cursor position between
the drawable area and the SDL window.
Changed paths:
backends/graphics/sdl/sdl-graphics.cpp
backends/platform/sdl/sdl-window.cpp
backends/platform/sdl/sdl-window.h
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index a21cd6f708..8a55e63404 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -230,14 +230,7 @@ bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
// Currently on macOS we need to scale the events for HiDPI screen, but on
// Windows we do not. We can find out if we need to do it by querying the
// SDL window size vs the SDL drawable size.
- float dpiScale = 1.f;
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- int windowWidth, windowHeight;
- SDL_GetWindowSize(_window->getSDLWindow(), &windowWidth, &windowHeight);
- int realWidth, realHeight;
- SDL_GL_GetDrawableSize(_window->getSDLWindow(), &realWidth, &realHeight);
- dpiScale = (float)realWidth / (float)windowWidth;
-#endif
+ float dpiScale = _window->getSdlDpiScalingFactor();
mouse.x = (int)(mouse.x * dpiScale + 0.5f);
mouse.y = (int)(mouse.y * dpiScale + 0.5f);
bool valid = true;
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 2aee89ab84..11dd5db7c7 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -272,6 +272,17 @@ float SdlWindow::getDpiScalingFactor() const {
return ratio;
}
+float SdlWindow::getSdlDpiScalingFactor() const {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ int windowWidth, windowHeight;
+ SDL_GetWindowSize(getSDLWindow(), &windowWidth, &windowHeight);
+ int realWidth, realHeight;
+ SDL_GL_GetDrawableSize(getSDLWindow(), &realWidth, &realHeight);
+ return (float)realWidth / (float)windowWidth;
+#else
+ return 1.f;
+#endif
+}
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Surface *copySDLSurface(SDL_Surface *src) {
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
index abab0b57a4..7006d82029 100644
--- a/backends/platform/sdl/sdl-window.h
+++ b/backends/platform/sdl/sdl-window.h
@@ -87,7 +87,17 @@ public:
*/
Common::Rect getDesktopResolution();
- void getDisplayDpi(float *dpi, float *defaultDpi) const;
+ /*
+ * Get the scaling between the SDL Window size and the SDL
+ * drawable area size. On some system, when HiDPI support is
+ * enabled, those two sizes are different.
+ *
+ * To convert from window coordinate to drawable area coordinate,
+ * multiple the coordinate by this scaling factor. To convert
+ * from drawable area coordinate to window coordinate, divide the
+ * coordinate by this scaling factor.
+ */
+ float getSdlDpiScalingFactor() const;
/**
* Returns the scaling mode based on the display DPI
@@ -115,6 +125,9 @@ private:
Common::Rect _desktopRes;
bool _inputGrabState, _inputLockState;
+protected:
+ void getDisplayDpi(float *dpi, float *defaultDpi) const;
+
#if SDL_VERSION_ATLEAST(2, 0, 0)
public:
/**
Commit: 9449e177f49f3d41d55911b3cad3aa2ead2c3736
https://github.com/scummvm/scummvm/commit/9449e177f49f3d41d55911b3cad3aa2ead2c3736
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-08-20T00:16:03+01:00
Commit Message:
SDL: Fix warping mouse on macOS HiDPI screens
This fixes bug #12822.
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 11dd5db7c7..e94211b9cd 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -197,6 +197,9 @@ bool SdlWindow::warpMouseInWindow(int x, int y) {
if (hasMouseFocus()) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {
+ float dpiScale = getSdlDpiScalingFactor();
+ x = (int)(x / dpiScale + 0.5f);
+ y = (int)(y / dpiScale + 0.5f);
SDL_WarpMouseInWindow(_window, x, y);
return true;
}
More information about the Scummvm-git-logs
mailing list