From 5532248cd739355201a043b0064c9509dca16dfd Mon Sep 17 00:00:00 2001 From: grorp Date: Sat, 12 Oct 2024 22:34:39 +0200 Subject: [PATCH] Add missing setting callbacks for display_density_factor (#15273) --- src/client/clientlauncher.cpp | 2 ++ src/client/fontengine.cpp | 30 ++++++++++++++++-------------- src/client/hud.cpp | 2 ++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index e99fbff42..13b87f2ef 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -72,6 +72,7 @@ ClientLauncher::~ClientLauncher() { delete input; g_settings->deregisterChangedCallback("dpi_change_notifier", setting_changed_callback, this); + g_settings->deregisterChangedCallback("display_density_factor", setting_changed_callback, this); g_settings->deregisterChangedCallback("gui_scaling", setting_changed_callback, this); delete g_fontengine; @@ -133,6 +134,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) guienv = m_rendering_engine->get_gui_env(); config_guienv(); g_settings->registerChangedCallback("dpi_change_notifier", setting_changed_callback, this); + g_settings->registerChangedCallback("display_density_factor", setting_changed_callback, this); g_settings->registerChangedCallback("gui_scaling", setting_changed_callback, this); g_fontengine = new FontEngine(guienv); diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp index e0174e011..5475e9768 100644 --- a/src/client/fontengine.cpp +++ b/src/client/fontengine.cpp @@ -33,10 +33,20 @@ 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) { - if (g_fontengine) - g_fontengine->readSettings(); + static_cast(userdata)->readSettings(); } +static const char *settings[] = { + "font_size", "font_bold", "font_italic", "font_size_divisible_by", + "mono_font_size", "mono_font_size_divisible_by", + "font_shadow", "font_shadow_alpha", + "font_path", "font_path_bold", "font_path_italic", "font_path_bold_italic", + "mono_font_path", "mono_font_path_bold", "mono_font_path_italic", + "mono_font_path_bold_italic", + "fallback_font_path", + "dpi_change_notifier", "display_density_factor", "gui_scaling", +}; + /******************************************************************************/ FontEngine::FontEngine(gui::IGUIEnvironment* env) : m_env(env) @@ -51,24 +61,16 @@ FontEngine::FontEngine(gui::IGUIEnvironment* env) : readSettings(); - const char *settings[] = { - "font_size", "font_bold", "font_italic", "font_size_divisible_by", - "mono_font_size", "mono_font_size_divisible_by", - "font_shadow", "font_shadow_alpha", - "font_path", "font_path_bold", "font_path_italic", "font_path_bold_italic", - "mono_font_path", "mono_font_path_bold", "mono_font_path_italic", - "mono_font_path_bold_italic", - "fallback_font_path", - "dpi_change_notifier", "gui_scaling", - }; - for (auto name : settings) - g_settings->registerChangedCallback(name, font_setting_changed, NULL); + g_settings->registerChangedCallback(name, font_setting_changed, this); } /******************************************************************************/ FontEngine::~FontEngine() { + for (auto name : settings) + g_settings->deregisterChangedCallback(name, font_setting_changed, this); + cleanCache(); } diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 3f3984d48..29fc31ffa 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -61,6 +61,7 @@ Hud::Hud(Client *client, LocalPlayer *player, readScalingSetting(); g_settings->registerChangedCallback("dpi_change_notifier", setting_changed_callback, this); + g_settings->registerChangedCallback("display_density_factor", setting_changed_callback, this); g_settings->registerChangedCallback("hud_scaling", setting_changed_callback, this); for (auto &hbar_color : hbar_colors) @@ -170,6 +171,7 @@ void Hud::readScalingSetting() Hud::~Hud() { g_settings->deregisterChangedCallback("dpi_change_notifier", setting_changed_callback, this); + g_settings->deregisterChangedCallback("display_density_factor", setting_changed_callback, this); g_settings->deregisterChangedCallback("hud_scaling", setting_changed_callback, this); if (m_selection_mesh)