aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/sdl/sdl-graphics.cpp
diff options
context:
space:
mode:
authorColin Snover2017-09-13 00:43:56 -0500
committerColin Snover2017-10-15 13:24:20 -0500
commitda0a8db704f610994d665dfd7c080b49476ce76d (patch)
treed22ed14f81f2a698f053df52e5ac57d8f9793957 /backends/graphics/sdl/sdl-graphics.cpp
parentde2bbe3b9738ef95b2529db989570770ef434f9d (diff)
downloadscummvm-rg350-da0a8db704f610994d665dfd7c080b49476ce76d.tar.gz
scummvm-rg350-da0a8db704f610994d665dfd7c080b49476ce76d.tar.bz2
scummvm-rg350-da0a8db704f610994d665dfd7c080b49476ce76d.zip
BACKENDS: Also hide mouse cursor outside game area when an engine has hidden the cursor
The only reason we show the system cursor outside the game area is to show users where their mouse is when the window is resized and the mouse is outside the game area. If the game cannot be interacted with, then the mouse also does not need to be shown in the black areas.
Diffstat (limited to 'backends/graphics/sdl/sdl-graphics.cpp')
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index ea947c1073..6ce0bc7bac 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -148,18 +148,36 @@ void SdlGraphicsManager::initSizeHint(const Graphics::ModeList &modes) {
#endif
}
+bool SdlGraphicsManager::showMouse(const 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);
+}
+
void SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
- int showCursor;
- if (_activeArea.drawRect.contains(mouse)) {
- showCursor = SDL_DISABLE;
- } else {
+ int showCursor = SDL_DISABLE;
+ if (!_activeArea.drawRect.contains(mouse)) {
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);
if (_window->mouseIsGrabbed()) {
setSystemMousePosition(mouse.x, mouse.y);
- showCursor = SDL_DISABLE;
- } else {
+ } else if (_cursorVisible) {
showCursor = SDL_ENABLE;
}
}