mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Settings: Purge getDefault, clean FontEngine
This commit is contained in:
parent
37a05ec8d6
commit
2760371d8e
@ -175,7 +175,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
g_fontengine = new FontEngine(g_settings, guienv);
|
g_fontengine = new FontEngine(guienv);
|
||||||
FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed.");
|
FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed.");
|
||||||
|
|
||||||
#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
|
#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
|
||||||
|
@ -42,8 +42,7 @@ static void font_setting_changed(const std::string &name, void *userdata)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
FontEngine::FontEngine(Settings* main_settings, gui::IGUIEnvironment* env) :
|
FontEngine::FontEngine(gui::IGUIEnvironment* env) :
|
||||||
m_settings(main_settings),
|
|
||||||
m_env(env)
|
m_env(env)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -51,34 +50,34 @@ FontEngine::FontEngine(Settings* main_settings, gui::IGUIEnvironment* env) :
|
|||||||
i = (FontMode) FONT_SIZE_UNSPECIFIED;
|
i = (FontMode) FONT_SIZE_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(m_settings != NULL); // pre-condition
|
assert(g_settings != NULL); // pre-condition
|
||||||
assert(m_env != NULL); // pre-condition
|
assert(m_env != NULL); // pre-condition
|
||||||
assert(m_env->getSkin() != NULL); // pre-condition
|
assert(m_env->getSkin() != NULL); // pre-condition
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|
||||||
if (m_currentMode == FM_Standard) {
|
if (m_currentMode == FM_Standard) {
|
||||||
m_settings->registerChangedCallback("font_size", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_size", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_bold", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_bold", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_italic", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_italic", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_path", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_path", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_path_bold", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_path_bold", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_path_italic", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_path_italic", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_path_bolditalic", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_path_bolditalic", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_shadow", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_shadow", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("font_shadow_alpha", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("font_shadow_alpha", font_setting_changed, NULL);
|
||||||
}
|
}
|
||||||
else if (m_currentMode == FM_Fallback) {
|
else if (m_currentMode == FM_Fallback) {
|
||||||
m_settings->registerChangedCallback("fallback_font_size", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("fallback_font_size", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("fallback_font_path", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("fallback_font_path", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("fallback_font_shadow", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("fallback_font_shadow", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("fallback_font_shadow_alpha", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("fallback_font_shadow_alpha", font_setting_changed, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_settings->registerChangedCallback("mono_font_path", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("mono_font_path", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("mono_font_size", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("mono_font_size", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("screen_dpi", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("screen_dpi", font_setting_changed, NULL);
|
||||||
m_settings->registerChangedCallback("gui_scaling", font_setting_changed, NULL);
|
g_settings->registerChangedCallback("gui_scaling", font_setting_changed, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -205,9 +204,9 @@ unsigned int FontEngine::getFontSize(FontMode mode)
|
|||||||
void FontEngine::readSettings()
|
void FontEngine::readSettings()
|
||||||
{
|
{
|
||||||
if (USE_FREETYPE && g_settings->getBool("freetype")) {
|
if (USE_FREETYPE && g_settings->getBool("freetype")) {
|
||||||
m_default_size[FM_Standard] = m_settings->getU16("font_size");
|
m_default_size[FM_Standard] = g_settings->getU16("font_size");
|
||||||
m_default_size[FM_Fallback] = m_settings->getU16("fallback_font_size");
|
m_default_size[FM_Fallback] = g_settings->getU16("fallback_font_size");
|
||||||
m_default_size[FM_Mono] = m_settings->getU16("mono_font_size");
|
m_default_size[FM_Mono] = g_settings->getU16("mono_font_size");
|
||||||
|
|
||||||
/*~ DO NOT TRANSLATE THIS LITERALLY!
|
/*~ DO NOT TRANSLATE THIS LITERALLY!
|
||||||
This is a special string. Put either "no" or "yes"
|
This is a special string. Put either "no" or "yes"
|
||||||
@ -220,15 +219,15 @@ void FontEngine::readSettings()
|
|||||||
m_currentMode = is_yes(gettext("needs_fallback_font")) ?
|
m_currentMode = is_yes(gettext("needs_fallback_font")) ?
|
||||||
FM_Fallback : FM_Standard;
|
FM_Fallback : FM_Standard;
|
||||||
|
|
||||||
m_default_bold = m_settings->getBool("font_bold");
|
m_default_bold = g_settings->getBool("font_bold");
|
||||||
m_default_italic = m_settings->getBool("font_italic");
|
m_default_italic = g_settings->getBool("font_italic");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m_currentMode = FM_Simple;
|
m_currentMode = FM_Simple;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_default_size[FM_Simple] = m_settings->getU16("font_size");
|
m_default_size[FM_Simple] = g_settings->getU16("font_size");
|
||||||
m_default_size[FM_SimpleMono] = m_settings->getU16("mono_font_size");
|
m_default_size[FM_SimpleMono] = g_settings->getU16("mono_font_size");
|
||||||
|
|
||||||
cleanCache();
|
cleanCache();
|
||||||
updateFontCache();
|
updateFontCache();
|
||||||
@ -244,7 +243,7 @@ void FontEngine::updateSkin()
|
|||||||
m_env->getSkin()->setFont(font);
|
m_env->getSkin()->setFont(font);
|
||||||
else
|
else
|
||||||
errorstream << "FontEngine: Default font file: " <<
|
errorstream << "FontEngine: Default font file: " <<
|
||||||
"\n\t\"" << m_settings->get("font_path") << "\"" <<
|
"\n\t\"" << g_settings->get("font_path") << "\"" <<
|
||||||
"\n\trequired for current screen configuration was not found" <<
|
"\n\trequired for current screen configuration was not found" <<
|
||||||
" or was invalid file format." <<
|
" or was invalid file format." <<
|
||||||
"\n\tUsing irrlicht default font." << std::endl;
|
"\n\tUsing irrlicht default font." << std::endl;
|
||||||
@ -292,7 +291,7 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
|
|||||||
setting_suffix.append("_italic");
|
setting_suffix.append("_italic");
|
||||||
|
|
||||||
u32 size = std::floor(RenderingEngine::getDisplayDensity() *
|
u32 size = std::floor(RenderingEngine::getDisplayDensity() *
|
||||||
m_settings->getFloat("gui_scaling") * spec.size);
|
g_settings->getFloat("gui_scaling") * spec.size);
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
errorstream << "FontEngine: attempt to use font size 0" << std::endl;
|
errorstream << "FontEngine: attempt to use font size 0" << std::endl;
|
||||||
@ -311,8 +310,8 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
|
|||||||
|
|
||||||
std::string fallback_settings[] = {
|
std::string fallback_settings[] = {
|
||||||
wanted_font_path,
|
wanted_font_path,
|
||||||
m_settings->get("fallback_font_path"),
|
g_settings->get("fallback_font_path"),
|
||||||
m_settings->getDefault(setting_prefix + "font_path")
|
Settings::getLayer(SL_DEFAULTS)->get(setting_prefix + "font_path")
|
||||||
};
|
};
|
||||||
|
|
||||||
#if USE_FREETYPE
|
#if USE_FREETYPE
|
||||||
@ -346,7 +345,7 @@ gui::IGUIFont *FontEngine::initSimpleFont(const FontSpec &spec)
|
|||||||
assert(spec.mode == FM_Simple || spec.mode == FM_SimpleMono);
|
assert(spec.mode == FM_Simple || spec.mode == FM_SimpleMono);
|
||||||
assert(spec.size != FONT_SIZE_UNSPECIFIED);
|
assert(spec.size != FONT_SIZE_UNSPECIFIED);
|
||||||
|
|
||||||
const std::string &font_path = m_settings->get(
|
const std::string &font_path = g_settings->get(
|
||||||
(spec.mode == FM_SimpleMono) ? "mono_font_path" : "font_path");
|
(spec.mode == FM_SimpleMono) ? "mono_font_path" : "font_path");
|
||||||
|
|
||||||
size_t pos_dot = font_path.find_last_of('.');
|
size_t pos_dot = font_path.find_last_of('.');
|
||||||
@ -364,7 +363,7 @@ gui::IGUIFont *FontEngine::initSimpleFont(const FontSpec &spec)
|
|||||||
|
|
||||||
u32 size = std::floor(
|
u32 size = std::floor(
|
||||||
RenderingEngine::getDisplayDensity() *
|
RenderingEngine::getDisplayDensity() *
|
||||||
m_settings->getFloat("gui_scaling") *
|
g_settings->getFloat("gui_scaling") *
|
||||||
spec.size);
|
spec.size);
|
||||||
|
|
||||||
irr::gui::IGUIFont *font = nullptr;
|
irr::gui::IGUIFont *font = nullptr;
|
||||||
|
@ -62,7 +62,7 @@ class FontEngine
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FontEngine(Settings* main_settings, gui::IGUIEnvironment* env);
|
FontEngine(gui::IGUIEnvironment* env);
|
||||||
|
|
||||||
~FontEngine();
|
~FontEngine();
|
||||||
|
|
||||||
@ -128,9 +128,6 @@ public:
|
|||||||
/** get font size for a specific mode */
|
/** get font size for a specific mode */
|
||||||
unsigned int getFontSize(FontMode mode);
|
unsigned int getFontSize(FontMode mode);
|
||||||
|
|
||||||
/** initialize font engine */
|
|
||||||
void initialize(Settings* main_settings, gui::IGUIEnvironment* env);
|
|
||||||
|
|
||||||
/** update internal parameters from settings */
|
/** update internal parameters from settings */
|
||||||
void readSettings();
|
void readSettings();
|
||||||
|
|
||||||
@ -150,9 +147,6 @@ private:
|
|||||||
/** clean cache */
|
/** clean cache */
|
||||||
void cleanCache();
|
void cleanCache();
|
||||||
|
|
||||||
/** pointer to settings for registering callbacks or reading config */
|
|
||||||
Settings* m_settings = nullptr;
|
|
||||||
|
|
||||||
/** pointer to irrlicht gui environment */
|
/** pointer to irrlicht gui environment */
|
||||||
gui::IGUIEnvironment* m_env = nullptr;
|
gui::IGUIEnvironment* m_env = nullptr;
|
||||||
|
|
||||||
|
@ -527,7 +527,6 @@ static bool read_config_file(const Settings &cmd_args)
|
|||||||
// Path of configuration file in use
|
// Path of configuration file in use
|
||||||
sanity_check(g_settings_path == ""); // Sanity check
|
sanity_check(g_settings_path == ""); // Sanity check
|
||||||
|
|
||||||
|
|
||||||
if (cmd_args.exists("config")) {
|
if (cmd_args.exists("config")) {
|
||||||
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
|
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
|
||||||
if (!r) {
|
if (!r) {
|
||||||
|
@ -31,7 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#include "lualib.h"
|
#include "lualib.h"
|
||||||
}
|
}
|
||||||
#include "settings.h"
|
|
||||||
#define MAINMENU_NUM_ASYNC_THREADS 4
|
#define MAINMENU_NUM_ASYNC_THREADS 4
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
Settings *g_settings = nullptr;
|
Settings *g_settings = nullptr; // Populated in main()
|
||||||
std::string g_settings_path;
|
std::string g_settings_path;
|
||||||
|
|
||||||
Settings *Settings::s_layers[SL_TOTAL_COUNT] = {0}; // Zeroed by compiler
|
Settings *Settings::s_layers[SL_TOTAL_COUNT] = {0}; // Zeroed by compiler
|
||||||
@ -85,6 +85,7 @@ Settings & Settings::operator = (const Settings &other)
|
|||||||
if (&other == this)
|
if (&other == this)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
|
// TODO: Avoid copying Settings objects. Make this private.
|
||||||
FATAL_ERROR_IF(m_settingslayer != SL_TOTAL_COUNT && other.m_settingslayer != SL_TOTAL_COUNT,
|
FATAL_ERROR_IF(m_settingslayer != SL_TOTAL_COUNT && other.m_settingslayer != SL_TOTAL_COUNT,
|
||||||
("Tried to copy unique Setting layer " + std::to_string(m_settingslayer)).c_str());
|
("Tried to copy unique Setting layer " + std::to_string(m_settingslayer)).c_str());
|
||||||
|
|
||||||
@ -208,6 +209,7 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const
|
|||||||
for (const auto &setting_it : m_settings)
|
for (const auto &setting_it : m_settings)
|
||||||
printEntry(os, setting_it.first, setting_it.second, tab_depth);
|
printEntry(os, setting_it.first, setting_it.second, tab_depth);
|
||||||
|
|
||||||
|
// For groups this must be "}" !
|
||||||
if (!m_end_tag.empty()) {
|
if (!m_end_tag.empty()) {
|
||||||
for (u32 i = 0; i < tab_depth; i++)
|
for (u32 i = 0; i < tab_depth; i++)
|
||||||
os << "\t";
|
os << "\t";
|
||||||
@ -458,20 +460,6 @@ const std::string &Settings::get(const std::string &name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string &Settings::getDefault(const std::string &name) const
|
|
||||||
{
|
|
||||||
const SettingsEntry *entry;
|
|
||||||
if (auto parent = getParent())
|
|
||||||
entry = &parent->getEntry(name);
|
|
||||||
else
|
|
||||||
entry = &getEntry(name); // Bottom of the chain
|
|
||||||
|
|
||||||
if (entry->is_group)
|
|
||||||
throw SettingNotFoundException("Setting [" + name + "] is a group.");
|
|
||||||
return entry->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Settings::getBool(const std::string &name) const
|
bool Settings::getBool(const std::string &name) const
|
||||||
{
|
{
|
||||||
return is_yes(get(name));
|
return is_yes(get(name));
|
||||||
|
@ -132,7 +132,6 @@ public:
|
|||||||
|
|
||||||
Settings *getGroup(const std::string &name) const;
|
Settings *getGroup(const std::string &name) const;
|
||||||
const std::string &get(const std::string &name) const;
|
const std::string &get(const std::string &name) const;
|
||||||
const std::string &getDefault(const std::string &name) const;
|
|
||||||
bool getBool(const std::string &name) const;
|
bool getBool(const std::string &name) const;
|
||||||
u16 getU16(const std::string &name) const;
|
u16 getU16(const std::string &name) const;
|
||||||
s16 getS16(const std::string &name) const;
|
s16 getS16(const std::string &name) const;
|
||||||
|
@ -229,7 +229,7 @@ void TestSettings::testAllSettings()
|
|||||||
// Confirm settings
|
// Confirm settings
|
||||||
Settings s2("[dummy_eof_end_tag]");
|
Settings s2("[dummy_eof_end_tag]");
|
||||||
std::istringstream is(config_text_after, std::ios_base::binary);
|
std::istringstream is(config_text_after, std::ios_base::binary);
|
||||||
s2.parseConfigLines(is);
|
UASSERT(s2.parseConfigLines(is) == true);
|
||||||
|
|
||||||
compare_settings("(main)", &s, &s2);
|
compare_settings("(main)", &s, &s2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user