From 0218963f1b45e49a1baeaa7dcf3fa34f71423d53 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall <82708541+grorp@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:42:43 +0200 Subject: [PATCH] Fix max_formspec_size not taking gui_scaling into account (#13493) --- src/client/game.cpp | 16 +--------------- src/clientdynamicinfo.h | 32 +++++++++++++++++++++++++++---- src/script/lua_api/l_mainmenu.cpp | 13 +++++-------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index c13e4aa05..c81e292e5 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -885,7 +885,6 @@ private: static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX]; f32 getSensitivityScaleFactor() const; - ClientDynamicInfo getCurrentDynamicInfo() const; InputHandler *input = nullptr; @@ -1199,7 +1198,7 @@ void Game::run() // + Sleep time until the wanted FPS are reached draw_times.limit(device, &dtime); - const auto current_dynamic_info = getCurrentDynamicInfo(); + const auto current_dynamic_info = ClientDynamicInfo::getCurrent(); if (!current_dynamic_info.equal(client_display_info)) { client_display_info = current_dynamic_info; dynamic_info_send_timer = 0.2f; @@ -2601,19 +2600,6 @@ f32 Game::getSensitivityScaleFactor() const return tan(fov_y / 2.0f) * 1.3763818698f; } -ClientDynamicInfo Game::getCurrentDynamicInfo() const -{ - v2u32 screen_size = RenderingEngine::getWindowSize(); - f32 density = RenderingEngine::getDisplayDensity(); - f32 gui_scaling = g_settings->getFloat("gui_scaling") * density; - f32 hud_scaling = g_settings->getFloat("hud_scaling") * density; - - return { - screen_size, gui_scaling, hud_scaling, - ClientDynamicInfo::calculateMaxFSSize(screen_size) - }; -} - void Game::updateCameraOrientation(CameraOrientation *cam, float dtime) { #ifdef HAVE_TOUCHSCREENGUI diff --git a/src/clientdynamicinfo.h b/src/clientdynamicinfo.h index ebe596400..c377a64f0 100644 --- a/src/clientdynamicinfo.h +++ b/src/clientdynamicinfo.h @@ -19,11 +19,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -#include "irrTypes.h" +#include "irrlichttypes_bloated.h" +#ifndef SERVER +#include "settings.h" +#include "client/renderingengine.h" +#endif struct ClientDynamicInfo { +public: v2u32 render_target_size; f32 real_gui_scaling; f32 real_hud_scaling; @@ -35,12 +40,30 @@ struct ClientDynamicInfo abs(real_hud_scaling - other.real_hud_scaling) < 0.001f; } - static v2f32 calculateMaxFSSize(v2u32 render_target_size) { +#ifndef SERVER + static ClientDynamicInfo getCurrent() { + v2u32 screen_size = RenderingEngine::getWindowSize(); + f32 density = RenderingEngine::getDisplayDensity(); + f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f); + f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f); + f32 real_gui_scaling = gui_scaling * density; + f32 real_hud_scaling = hud_scaling * density; + + return { + screen_size, real_gui_scaling, real_hud_scaling, + ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling) + }; + } +#endif + +private: +#ifndef SERVER + static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling) { f32 factor = #ifdef HAVE_TOUCHSCREENGUI - 10; + 10 / gui_scaling; #else - 15; + 15 / gui_scaling; #endif f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y; if (ratio < 1) @@ -48,4 +71,5 @@ struct ClientDynamicInfo else return { factor * ratio, factor }; } +#endif }; diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 6a9e1134c..f54ec0f4d 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -928,25 +928,22 @@ int ModApiMainMenu::l_get_window_info(lua_State *L) lua_newtable(L); int top = lua_gettop(L); - const v2u32 &window_size = RenderingEngine::getWindowSize(); - f32 density = RenderingEngine::getDisplayDensity(); - f32 gui_scaling = g_settings->getFloat("gui_scaling") * density; - f32 hud_scaling = g_settings->getFloat("hud_scaling") * density; + auto info = ClientDynamicInfo::getCurrent(); lua_pushstring(L, "size"); - push_v2u32(L, window_size); + push_v2u32(L, info.render_target_size); lua_settable(L, top); lua_pushstring(L, "max_formspec_size"); - push_v2f(L, ClientDynamicInfo::calculateMaxFSSize(window_size)); + push_v2f(L, info.max_fs_size); lua_settable(L, top); lua_pushstring(L, "real_gui_scaling"); - lua_pushnumber(L, gui_scaling); + lua_pushnumber(L, info.real_gui_scaling); lua_settable(L, top); lua_pushstring(L, "real_hud_scaling"); - lua_pushnumber(L, hud_scaling); + lua_pushnumber(L, info.real_hud_scaling); lua_settable(L, top); return 1;