mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Implemented UI scaling (non-selectable option for now)
This commit is contained in:
@@ -35,8 +35,22 @@ static const std::string NAME = GameConstants::VCMI_VERSION + std::string(" (")
|
|||||||
|
|
||||||
Point WindowHandler::getPreferredLogicalResolution() const
|
Point WindowHandler::getPreferredLogicalResolution() const
|
||||||
{
|
{
|
||||||
// TODO: CONFIGURABLE ADVMAP - IMPLEMENT UI SCALE SETTING
|
// H3 resolution, any resolution smaller than that is not correctly supported
|
||||||
return {1280, 720};
|
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
|
Point WindowHandler::getPreferredRenderingResolution() const
|
||||||
@@ -50,8 +64,8 @@ Point WindowHandler::getPreferredRenderingResolution() const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const JsonNode & video = settings["video"];
|
const JsonNode & video = settings["video"];
|
||||||
int width = video["screenRes"]["width"].Integer();
|
int width = video["resolution"]["width"].Integer();
|
||||||
int height = video["screenRes"]["height"].Integer();
|
int height = video["resolution"]["height"].Integer();
|
||||||
|
|
||||||
return Point(width, height);
|
return Point(width, height);
|
||||||
}
|
}
|
||||||
@@ -328,7 +342,7 @@ void WindowHandler::validateSettings()
|
|||||||
{
|
{
|
||||||
if(resolution.x > mode.w || resolution.y > mode.h)
|
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["width"].Float() = mode.w;
|
||||||
writer["height"].Float() = mode.h;
|
writer["height"].Float() = mode.h;
|
||||||
}
|
}
|
||||||
|
@@ -115,7 +115,7 @@ GeneralOptionsTab::GeneralOptionsTab()
|
|||||||
build(config);
|
build(config);
|
||||||
|
|
||||||
std::shared_ptr<CLabel> resolutionLabel = widget<CLabel>("resolutionLabel");
|
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()));
|
resolutionLabel->setText(resolutionToLabelString(currentResolution["width"].Integer(), currentResolution["height"].Integer()));
|
||||||
|
|
||||||
std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
|
std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
|
||||||
@@ -185,7 +185,7 @@ void GeneralOptionsTab::setGameResolution(int index)
|
|||||||
|
|
||||||
Point resolution = supportedResolutions[index];
|
Point resolution = supportedResolutions[index];
|
||||||
|
|
||||||
Settings gameRes = settings.write["video"]["screenRes"];
|
Settings gameRes = settings.write["video"]["resolution"];
|
||||||
gameRes["width"].Float() = resolution.x;
|
gameRes["width"].Float() = resolution.x;
|
||||||
gameRes["height"].Float() = resolution.y;
|
gameRes["height"].Float() = resolution.y;
|
||||||
|
|
||||||
|
@@ -111,7 +111,7 @@
|
|||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"default": {},
|
"default": {},
|
||||||
"required" : [
|
"required" : [
|
||||||
"screenRes",
|
"resolution",
|
||||||
"bitsPerPixel",
|
"bitsPerPixel",
|
||||||
"fullscreen",
|
"fullscreen",
|
||||||
"realFullscreen",
|
"realFullscreen",
|
||||||
@@ -124,15 +124,16 @@
|
|||||||
"targetfps"
|
"targetfps"
|
||||||
],
|
],
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"screenRes" : {
|
"resolution" : {
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"required" : [ "width", "height" ],
|
"required" : [ "width", "height", "scaling" ],
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"width" : { "type" : "number" },
|
"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" : {
|
"bitsPerPixel" : {
|
||||||
"type" : "number",
|
"type" : "number",
|
||||||
|
@@ -155,8 +155,8 @@ void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
|
|||||||
ui->comboBoxResolution->addItem(resolutionToString(resolution));
|
ui->comboBoxResolution->addItem(resolutionToString(resolution));
|
||||||
}
|
}
|
||||||
|
|
||||||
int resX = settings["video"]["screenRes"]["width"].Integer();
|
int resX = settings["video"]["resolution"]["width"].Integer();
|
||||||
int resY = settings["video"]["screenRes"]["height"].Integer();
|
int resY = settings["video"]["resolution"]["height"].Integer();
|
||||||
int resIndex = ui->comboBoxResolution->findText(resolutionToString({resX, resY}));
|
int resIndex = ui->comboBoxResolution->findText(resolutionToString({resX, resY}));
|
||||||
ui->comboBoxResolution->setCurrentIndex(resIndex);
|
ui->comboBoxResolution->setCurrentIndex(resIndex);
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ void CSettingsView::on_comboBoxResolution_currentTextChanged(const QString & arg
|
|||||||
{
|
{
|
||||||
QStringList list = arg1.split("x");
|
QStringList list = arg1.split("x");
|
||||||
|
|
||||||
Settings node = settings.write["video"]["screenRes"];
|
Settings node = settings.write["video"]["resolution"];
|
||||||
node["width"].Float() = list[0].toInt();
|
node["width"].Float() = list[0].toInt();
|
||||||
node["height"].Float() = list[1].toInt();
|
node["height"].Float() = list[1].toInt();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user