Maelstrom: Removed logical size handling and make window always resizable

From a08420d5ce2c349a93a9f15dabec2fd42a4841e5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 22 Nov 2025 21:17:40 -0800
Subject: [PATCH] Removed logical size handling and make window always
 resizable

SDL takes care of logical size with the logical presentation mode.

Also updated command line parameters to use '--' long form prefix.
---
 game/MaelstromUI.cpp       |  14 +---
 game/init.cpp              |   1 -
 game/main.cpp              |  20 +++--
 screenlib/SDL_FrameBuf.cpp | 152 +++----------------------------------
 screenlib/SDL_FrameBuf.h   |  13 ----
 screenlib/UIManager.cpp    |  15 ----
 6 files changed, 23 insertions(+), 192 deletions(-)

diff --git a/game/MaelstromUI.cpp b/game/MaelstromUI.cpp
index 42a469e6..363183ce 100644
--- a/game/MaelstromUI.cpp
+++ b/game/MaelstromUI.cpp
@@ -264,16 +264,6 @@ MaelstromUI::CreateText(const char *text, const char *fontName, int fontSize, UI
 	char *key;
 	int keysize;
 	SDL_Texture *texture;
-	float logicalScale;
-
-	/* Adjust the font size by our logical scale */
-	//logicalScale = m_screen->GetLogicalScale();
-	int displayWidth, displayHeight;
-	int logicalWidth, logicalHeight;
-	m_screen->GetDisplaySize(displayWidth, displayHeight);
-	m_screen->GetLogicalSize(logicalWidth, logicalHeight);
-	logicalScale = (float)displayWidth / logicalWidth;
-	fontSize = (int)(fontSize * logicalScale);
 
 	/* First see if we can find it in our cache */
 	keysize = strlen(fontName)+1+2+1+1+1+8+1+strlen(text)+1;
@@ -281,7 +271,7 @@ MaelstromUI::CreateText(const char *text, const char *fontName, int fontSize, UI
 	SDL_snprintf(key, keysize, "%s:%d:%c:%8.8x:%s", fontName, fontSize, '0'+fontStyle, color, text);
 	if (hash_find(m_strings, key, (const void**)&texture)) {
 		SDL_stack_free(key);
-		return new UITexture(texture, logicalScale);
+		return new UITexture(texture, 1.0f);
 	}
 
 	font = GetFont(fontName, fontSize);
@@ -312,7 +302,7 @@ MaelstromUI::CreateText(const char *text, const char *fontName, int fontSize, UI
 	}
 	SDL_stack_free(key);
 
-	return new UITexture(texture, logicalScale);
+	return new UITexture(texture, 1.0f);
 }
 
 void 
diff --git a/game/init.cpp b/game/init.cpp
index c54b9db9..277ed600 100644
--- a/game/init.cpp
+++ b/game/init.cpp
@@ -797,7 +797,6 @@ int DoInitializations(Uint32 window_flags)
 		error("Fatal: %s\n", screen->Error());
 		return(-1);
 	}
-	screen->SetLogicalSize(GAME_WIDTH, GAME_HEIGHT);
 	screen->SetCaption("Maelstrom");
 	SDL_DestroySurface(icon);
 
diff --git a/game/main.cpp b/game/main.cpp
index e666c4fa..2994a7c9 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -138,13 +138,11 @@ static void CheatDialogDone(void*, UIDialog *dialog, int status)
 static char *progname;
 void PrintUsage(void)
 {
-	error("Usage: %s <options>\n\n", progname);
-	error("Where <options> can be any of:\n\n"
-"	-fullscreen		# Run Maelstrom in full-screen mode\n"
-"	-windowed		# Run Maelstrom in windowed mode\n"
-"	-classic		# Run Maelstrom in 640x480 classic mode\n"
+	SDL_Log("Usage: %s <options>", progname);
+	SDL_Log("Where <options> can be any of:\n"
+"	--fullscreen		# Run Maelstrom in full-screen mode\n"
+"	--windowed		# Run Maelstrom in windowed mode\n"
 	);
-	error("\n");
 	exit(1);
 }
 
@@ -177,7 +175,7 @@ void ShowFrame(void*)
 int MaelstromMain(int argc, char *argv[])
 {
 	/* Command line flags */
-	Uint32 window_flags = 0;
+	Uint32 window_flags = SDL_WINDOW_FULLSCREEN | SDL_WINDOW_RESIZABLE;
 
 	if ( !InitFilesystem(MAELSTROM_ORGANIZATION, MAELSTROM_NAME) ) {
 		exit(1);
@@ -191,14 +189,14 @@ int MaelstromMain(int argc, char *argv[])
 	window_flags |= SDL_WINDOW_FULLSCREEN;
 #endif
 	for ( progname=argv[0]; --argc; ++argv ) {
-		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
+		if ( strcmp(argv[1], "--fullscreen") == 0 ) {
 			window_flags |= SDL_WINDOW_FULLSCREEN;
-		} else if ( strcmp(argv[1], "-windowed") == 0 ) {
+		} else if ( strcmp(argv[1], "--windowed") == 0 ) {
 			window_flags &= ~SDL_WINDOW_FULLSCREEN;
-		} else if ( strcmp(argv[1], "-version") == 0 ) {
+		} else if ( strcmp(argv[1], "--version") == 0 ) {
 			error("%s", Version);
 			exit(0);
-		} else if ( strcmp(argv[1], "-help") == 0 ) {
+		} else {
 			PrintUsage();
 		}
 	}
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index 85705a48..f7ecbf4e 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -38,20 +38,12 @@ FrameBuf::FrameBuf() : ErrorBase()
 	window = NULL;
 	renderer = NULL;
 	faded = 0;
-	resizable = false;
-	logicalScale = 0.0f;
 }
 
 int
 FrameBuf::Init(int width, int height, Uint32 window_flags, SDL_Surface *icon)
 {
-	if (window_flags & SDL_WINDOW_RESIZABLE) {
-		resizable = true;
-	} else {
-		resizable = false;
-	}
-
-	window = SDL_CreateWindow("Maelstrom", width, height, window_flags);
+	window = SDL_CreateWindow(NULL, width, height, window_flags);
 	if (!window) {
 		SetError("Couldn't create %dx%d window: %s", 
 					width, height, SDL_GetError());
@@ -70,13 +62,8 @@ FrameBuf::Init(int width, int height, Uint32 window_flags, SDL_Surface *icon)
 	}
 
 	/* Set the output area */
-	if (Resizable()) {
-		int w, h;
-		SDL_GetWindowSize(window, &w, &h);
-		UpdateWindowSize(w, h);
-	} else {
-		SetLogicalSize(width, height);
-	}
+	SDL_SetRenderLogicalPresentation(renderer, width, height, SDL_LOGICAL_PRESENTATION_LETTERBOX);
+	UpdateWindowSize(width, height);
 
 	return(0);
 }
@@ -94,44 +81,17 @@ FrameBuf::~FrameBuf()
 void
 FrameBuf::ProcessEvent(SDL_Event *event)
 {
-	switch (event->type) {
-	case SDL_EVENT_WINDOW_RESIZED:
-		{
-			int w, h;
-			SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
-
-			w = Width();
-			h = Height();
-			if (Resizable()) {
-				// We'll accept this window size change
-				SDL_GetWindowSize(window, &w, &h);
-				SDL_SetRenderViewport(renderer, NULL);
-			}
-			if (logicalScale > 0.0f) {
-				w = (int)(w/logicalScale);
-				h = (int)(h/logicalScale);
-				SetLogicalSize(w, h);
-			} else {
-				UpdateWindowSize(w, h);
-			}
-		}
-		break;
-	}
+	SDL_ConvertEventToRenderCoordinates(renderer, event);
 }
 
-// This routine or something like it should probably go in SDL
 bool
 FrameBuf::ConvertTouchCoordinates(const SDL_TouchFingerEvent &finger, int *x, int *y)
 {
-	int window_w, window_h;
-	float scale_x, scale_y;
-
-	SDL_GetWindowSize(window, &window_w, &window_h);
-	SDL_GetRenderScale(renderer, &scale_x, &scale_y);
-	*x = (int)(finger.x*window_w/scale_x) - output.x;
-	*y = (int)(finger.y*window_h/scale_y) - output.y;
-	*x = (*x * rect.w) / output.w;
-	*y = (*y * rect.h) / output.h;
+	int w, h;
+
+	SDL_GetRenderOutputSize(renderer, &w, &h);
+	*x = (int)(finger.x * w);
+	*y = (int)(finger.y * h);
 	return true;
 }
 
@@ -146,15 +106,12 @@ void
 FrameBuf::GetCursorPosition(int *x, int *y)
 {
 	float mouse_x, mouse_y;
-	float scale_x, scale_y;
 
 	SDL_GetMouseState(&mouse_x, &mouse_y);
-	SDL_GetRenderScale(renderer, &scale_x, &scale_y);
+	SDL_RenderCoordinatesFromWindow(renderer, mouse_x, mouse_y, &mouse_x, &mouse_y);
 
-	*x = (int)(mouse_x/scale_x) - output.x;
-	*y = (int)(mouse_y/scale_y) - output.y;
-	*x = (*x * rect.w) / output.w;
-	*y = (*y * rect.h) / output.h;
+	*x = (int)mouse_x;
+	*y = (int)mouse_y;
 }
 
 void
@@ -169,77 +126,6 @@ FrameBuf::DisableTextInput()
 	SDL_StopTextInput(window);
 }
 
-void
-FrameBuf::GetDesktopSize(int &w, int &h) const
-{
-	const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
-	if (!mode) {
-		w = 0;
-		h = 0;
-	} else {
-		w = mode->w;
-		h = mode->h;
-	}
-}
-
-void
-FrameBuf::GetDisplaySize(int &w, int &h) const
-{
-	SDL_GetWindowSize(window, &w, &h);
-}
-
-void
-FrameBuf::GetLogicalSize(int &w, int &h) const
-{
-	SDL_GetRenderLogicalPresentation(renderer, &w, &h, NULL);
-	if (!w || !h) {
-		w = Width();
-		h = Height();
-	}
-}
-
-void
-FrameBuf::SetLogicalSize(int w, int h)
-{
-	SDL_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_LETTERBOX);
-	UpdateWindowSize(w, h);
-}
-
-void
-FrameBuf::SetLogicalScale(float scale)
-{
-	int w, h;
-	SDL_Texture *target;
-
-	target = SDL_GetRenderTarget(renderer);
-	if (target) {
-		// This is a temporary scale change
-		w = target->w;
-		h = target->h;
-		if (scale > 0.0f) {
-			w = (int)(w/scale);
-			h = (int)(h/scale);
-		}
-		SDL_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_LETTERBOX);
-	} else {
-		logicalScale = scale;
-
-		if (Resizable()) {
-			SDL_GetWindowSize(window, &w, &h);
-		} else {
-			w = Width();
-			h = Height();
-		}
-		if (logicalScale > 0.0f) {
-			w = (int)(w/logicalScale);
-			h = (int)(h/logicalScale);
-			SetLogicalSize(w, h);
-		} else {
-			UpdateWindowSize(w, h);
-		}
-	}
-}
-
 void
 FrameBuf::QueueBlit(SDL_Texture *src,
 			int srcx, int srcy, int srcw, int srch,
@@ -334,7 +220,6 @@ FrameBuf::Fade(void)
 int
 FrameBuf::ScreenDump(const char *prefix, int x, int y, int w, int h)
 {
-	float scale_x, scale_y;
 	SDL_Rect rect;
 	SDL_Surface *dump;
 	char file[1024];
@@ -347,19 +232,6 @@ FrameBuf::ScreenDump(const char *prefix, int x, int y, int w, int h)
 		h = Height();
 	}
 
-	// Convert to real output coordinates
-	SDL_GetRenderScale(renderer, &scale_x, &scale_y);
-
-	x = (x * output.w) / this->rect.w;
-	y = (y * output.h) / this->rect.h;
-	x = (int)((x + output.x) * scale_x);
-	y = (int)((y + output.y) * scale_y);
-
-	w = (w * output.w) / this->rect.w;
-	h = (h * output.h) / this->rect.h;
-	w = (int)(w * scale_x);
-	h = (int)(h * scale_y);
-
 	rect.x = x;
 	rect.y = y;
 	rect.w = w;
diff --git a/screenlib/SDL_FrameBuf.h b/screenlib/SDL_FrameBuf.h
index fab4e99c..710e56c5 100644
--- a/screenlib/SDL_FrameBuf.h
+++ b/screenlib/SDL_FrameBuf.h
@@ -106,17 +106,6 @@ class FrameBuf : public ErrorBase {
 	int Height() const {
 		return rect.h;
 	}
-	bool Resizable() const {
-		return resizable;
-	}
-	void GetDesktopSize(int &w, int &h) const;
-	void GetDisplaySize(int &w, int &h) const;
-	void GetLogicalSize(int &w, int &h) const;
-	void SetLogicalSize(int w, int h);
-	float GetLogicalScale() const {
-		return logicalScale ? logicalScale : 1.0f;
-	}
-	void SetLogicalScale(float scale);
 
 	/* Blit and update routines */
 	void QueueBlit(SDL_Texture *src,
@@ -221,8 +210,6 @@ class FrameBuf : public ErrorBase {
 	SDL_Rect rect;
 	SDL_FRect clip;
 	SDL_Rect output;
-	bool resizable;
-	float logicalScale;
 
 	void UpdateWindowSize(int width, int height) {
 		clip.x = rect.x = 0;
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index 877b029a..4fdce5ad 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -416,21 +416,6 @@ UIManager::HandleEvent(const SDL_Event &event)
 {
 	unsigned int i;
 
-	if (event.type == SDL_EVENT_WINDOW_RESIZED &&
-	    m_screen->Resizable()) {
-		SDL_Rect clip;
-
-		// Reset the clip rectangle
-		clip.x = 0;
-		clip.y = 0;
-		clip.w = m_screen->Width();
-		clip.h = m_screen->Height();
-		m_screen->ClipBlit(&clip);
-
-		// Resize to match window size
-		SetSize(m_screen->Width(), m_screen->Height());
-	}
-
 	// In case it's not called any other time...
 	Poll();