SDL: Better workaround for enabling the system cursor

This commit is contained in:
Cameron Cawley 2022-08-20 23:51:45 +01:00
parent 416bd3a882
commit 350e21ba58
6 changed files with 16 additions and 94 deletions

View file

@ -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)) {