Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid SDL_GetMouseState(), which returns raw coordinates (fixes #318) #320

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

sulix
Copy link
Contributor

@sulix sulix commented Sep 13, 2023

sdl12-compat tracks the mouse position in the MousePosition variable, even when we're not in relative mouse mode. We therefore don't need to call SDL20_GetMouseState() to update it before entering relative mouse mode: we already have it from the last SDL_MOUSEMOTION event, and have already applied any scaling we need.

This is important, because SDL_GetMouseState() returns the raw mouse coordinates, not the ones scaled by SDL_RenderSetLogicalSize(). So we end up with a mismatch. This results in a mouse offset on non-OpenGL, scaled games, like Alpha Centauri in fullscreen (see #318).

We could fix this by calling SDL_RenderWindowToLogical() instead, but that complicates the codepath as we don't always have an SDL_Renderer (we might be using OpenGL), so this seems cleaner.

I've tested this with SMAC (where it fixes the bug) and Wolf4SDL (which was cited in the commit which introduced this check). Both work fine.

sdl12-compat tracks the mouse position in the MousePosition variable,
even when we're not in relative mouse mode. We therefore don't need to
call SDL20_GetMouseState() to update it before entering relative mouse
mode: we already have it from the last SDL_MOUSEMOTION event, and have
already applied any scaling we need.

This is important, because SDL_GetMouseState() returns the _raw_ mouse
coordinates, not the ones scaled by SDL_RenderSetLogicalSize(). So we
end up with a mismatch. This results in a mouse offset on non-OpenGL,
scaled games, like Alpha Centauri in fullscreen (see libsdl-org#318).

We could fix this by calling SDL_RenderWindowToLogical() instead, but
that complicates the codepath as we don't always have an SDL_Renderer
(we might be using OpenGL), so this seems cleaner.

I've tested this with SMAC (where it fixes the bug) and Wolf4SDL (which
was cited in the commit which introduced this check). Both work fine.
@slouken slouken merged commit 0d818b0 into libsdl-org:main Sep 13, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants