shithub: candycrisis

Download patch

ref: de3d29e478ff57d6c2fd083a7838fe9b286503a6
parent: fbb518d82487118bc5403a798895642bf7ad4304
author: Iliyas Jorio <iliyas@jor.io>
date: Mon Feb 6 14:21:46 EST 2023

HiDPI support

--- a/src/SDLU.cpp
+++ b/src/SDLU.cpp
@@ -423,6 +423,29 @@
 
 static MPoint SDLUi_TranslatePointFromWindowToFrontSurface(MPoint pt)
 {
+	// On macOS, the mouse position is relative to the window's "point size" on Retina screens.
+	int windowPointW = 1;
+	int windowPointH = 1;
+	int windowPixelW = 1;
+	int windowPixelH = 1;
+
+	SDL_GetWindowSize(g_window, &windowPointW, &windowPointH);
+#if SDL_VERSION_ATLEAST(2,26,0)
+	SDL_GetWindowSizeInPixels(g_window, &windowPixelW, &windowPixelH);
+#else
+	// Backwards compat with old versions of SDL
+	windowPixelW = windowPointW;
+	windowPixelH = windowPointH;
+#endif
+
+	if (windowPointW != windowPixelW || windowPointH != windowPixelH)
+	{
+		float dpiScaleX = (float) windowPixelW / (float) windowPointW;		// gGameWindowWidth is in actual pixels
+		float dpiScaleY = (float) windowPixelH / (float) windowPointH;		// gGameWindowHeight is in actual pixels
+		pt.h *= dpiScaleX;
+		pt.v *= dpiScaleY;
+	}
+
     SDL_Rect viewport;
     float scaleX, scaleY;
     SDL_RenderGetViewport(g_renderer, &viewport);
@@ -430,6 +453,12 @@
 
     pt.h = pt.h / scaleX - viewport.x;
     pt.v = pt.v / scaleY - viewport.y;
+
+    if (widescreen)
+    {
+        pt.h += g_widescreenCrop.x;
+        pt.v += g_widescreenCrop.y;
+    }
 
     return pt;
 }
binary files a/src/main.cpp b/src/main.cpp differ