imgui icon indicating copy to clipboard operation
imgui copied to clipboard

GetMouseState dont calculate for scaling SDL3

Open CptFisk opened this issue 2 years ago • 2 comments

Problem

When using SDL3_Renderer with SDL_SetREnderScale the mouse cordinates that is recived throught event->motion.x and event->motion.y dont account for scaling offset.

Solution

Before io.AddMousePosEvent the scalefactor is applied to the mouse cordinates

Changes

ImGui_ImplSDL3_ProcessEvent now fetches the scaling and apply it to the mouse cordinates.

CptFisk avatar Apr 24 '23 19:04 CptFisk

I am rather puzzled by this. You are highlighting a real problem if using SDL_SetRenderScale() but it seems like absolutely nothing in this PR was tested?

  • Variables scaleX/scaleY are not declared.
  • The correct formula here seems to a divide rather than a multiply.
  • There is also call to AddMousePosEvent() in ImGui_ImplSDL3_UpdateMouseData() which hasn't been scaled.
  • bd->Renderer may be NULL on other backends.
  • The io.WantSetMousePos path has not been handled.

I can't comprehend how this would have possibly worked on our end. Could you clarify?

ocornut avatar May 05 '25 13:05 ocornut

Also see https://wiki.libsdl.org/SDL3/SDL_ConvertEventToRenderCoordinates

ocornut avatar May 05 '25 14:05 ocornut