From da0a8db704f610994d665dfd7c080b49476ce76d Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 13 Sep 2017 00:43:56 -0500 Subject: 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. --- backends/graphics/sdl/sdl-graphics.cpp | 30 ++++++++++++++++++++++++------ backends/graphics/sdl/sdl-graphics.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'backends/graphics/sdl') 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(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right - 1); mouse.y = CLIP(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. -- cgit v1.2.3