shithub: ft²

Download patch

ref: 89fa5c62c45c8f4bd2c56349af1040ce7c82dff1
parent: d419839301ac35e27302818ad6e05498e3a6b5b8
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Mar 18 11:44:31 EDT 2024

Cleanup

--- a/src/ft2_video.c
+++ b/src/ft2_video.c
@@ -283,8 +283,6 @@
 	video.renderX = 0;
 	video.renderY = 0;
 
-	video.dHiDPIScaleX = 1.0;
-	video.dHiDPIScaleY = 1.0;
 	video.useCustomRenderRect = false;
 
 	if (video.fullscreen)
@@ -301,22 +299,21 @@
 			// centered windowed fullscreen, with pixel-perfect integer upscaling
 
 			const int32_t maxUpscaleFactor = MIN(video.windowW / SCREEN_W, video.windowH / SCREEN_H);
-
-			// get hi-DPI upscale factors (returns 1.0 if no hi-DPI upscaling)
-			int32_t w, h;
-			SDL_GL_GetDrawableSize(video.window, &w, &h);
-			video.dHiDPIScaleX = (double)w / video.windowW;
-			video.dHiDPIScaleY = (double)h / video.windowH;
-
 			video.renderW = SCREEN_W * maxUpscaleFactor;
 			video.renderH = SCREEN_H * maxUpscaleFactor;
 			video.renderX = (video.windowW - video.renderW) / 2;
 			video.renderY = (video.windowH - video.renderH) / 2;
 
-			video.renderRect.x = (int32_t)floor(video.renderX * video.dHiDPIScaleX);
-			video.renderRect.y = (int32_t)floor(video.renderY * video.dHiDPIScaleY);
-			video.renderRect.w = (int32_t)floor(video.renderW * video.dHiDPIScaleX);
-			video.renderRect.h = (int32_t)floor(video.renderH * video.dHiDPIScaleY);
+			// get hi-DPI upscale factors (returns 1.0 if no hi-DPI upscaling)
+			int32_t widthInPixels, heightInPixels;
+			SDL_GL_GetDrawableSize(video.window, &widthInPixels, &heightInPixels);
+			double dHiDPIScaleX = (double)widthInPixels / video.windowW;
+			double dHiDPIScaleY = (double)heightInPixels / video.windowH;
+
+			video.renderRect.x = (int32_t)floor(video.renderX * dHiDPIScaleX);
+			video.renderRect.y = (int32_t)floor(video.renderY * dHiDPIScaleY);
+			video.renderRect.w = (int32_t)floor(video.renderW * dHiDPIScaleX);
+			video.renderRect.h = (int32_t)floor(video.renderH * dHiDPIScaleY);
 			video.useCustomRenderRect = true; // use the destination coordinates above in SDL_RenderCopy()
 		}
 	}
--- a/src/ft2_video.h
+++ b/src/ft2_video.h
@@ -19,19 +19,16 @@
 
 typedef struct video_t
 {
-	bool fullscreen, showFPSCounter, useCustomRenderRect;
-	uint32_t mouseCursorUpscaleFactor;
-	uint32_t *frameBuffer, palette[PAL_NUM];
+	bool fullscreen, showFPSCounter, useCustomRenderRect, vsync60HzPresent, windowHidden;
+	uint8_t windowModeUpscaleFactor;
+	int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH;
+	uint32_t mouseCursorUpscaleFactor, *frameBuffer, palette[PAL_NUM];
+	double dMonitorRefreshRate, dMouseXMul, dMouseYMul;
 #ifdef _WIN32
 	HWND hWnd;
 #endif
 	hpc_t vblankHpc;
 	SDL_Window *window;
-	double dMonitorRefreshRate, dHiDPIScaleX, dHiDPIScaleY;
-	double dMouseXMul, dMouseYMul;
-	uint8_t windowModeUpscaleFactor;
-	bool vsync60HzPresent, windowHidden;
-	int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH;
 	SDL_Rect renderRect;
 	SDL_Renderer *renderer;
 	SDL_Texture *texture;