فهرست منبع

Enable auto-detection of UI scaling

Ivan Savenko 1 سال پیش
والد
کامیت
42adc9d394
2فایلهای تغییر یافته به همراه21 افزوده شده و 8 حذف شده
  1. 16 0
      client/renderSDL/ScreenHandler.cpp
  2. 5 8
      config/schemas/settings.json

+ 16 - 0
client/renderSDL/ScreenHandler.cpp

@@ -93,6 +93,22 @@ Point ScreenHandler::getPreferredLogicalResolution() const
 	auto [minimalScaling, maximalScaling] = getSupportedScalingRange();
 
 	int userScaling = settings["video"]["resolution"]["scaling"].Integer();
+
+	if (userScaling == 0) // autodetection
+	{
+#ifdef VCMI_MOBILE
+		// for mobiles - stay at maximum scaling unless we have large screen
+		// might be better to check screen DPI / physical dimensions, but way more complex, and may result in different edge cases, e.g. chromebooks / tv's
+		int preferredMinimalScaling = 200;
+#else
+		// for PC - avoid downscaling if possible
+		int preferredMinimalScaling = 100;
+#endif
+		// prefer a little below maximum - to give space for extended UI
+		int preferredMaximalScaling = maximalScaling * 10 / 12;
+		userScaling = std::max(std::min(maximalScaling, preferredMinimalScaling), preferredMaximalScaling);
+	}
+
 	int scaling = std::clamp(userScaling, minimalScaling, maximalScaling);
 
 	Point logicalResolution = availableResolution * 100.0 / scaling;

+ 5 - 8
config/schemas/settings.json

@@ -195,17 +195,14 @@
 					"additionalProperties" : false,
 					"required" : [ "width", "height", "scaling" ],
 					"properties" : {
-						"width"  : { "type" : "number" },
-						"height" : { "type" : "number" },
-						"scaling" : { "type" : "number" }
-					},
-					"defaultIOS" : {"width" : 800, "height" : 600, "scaling" : 200 },
-					"defaultAndroid" : {"width" : 800, "height" : 600, "scaling" : 200 },
-					"default" : {"width" : 800, "height" : 600, "scaling" : 100 }
+						"width"  :  { "type" : "number", "default" : 800 },
+						"height" :  { "type" : "number", "default" : 600 },
+						"scaling" : { "type" : "number", "default" :   0 }
+					}
 				},
 				"reservedWidth" : {
 					"type" : "number",
-					"defaultIOS" : 0.1, // iOS camera cutout / notch is excluded from available area by SDL
+					"defaultIOS" : 0.1, // iOS camera cutout / notch is not excluded from available area by SDL, handle it this way
 					"default" : 0
 				},
 				"fullscreen" : {