[Scummvm-git-logs] scummvm master -> 350e21ba582362a335ca8dd3df43f077898b5dfd
ccawley2011
noreply at scummvm.org
Fri Aug 26 20:47:52 UTC 2022
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:
350e21ba58 SDL: Better workaround for enabling the system cursor
Commit: 350e21ba582362a335ca8dd3df43f077898b5dfd
https://github.com/scummvm/scummvm/commit/350e21ba582362a335ca8dd3df43f077898b5dfd
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2022-08-26T21:47:49+01:00
Commit Message:
SDL: Better workaround for enabling the system cursor
Changed paths:
backends/graphics/openpandora/op-graphics.cpp
backends/graphics/openpandora/op-graphics.h
backends/graphics/sdl/sdl-graphics.cpp
backends/graphics/sdl/sdl-graphics.h
backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
backends/graphics3d/openglsdl/openglsdl-graphics3d.h
diff --git a/backends/graphics/openpandora/op-graphics.cpp b/backends/graphics/openpandora/op-graphics.cpp
index 0ddc7315f43..05acabeb020 100644
--- a/backends/graphics/openpandora/op-graphics.cpp
+++ b/backends/graphics/openpandora/op-graphics.cpp
@@ -66,83 +66,7 @@ void OPGraphicsManager::unloadGFXMode() {
SurfaceSdlGraphicsManager::unloadGFXMode();
}
-bool OPGraphicsManager::showMouse(bool visible) {
- if (visible == _cursorVisible) {
- return visible;
- }
-
- int showCursor = SDL_DISABLE;
- if (visible) {
- // _cursorX and _cursorY are currently always clipped to the active
- // area, so we need to ask SDL where the system's mouse cursor is
- // instead
- int x, y;
- SDL_GetMouseState(&x, &y);
- if (!_activeArea.drawRect.contains(Common::Point(x, y))) {
- showCursor = SDL_ENABLE;
- }
- }
- //SDL_ShowCursor(showCursor);
-
- return WindowedGraphicsManager::showMouse(visible);
-}
-
-bool OPGraphicsManager::notifyMousePosition(Common::Point &mouse) {
- mouse.x = CLIP<int16>(mouse.x, 0, _windowWidth - 1);
- mouse.y = CLIP<int16>(mouse.y, 0, _windowHeight - 1);
-
- int showCursor = SDL_DISABLE;
- // 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 = _window->getSdlDpiScalingFactor();
- mouse.x = (int)(mouse.x * dpiScale + 0.5f);
- mouse.y = (int)(mouse.y * dpiScale + 0.5f);
- bool valid = true;
- if (_activeArea.drawRect.contains(mouse)) {
- _cursorLastInActiveArea = true;
- } else {
- // 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
- // event mismatch where the mouseup event gets lost because it is
- // performed outside of the game area
- (_cursorLastInActiveArea && SDL_GetMouseState(nullptr, nullptr) != 0)) {
- setSystemMousePosition(mouse.x, mouse.y);
- } else {
- // Allow the in-game mouse to get a final movement event to the edge
- // of the window if the mouse was moved out of the game area
- if (_cursorLastInActiveArea) {
- _cursorLastInActiveArea = false;
- } else if (_cursorVisible) {
- // Keep sending events to the game if the cursor is invisible,
- // since otherwise if a game lets you skip a cutscene by
- // clicking and the user moved the mouse outside the active
- // area, the clicks wouldn't do anything, which would be
- // confusing
- valid = false;
- }
-
- if (_cursorVisible) {
- showCursor = SDL_ENABLE;
- }
- }
- }
-
- //SDL_ShowCursor(showCursor);
- if (valid) {
- setMousePosition(mouse.x, mouse.y);
- mouse = convertWindowToVirtual(mouse.x, mouse.y);
- }
- return valid;
+void OPGraphicsManager::showSystemMouseCursor(bool visible) {
}
#endif
diff --git a/backends/graphics/openpandora/op-graphics.h b/backends/graphics/openpandora/op-graphics.h
index 1362c2e2806..12fe97829ce 100644
--- a/backends/graphics/openpandora/op-graphics.h
+++ b/backends/graphics/openpandora/op-graphics.h
@@ -31,8 +31,7 @@ public:
bool loadGFXMode() override;
void unloadGFXMode() override;
- bool showMouse(bool visible) override;
- bool notifyMousePosition(Common::Point &mouse);
+ void showSystemMouseCursor(bool visible) override;
};
#endif /* BACKENDS_GRAPHICS_OP_H */
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 92c925ee301..4d57559b36e 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -186,7 +186,7 @@ bool SdlGraphicsManager::showMouse(bool visible) {
return visible;
}
- int showCursor = SDL_DISABLE;
+ bool showCursor = false;
if (visible) {
// _cursorX and _cursorY are currently always clipped to the active
// area, so we need to ask SDL where the system's mouse cursor is
@@ -194,10 +194,10 @@ bool SdlGraphicsManager::showMouse(bool visible) {
int x, y;
SDL_GetMouseState(&x, &y);
if (!_activeArea.drawRect.contains(Common::Point(x, y))) {
- showCursor = SDL_ENABLE;
+ showCursor = true;
}
}
- SDL_ShowCursor(showCursor);
+ showSystemMouseCursor(showCursor);
return WindowedGraphicsManager::showMouse(visible);
}
@@ -210,7 +210,7 @@ bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
mouse.x = CLIP<int16>(mouse.x, 0, _windowWidth - 1);
mouse.y = CLIP<int16>(mouse.y, 0, _windowHeight - 1);
- int showCursor = SDL_DISABLE;
+ bool showCursor = false;
// 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.
@@ -251,12 +251,12 @@ bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
}
if (_cursorVisible) {
- showCursor = SDL_ENABLE;
+ showCursor = true;
}
}
}
- SDL_ShowCursor(showCursor);
+ showSystemMouseCursor(showCursor);
if (valid) {
setMousePosition(mouse.x, mouse.y);
mouse = convertWindowToVirtual(mouse.x, mouse.y);
@@ -264,6 +264,10 @@ bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
return valid;
}
+void SdlGraphicsManager::showSystemMouseCursor(bool visible) {
+ SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
+}
+
void SdlGraphicsManager::setSystemMousePosition(const int x, const int y) {
assert(_window);
if (!_window->warpMouseInWindow(x, y)) {
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index ccddafced7d..10e2bd3b61b 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -174,6 +174,8 @@ protected:
#endif
}
+ virtual void showSystemMouseCursor(bool visible);
+
void setSystemMousePosition(const int x, const int y) override;
void notifyActiveAreaChanged() override;
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index 0c7706c3fb6..67aedfd16d9 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -755,17 +755,10 @@ bool OpenGLSdlGraphics3dManager::showMouse(bool visible) {
return true;
}
-bool OpenGLSdlGraphics3dManager::notifyMousePosition(Common::Point &mouse) {
+void OpenGLSdlGraphics3dManager::showSystemMouseCursor(bool visible) {
// HACK: SdlGraphicsManager disables the system cursor when the mouse is in the
// active draw rect, however the 3D graphics manager uses it instead of the
// standard mouse graphic.
- int showCursor = SDL_ShowCursor(SDL_QUERY);
-
- bool valid = SdlGraphicsManager::notifyMousePosition(mouse);
-
- SDL_ShowCursor(showCursor);
-
- return valid;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
index e6296516ff9..4a3380776f1 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
@@ -112,7 +112,7 @@ public:
bool gameNeedsAspectRatioCorrection() const override;
- bool notifyMousePosition(Common::Point &mouse) override;
+ void showSystemMouseCursor(bool visible) override;
protected:
#if SDL_VERSION_ATLEAST(2, 0, 0)
More information about the Scummvm-git-logs
mailing list