Skip to content

Commit

Permalink
Fix mouse position tracking for non-4:3 windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Jan 8, 2023
1 parent 8871dfa commit 54ea6be
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/SDLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ MBoolean SDLU_CheckSDLTyping(SDL_Keycode* sdlKey)

static MPoint SDLUi_TranslatePointFromWindowToFrontSurface(MPoint pt)
{
int windowWidth, windowHeight;
SDL_GetWindowSize(g_window, &windowWidth, &windowHeight);

pt.h = pt.h * g_frontSurface->w / windowWidth;
pt.v = pt.v * g_frontSurface->h / windowHeight;
SDL_Rect viewport;
float scaleX, scaleY;
SDL_RenderGetViewport(g_renderer, &viewport);
SDL_RenderGetScale(g_renderer, &scaleX, &scaleY);

pt.h = pt.h / scaleX - viewport.x;
pt.v = pt.v / scaleY - viewport.y;

return pt;
}
Expand Down

0 comments on commit 54ea6be

Please sign in to comment.