diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp index a8c6d4b3e..c807d5011 100644 --- a/src/client/fontengine.cpp +++ b/src/client/fontengine.cpp @@ -18,10 +18,9 @@ /** reference to access font engine, has to be initialized by main */ FontEngine *g_fontengine = nullptr; -/** callback to be used on change of font size setting */ -static void font_setting_changed(const std::string &name, void *userdata) +void FontEngine::fontSettingChanged(const std::string &name, void *userdata) { - static_cast(userdata)->readSettings(); + ((FontEngine *)userdata)->m_needs_reload = true; } static const char *settings[] = { @@ -49,7 +48,7 @@ FontEngine::FontEngine(gui::IGUIEnvironment* env) : readSettings(); for (auto name : settings) - g_settings->registerChangedCallback(name, font_setting_changed, this); + g_settings->registerChangedCallback(name, fontSettingChanged, this); } FontEngine::~FontEngine() @@ -162,6 +161,15 @@ void FontEngine::readSettings() refresh(); } +void FontEngine::handleReload() +{ + if (!m_needs_reload) + return; + + m_needs_reload = false; + readSettings(); +} + void FontEngine::updateSkin() { gui::IGUIFont *font = getFont(); diff --git a/src/client/fontengine.h b/src/client/fontengine.h index 70713034f..0ed81f678 100644 --- a/src/client/fontengine.h +++ b/src/client/fontengine.h @@ -121,6 +121,9 @@ public: /** update internal parameters from settings */ void readSettings(); + /** reload fonts if settings were changed */ + void handleReload(); + void setMediaFont(const std::string &name, const std::string &data); void clearMediaFonts(); @@ -142,6 +145,9 @@ private: /** refresh after fonts have been changed */ void refresh(); + /** callback to be used on change of font size setting */ + static void fontSettingChanged(const std::string &name, void *userdata); + /** pointer to irrlicht gui environment */ gui::IGUIEnvironment* m_env = nullptr; @@ -164,6 +170,8 @@ private: /** default font engine mode (fixed) */ static const FontMode m_currentMode = FM_Standard; + bool m_needs_reload = false; + DISABLE_CLASS_COPY(FontEngine); }; diff --git a/src/client/game.cpp b/src/client/game.cpp index c2513fd9b..fa9beadbd 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -970,6 +970,8 @@ void Game::run() framemarker.start(); + g_fontengine->handleReload(); + const auto current_dynamic_info = ClientDynamicInfo::getCurrent(); if (!current_dynamic_info.equal(client_display_info)) { client_display_info = current_dynamic_info; diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 9402b4770..a83a913ec 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -337,6 +337,8 @@ void GUIEngine::run() fps_control.limit(device, &dtime); framemarker.start(); + g_fontengine->handleReload(); + if (device->isWindowVisible()) { // check if we need to update the "upper left corner"-text if (text_height != g_fontengine->getTextHeight()) {