Maelstrom: Fixed size of touch controls on phones

From 3273fd541474a493eff169ae6574b1d8f62b4677 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 31 Mar 2026 16:18:30 -0700
Subject: [PATCH] Fixed size of touch controls on phones

---
 game/MaelstromUI.cpp     |  3 +++
 game/Maelstrom_Globals.h |  2 ++
 game/game.cpp            | 15 +------------
 game/main.cpp            | 23 ++++++++++++++++++++
 game/steam.cpp           | 47 ++++++++++++++++++++++++++++++++++------
 game/steam.h             |  3 ++-
 6 files changed, 71 insertions(+), 22 deletions(-)

diff --git a/game/MaelstromUI.cpp b/game/MaelstromUI.cpp
index 1f0dc5ac..8f194a27 100644
--- a/game/MaelstromUI.cpp
+++ b/game/MaelstromUI.cpp
@@ -214,6 +214,9 @@ MaelstromUI::MaelstromUI(FrameBuf *screen, Prefs *prefs) : UIManager(screen, pre
 	if (gNetworkAvailable) {
 		SetCondition("NETWORK_AVAILABLE");
 	}
+	if (IsPhone()) {
+		SetCondition("PHONE");
+	}
 
 	/* Load up our UI templates */
 	ClearLoadPath();
diff --git a/game/Maelstrom_Globals.h b/game/Maelstrom_Globals.h
index b715c3be..22a49026 100644
--- a/game/Maelstrom_Globals.h
+++ b/game/Maelstrom_Globals.h
@@ -70,6 +70,8 @@ typedef Uint8 Bool;
 
 // Functions from main.cpp
 extern void   PrintUsage(void);
+extern bool   IsPhone(void);
+extern bool   IsTablet(void);
 extern int    DrawText(int x, int y, const char *text, MFont *font, Uint8 style,
 						Uint8 R, Uint8 G, Uint8 B);
 extern void   DelayFrame(void);
diff --git a/game/game.cpp b/game/game.cpp
index 1fe3e947..af22f871 100644
--- a/game/game.cpp
+++ b/game/game.cpp
@@ -587,19 +587,6 @@ GamePanelDelegate::OnAction(UIBaseElement *sender, const char *action)
 	return true;
 }
 
-#if !SDL_VERSION_ATLEAST(3, 5, 0)
-static bool SDL_IsPhone(void)
-{
-#if defined(SDL_PLATFORM_ANDROID) || \
-    (defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_VISIONOS))
-    if (!SDL_IsTablet() && !SDL_IsTV()) {
-        return true;
-    }
-#endif
-    return false;
-}
-#endif // SDL < 3.5.0
-
 void
 GamePanelDelegate::UpdateZoom()
 {
@@ -613,7 +600,7 @@ GamePanelDelegate::UpdateZoom()
 	SDL_SetRenderLogicalPresentation(renderer, saved_w, saved_h, saved_mode);
 
 	// We can zoom if we're on a phone or tablet in landscape mode
-	if ((SDL_IsPhone() || SDL_IsTablet() || SteamStreamingToPhoneOrTablet()) && rect.w > rect.h) {
+	if ((IsPhone() || IsTablet()) && rect.w > rect.h) {
 		StartZoom(rect);
 	} else {
 		StopZoom();
diff --git a/game/main.cpp b/game/main.cpp
index d3246a74..a1909085 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -145,6 +145,29 @@ void PrintUsage(const char *progname)
 	);
 }
 
+#if !SDL_VERSION_ATLEAST(3, 5, 0)
+static bool SDL_IsPhone(void)
+{
+#if defined(SDL_PLATFORM_ANDROID) || \
+    (defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_VISIONOS))
+    if (!SDL_IsTablet() && !SDL_IsTV()) {
+        return true;
+    }
+#endif
+    return false;
+}
+#endif // SDL < 3.5.0
+
+bool IsPhone(void)
+{
+	return (SDL_IsPhone() || SteamStreamingToPhone());
+}
+
+bool IsTablet(void)
+{
+	return (SDL_IsTablet() || SteamStreamingToTablet());
+}
+
 /* ----------------------------------------------------------------- */
 /* -- Blitter main program */
 SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
diff --git a/game/steam.cpp b/game/steam.cpp
index 73c58f3a..03f79710 100644
--- a/game/steam.cpp
+++ b/game/steam.cpp
@@ -44,7 +44,8 @@ class SteamInterface
 	bool Init();
 	void Quit();
 
-	bool StreamingToPhoneOrTablet();
+	bool StreamingToPhone();
+	bool StreamingToTablet();
 
 	void SetSteamTimelineMode(STEAM_TIMELINE_MODE mode);
 	void SetSteamTimelineLevelStarted(int level);
@@ -130,7 +131,7 @@ void SteamInterface::Quit()
 	m_initialized = false;
 }
 
-bool SteamInterface::StreamingToPhoneOrTablet()
+bool SteamInterface::StreamingToPhone()
 {
 	if (!m_initialized) {
 		return false;
@@ -146,8 +147,30 @@ bool SteamInterface::StreamingToPhoneOrTablet()
 		}
 
 		ESteamDeviceFormFactor eFormFactor = pSteamRemotePlay->GetSessionClientFormFactor(sessionID);
-		if (eFormFactor == k_ESteamDeviceFormFactorPhone || 
-		    eFormFactor == k_ESteamDeviceFormFactorTablet) {
+		if (eFormFactor == k_ESteamDeviceFormFactorPhone) {
+			return true;
+		}
+	}
+	return false;
+}
+
+bool SteamInterface::StreamingToTablet()
+{
+	if (!m_initialized) {
+		return false;
+	}
+
+	ISteamRemotePlay *pSteamRemotePlay = SteamRemotePlay();
+	for (uint32 i = 0; i < pSteamRemotePlay->GetSessionCount(); ++i) {
+		RemotePlaySessionID_t sessionID = pSteamRemotePlay->GetSessionID(i);
+
+		// Skip Remote Play Together sessions
+		if (pSteamRemotePlay->BSessionRemotePlayTogether(sessionID)) {
+			continue;
+		}
+
+		ESteamDeviceFormFactor eFormFactor = pSteamRemotePlay->GetSessionClientFormFactor(sessionID);
+		if (eFormFactor == k_ESteamDeviceFormFactorTablet) {
 			return true;
 		}
 	}
@@ -509,9 +532,14 @@ bool InitSteam()
 	return steam.Init();
 }
 
-bool SteamStreamingToPhoneOrTablet()
+bool SteamStreamingToPhone()
 {
-	return steam.StreamingToPhoneOrTablet();
+	return steam.StreamingToPhone();
+}
+
+bool SteamStreamingToTablet()
+{
+	return steam.StreamingToTablet();
 }
 
 Uint32 GetRemoteSessionForGamepad(SDL_Gamepad *gamepad)
@@ -586,7 +614,12 @@ bool InitSteam()
 	return false;
 }
 
-bool SteamStreamingToPhoneOrTablet()
+bool SteamStreamingToPhone()
+{
+	return false;
+}
+
+bool SteamStreamingToTablet()
 {
 	return false;
 }
diff --git a/game/steam.h b/game/steam.h
index 937f54b1..25e70fb1 100644
--- a/game/steam.h
+++ b/game/steam.h
@@ -45,7 +45,8 @@ enum STEAM_TIMELINE_EVENT
 typedef Uint32 RemotePlaySessionID_t;
 
 extern bool InitSteam();
-extern bool SteamStreamingToPhoneOrTablet();
+extern bool SteamStreamingToPhone();
+extern bool SteamStreamingToTablet();
 extern RemotePlaySessionID_t GetRemoteSessionForGamepad(SDL_Gamepad *gamepad);
 extern Uint8 GetRemoteSessionControl(RemotePlaySessionID_t sessionID);
 extern const char *GetRemotePlayerName(Uint8 controlType);