libsdl-org / sdl2-compat

An SDL2 compatibility layer that uses SDL3 behind the scenes.
zlib License
65 stars 17 forks source link

Only scale mouse coordinates if logical size is set #156

Closed cgutman closed 3 months ago

cgutman commented 3 months ago

SDL2 only scales mouse coordinates to the renderer's (logical) size if SDL_RenderSetLogicalSize() was called to enable logical scaling. If not, it will send unmodified coordinates in mouse events. Relevant SDL2 code: https://github.com/libsdl-org/SDL/blob/f1690e265e306818882c7c876a9e85492eeefa42/src/render/SDL_render.c#L761-L787

Unconditionally calling SDL_ConvertEventToRenderCoordinates() doesn't exactly match SDL2's behavior here because it will still adjust for DPI even if the renderer's logical presentation size is not set. I'm assuming SDL_ConvertEventToRenderCoordinates() is working as intended, so we have to check if logical scaling is enabled before using it.

cgutman commented 3 months ago

CI needs to be rerun after cde306383b741e1d5a2b8b49e74ef0b316a5336f landed. I don't have permission to kick it myself (without pushing again).

slouken commented 3 months ago

Merged, thanks!