1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Add selector for font type in Launcher, add autoselection

This commit is contained in:
Ivan Savenko 2024-09-24 12:17:25 +00:00
parent 87274128e7
commit ca3c6227c4
7 changed files with 930 additions and 780 deletions

View File

@ -39,17 +39,36 @@ size_t FontChain::getFontAscentScaled() const
return maxHeight;
}
bool FontChain::bitmapFontsPrioritized() const
{
const std::string & fontType = settings["video"]["fontsType"].String();
if (fontType == "original")
return true;
if (fontType == "scalable")
return false;
// else - autoselection.
if (getScalingFactor() != 1)
return false; // If xbrz in use ttf/scalable fonts are preferred
if (!vstd::isAlmostEqual(1.0, settings["video"]["fontScalingFactor"].Float()))
return false; // If player requested non-100% scaling - use scalable fonts
return true; // else - use original bitmap fonts
}
void FontChain::addTrueTypeFont(const JsonNode & trueTypeConfig)
{
chain.push_back(std::make_unique<CTrueTypeFont>(trueTypeConfig));
chain.insert(chain.begin(), std::make_unique<CTrueTypeFont>(trueTypeConfig));
}
void FontChain::addBitmapFont(const std::string & bitmapFilename)
{
if (settings["video"]["scalableFonts"].Bool())
chain.push_back(std::make_unique<CBitmapFont>(bitmapFilename));
else
if (bitmapFontsPrioritized())
chain.insert(chain.begin(), std::make_unique<CBitmapFont>(bitmapFilename));
else
chain.push_back(std::make_unique<CBitmapFont>(bitmapFilename));
}
bool FontChain::canRepresentCharacter(const char * data) const

View File

@ -29,6 +29,7 @@ class FontChain final : public IFont
void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const override;
size_t getFontAscentScaled() const override;
bool bitmapFontsPrioritized() const;
public:
FontChain() = default;

View File

@ -356,7 +356,8 @@ std::shared_ptr<const IFont> RenderHandler::loadFont(EFonts font)
const JsonNode & ttfConf = config["trueType"];
bitmapPath = bmpConf[index].String();
loadedFont->addTrueTypeFont(ttfConf[bitmapPath]);
if (!ttfConf[bitmapPath].isNull())
loadedFont->addTrueTypeFont(ttfConf[bitmapPath]);
}
loadedFont->addBitmapFont(bitmapPath);

View File

@ -166,7 +166,7 @@
"showfps",
"targetfps",
"vsync",
"scalableFonts",
"fontsType",
"fontScalingFactor",
"upscalingFilter",
"fontUpscalingFilter",
@ -234,9 +234,10 @@
"type" : "boolean",
"default" : true
},
"scalableFonts" : {
"type" : "boolean",
"default" : false
"fontsType" : {
"type" : "string",
"enum" : [ "auto", "original", "scalable" ],
"default" : "auto"
},
"fontScalingFactor" : {
"type" : "number",

View File

@ -174,7 +174,14 @@ void CSettingsView::loadSettings()
ui->sliderControllerSticksAcceleration->setValue(settings["input"]["controllerAxisScale"].Float() * 100);
ui->lineEditGameLobbyHost->setText(QString::fromStdString(settings["lobby"]["hostname"].String()));
ui->spinBoxNetworkPortLobby->setValue(settings["lobby"]["port"].Integer());
if (settings["video"]["fontsType"].String() == "auto")
ui->buttonFontAuto->setChecked(true);
else if (settings["video"]["fontsType"].String() == "original")
ui->buttonFontOriginal->setChecked(true);
else
ui->buttonFontScalable->setChecked(true);
loadToggleButtonSettings();
}
@ -195,11 +202,13 @@ void CSettingsView::loadToggleButtonSettings()
setCheckbuttonState(ui->buttonRelativeCursorMode, settings["general"]["userRelativePointer"].Bool());
setCheckbuttonState(ui->buttonHapticFeedback, settings["general"]["hapticFeedback"].Bool());
setCheckbuttonState(ui->buttonTtfFont, settings["video"]["scalableFonts"].Bool());
std::string cursorType = settings["video"]["cursor"].String();
int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType);
setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex);
int fontScalingPercentage = settings["video"]["fontScalingFactor"].Float() * 100;
ui->sliderScalingFont->setValue(fontScalingPercentage / 5);
}
void CSettingsView::fillValidResolutions()
@ -757,9 +766,28 @@ void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value)
node->Integer() = value;
}
void CSettingsView::on_buttonTtfFont_toggled(bool value)
void CSettingsView::on_sliderScalingFont_valueChanged(int value)
{
Settings node = settings.write["video"]["scalableFonts"];
node->Bool() = value;
updateCheckbuttonText(ui->buttonTtfFont);
int actualValuePercentage = value * 5;
ui->labelScalingFontValue->setText(QString("%1%").arg(actualValuePercentage));
Settings node = settings.write["video"]["fontScalingFactor"];
node->Float() = actualValuePercentage / 100.0;
}
void CSettingsView::on_buttonFontAuto_clicked(bool checked)
{
Settings node = settings.write["video"]["fontsType"];
node->String() = "auto";
}
void CSettingsView::on_buttonFontScalable_clicked(bool checked)
{
Settings node = settings.write["video"]["fontsType"];
node->String() = "scalable";
}
void CSettingsView::on_buttonFontOriginal_clicked(bool checked)
{
Settings node = settings.write["video"]["fontsType"];
node->String() = "original";
}

View File

@ -88,7 +88,13 @@ private slots:
void on_sliderControllerSticksSensitivity_valueChanged(int value);
void on_buttonTtfFont_toggled(bool value);
//void on_buttonTtfFont_toggled(bool value);
void on_sliderScalingFont_valueChanged(int value);
void on_buttonFontAuto_clicked(bool checked);
void on_buttonFontScalable_clicked(bool checked);
void on_buttonFontOriginal_clicked(bool checked);
private:
Ui::CSettingsView * ui;

File diff suppressed because it is too large Load Diff