mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
parent
7a64527db5
commit
a9cca5e76c
12 changed files with 84 additions and 47 deletions
|
@ -69,6 +69,7 @@ static void dump_start_data(const GameStartData &data)
|
|||
ClientLauncher::~ClientLauncher()
|
||||
{
|
||||
delete input;
|
||||
g_settings->deregisterChangedCallback("dpi_change_notifier", setting_changed_callback, this);
|
||||
g_settings->deregisterChangedCallback("gui_scaling", setting_changed_callback, this);
|
||||
|
||||
delete g_fontengine;
|
||||
|
@ -129,6 +130,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("gui_scaling", setting_changed_callback, this);
|
||||
|
||||
g_fontengine = new FontEngine(guienv);
|
||||
|
|
|
@ -59,7 +59,7 @@ FontEngine::FontEngine(gui::IGUIEnvironment* env) :
|
|||
"mono_font_path", "mono_font_path_bold", "mono_font_path_italic",
|
||||
"mono_font_path_bold_italic",
|
||||
"fallback_font_path",
|
||||
"screen_dpi", "gui_scaling",
|
||||
"dpi_change_notifier", "gui_scaling",
|
||||
};
|
||||
|
||||
for (auto name : settings)
|
||||
|
|
|
@ -60,6 +60,7 @@ Hud::Hud(Client *client, LocalPlayer *player,
|
|||
this->inventory = inventory;
|
||||
|
||||
readScalingSetting();
|
||||
g_settings->registerChangedCallback("dpi_change_notifier", setting_changed_callback, this);
|
||||
g_settings->registerChangedCallback("hud_scaling", setting_changed_callback, this);
|
||||
|
||||
for (auto &hbar_color : hbar_colors)
|
||||
|
@ -153,6 +154,7 @@ void Hud::readScalingSetting()
|
|||
|
||||
Hud::~Hud()
|
||||
{
|
||||
g_settings->deregisterChangedCallback("dpi_change_notifier", setting_changed_callback, this);
|
||||
g_settings->deregisterChangedCallback("hud_scaling", setting_changed_callback, this);
|
||||
|
||||
if (m_selection_mesh)
|
||||
|
|
|
@ -113,6 +113,15 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (event.EventType == EET_APPLICATION_EVENT &&
|
||||
event.ApplicationEvent.EventType == EAET_DPI_CHANGED) {
|
||||
// This is a fake setting so that we can use (de)registerChangedCallback
|
||||
// not only to listen for gui/hud_scaling changes, but also for DPI changes.
|
||||
g_settings->setU16("dpi_change_notifier",
|
||||
g_settings->getU16("dpi_change_notifier") + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is separate from other keyboard handling so that it also works in menus.
|
||||
if (event.EventType == EET_KEY_INPUT_EVENT) {
|
||||
const KeyPress keyCode(event.KeyInput);
|
||||
|
|
|
@ -462,18 +462,14 @@ const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_
|
|||
|
||||
float RenderingEngine::getDisplayDensity()
|
||||
{
|
||||
float user_factor = g_settings->getFloat("display_density_factor", 0.5f, 5.0f);
|
||||
#ifndef __ANDROID__
|
||||
static float cached_display_density = [&] {
|
||||
float dpi = get_raw_device()->getDisplayDensity();
|
||||
// fall back to manually specified dpi
|
||||
if (dpi == 0.0f)
|
||||
dpi = g_settings->getFloat("screen_dpi");
|
||||
return dpi / 96.0f;
|
||||
}();
|
||||
return std::max(cached_display_density * g_settings->getFloat("display_density_factor"), 0.5f);
|
||||
|
||||
float dpi = get_raw_device()->getDisplayDensity();
|
||||
if (dpi == 0.0f)
|
||||
dpi = 96.0f;
|
||||
return std::max(dpi / 96.0f * user_factor, 0.5f);
|
||||
#else // __ANDROID__
|
||||
return porting::getDisplayDensity();
|
||||
return porting::getDisplayDensity() * user_factor;
|
||||
#endif // __ANDROID__
|
||||
}
|
||||
|
||||
|
|
|
@ -536,8 +536,8 @@ void set_default_settings()
|
|||
settings->setDefault("server_description", "");
|
||||
|
||||
settings->setDefault("enable_console", "false");
|
||||
settings->setDefault("screen_dpi", "72");
|
||||
settings->setDefault("display_density_factor", "1");
|
||||
settings->setDefault("dpi_change_notifier", "0");
|
||||
|
||||
// Altered settings for macOS
|
||||
#if defined(__MACH__) && defined(__APPLE__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue