shithub: candycrisis

Download patch

ref: 54ea6bebeb3effbfc25b3790f4b1d8c49fa441bd
parent: 8871dfafcd58c3952762d5f0de3a6222e638fba2
author: Iliyas Jorio <[email protected]>
date: Sun Jan 8 14:36:13 EST 2023

Fix mouse position tracking for non-4:3 windows

--- a/src/SDLU.cpp
+++ b/src/SDLU.cpp
@@ -367,11 +367,13 @@
 
 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;
 }