소스 검색

Implemented UI scaling (non-selectable option for now)

Ivan Savenko 2 년 전
부모
커밋
a4b102e46f
4개의 변경된 파일30개의 추가작업 그리고 15개의 파일을 삭제
  1. 19 5
      client/renderSDL/WindowHandler.cpp
  2. 2 2
      client/windows/settings/GeneralOptionsTab.cpp
  3. 6 5
      config/schemas/settings.json
  4. 3 3
      launcher/settingsView/csettingsview_moc.cpp

+ 19 - 5
client/renderSDL/WindowHandler.cpp

@@ -35,8 +35,22 @@ static const std::string NAME = GameConstants::VCMI_VERSION + std::string(" (")
 
 Point WindowHandler::getPreferredLogicalResolution() const
 {
-	// TODO: CONFIGURABLE ADVMAP - IMPLEMENT UI SCALE SETTING
-	return {1280, 720};
+	// H3 resolution, any resolution smaller than that is not correctly supported
+	static const Point minResolution = {800, 600};
+	// arbitrary limit on *downscaling*. Allow some downscaling, if requested by user. Should be generally limited to 100+ for all but few devices
+	static const double minimalScaling = 50;
+
+	Point renderResolution = getPreferredRenderingResolution();
+	double userScaling = settings["video"]["resolution"]["scaling"].Float();
+	double maximalScalingWidth = 100.0 * renderResolution.x / minResolution.x;
+	double maximalScalingHeight = 100.0 * renderResolution.y / minResolution.y;
+	double maximalScaling = std::min(maximalScalingWidth, maximalScalingHeight);
+
+	double scaling = std::clamp(userScaling, minimalScaling, maximalScaling);
+
+	Point logicalResolution = renderResolution * 100.0 / scaling;
+
+	return logicalResolution;
 }
 
 Point WindowHandler::getPreferredRenderingResolution() const
@@ -50,8 +64,8 @@ Point WindowHandler::getPreferredRenderingResolution() const
 	else
 	{
 		const JsonNode & video = settings["video"];
-		int width = video["screenRes"]["width"].Integer();
-		int height = video["screenRes"]["height"].Integer();
+		int width = video["resolution"]["width"].Integer();
+		int height = video["resolution"]["height"].Integer();
 
 		return Point(width, height);
 	}
@@ -328,7 +342,7 @@ void WindowHandler::validateSettings()
 		{
 			if(resolution.x > mode.w || resolution.y > mode.h)
 			{
-				Settings writer = settings.write["video"]["screenRes"];
+				Settings writer = settings.write["video"]["resolution"];
 				writer["width"].Float() = mode.w;
 				writer["height"].Float() = mode.h;
 			}

+ 2 - 2
client/windows/settings/GeneralOptionsTab.cpp

@@ -115,7 +115,7 @@ GeneralOptionsTab::GeneralOptionsTab()
 	build(config);
 
 	std::shared_ptr<CLabel> resolutionLabel = widget<CLabel>("resolutionLabel");
-	const auto & currentResolution = settings["video"]["screenRes"];
+	const auto & currentResolution = settings["video"]["resolution"];
 	resolutionLabel->setText(resolutionToLabelString(currentResolution["width"].Integer(), currentResolution["height"].Integer()));
 
 	std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
@@ -185,7 +185,7 @@ void GeneralOptionsTab::setGameResolution(int index)
 
 	Point resolution = supportedResolutions[index];
 
-	Settings gameRes = settings.write["video"]["screenRes"];
+	Settings gameRes = settings.write["video"]["resolution"];
 	gameRes["width"].Float() = resolution.x;
 	gameRes["height"].Float() = resolution.y;
 

+ 6 - 5
config/schemas/settings.json

@@ -111,7 +111,7 @@
 			"additionalProperties" : false,
 			"default": {},
 			"required" : [ 
-				"screenRes", 
+				"resolution", 
 				"bitsPerPixel", 
 				"fullscreen", 
 				"realFullscreen", 
@@ -124,15 +124,16 @@
 				"targetfps"
 			],
 			"properties" : {
-				"screenRes" : {
+				"resolution" : {
 					"type" : "object",
 					"additionalProperties" : false,
-					"required" : [ "width", "height" ],
+					"required" : [ "width", "height", "scaling" ],
 					"properties" : {
 						"width"  : { "type" : "number" },
-						"height" : { "type" : "number" }
+						"height" : { "type" : "number" },
+						"scaling" : { "type" : "number" }
 					},
-					"default": {"width" : 800, "height": 600 }
+					"default": {"width" : 800, "height": 600, "scaling" : 100 }
 				},
 				"bitsPerPixel" : {
 					"type" : "number",

+ 3 - 3
launcher/settingsView/csettingsview_moc.cpp

@@ -155,8 +155,8 @@ void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
 		ui->comboBoxResolution->addItem(resolutionToString(resolution));
 	}
 
-	int resX = settings["video"]["screenRes"]["width"].Integer();
-	int resY = settings["video"]["screenRes"]["height"].Integer();
+	int resX = settings["video"]["resolution"]["width"].Integer();
+	int resY = settings["video"]["resolution"]["height"].Integer();
 	int resIndex = ui->comboBoxResolution->findText(resolutionToString({resX, resY}));
 	ui->comboBoxResolution->setCurrentIndex(resIndex);
 
@@ -186,7 +186,7 @@ void CSettingsView::on_comboBoxResolution_currentTextChanged(const QString & arg
 {
 	QStringList list = arg1.split("x");
 
-	Settings node = settings.write["video"]["screenRes"];
+	Settings node = settings.write["video"]["resolution"];
 	node["width"].Float() = list[0].toInt();
 	node["height"].Float() = list[1].toInt();
 }