Enable auto-detection of UI scaling

This commit is contained in:
Ivan Savenko
2024-10-09 17:37:54 +00:00
parent 0c03e0b7c7
commit 42adc9d394
2 changed files with 21 additions and 8 deletions
+16
View File
@@ -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
View File
@@ -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" : {