diff options
author | Colin Snover | 2017-09-13 00:43:56 -0500 |
---|---|---|
committer | Colin Snover | 2017-10-15 13:24:20 -0500 |
commit | da0a8db704f610994d665dfd7c080b49476ce76d (patch) | |
tree | d22ed14f81f2a698f053df52e5ac57d8f9793957 /backends/graphics/sdl | |
parent | de2bbe3b9738ef95b2529db989570770ef434f9d (diff) | |
download | scummvm-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')
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp | 30 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 2 |
2 files changed, 26 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; } } diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 886070aedb..772bc88637 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -87,6 +87,8 @@ public: */ virtual void notifyMousePosition(Common::Point &mouse); + virtual bool showMouse(const bool visible) override; + /** * A (subset) of the graphic manager's state. This is used when switching * between different SDL graphic managers at runtime. |