Skip to content

Commit 0218963

Browse files
authored
Fix max_formspec_size not taking gui_scaling into account (luanti-org#13493)
1 parent 078bd95 commit 0218963

3 files changed

Lines changed: 34 additions & 27 deletions

File tree

src/client/game.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ class Game {
885885
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
886886

887887
f32 getSensitivityScaleFactor() const;
888-
ClientDynamicInfo getCurrentDynamicInfo() const;
889888

890889
InputHandler *input = nullptr;
891890

@@ -1199,7 +1198,7 @@ void Game::run()
11991198
// + Sleep time until the wanted FPS are reached
12001199
draw_times.limit(device, &dtime);
12011200

1202-
const auto current_dynamic_info = getCurrentDynamicInfo();
1201+
const auto current_dynamic_info = ClientDynamicInfo::getCurrent();
12031202
if (!current_dynamic_info.equal(client_display_info)) {
12041203
client_display_info = current_dynamic_info;
12051204
dynamic_info_send_timer = 0.2f;
@@ -2601,19 +2600,6 @@ f32 Game::getSensitivityScaleFactor() const
26012600
return tan(fov_y / 2.0f) * 1.3763818698f;
26022601
}
26032602

2604-
ClientDynamicInfo Game::getCurrentDynamicInfo() const
2605-
{
2606-
v2u32 screen_size = RenderingEngine::getWindowSize();
2607-
f32 density = RenderingEngine::getDisplayDensity();
2608-
f32 gui_scaling = g_settings->getFloat("gui_scaling") * density;
2609-
f32 hud_scaling = g_settings->getFloat("hud_scaling") * density;
2610-
2611-
return {
2612-
screen_size, gui_scaling, hud_scaling,
2613-
ClientDynamicInfo::calculateMaxFSSize(screen_size)
2614-
};
2615-
}
2616-
26172603
void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
26182604
{
26192605
#ifdef HAVE_TOUCHSCREENGUI

src/clientdynamicinfo.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#pragma once
2121

22-
#include "irrTypes.h"
22+
#include "irrlichttypes_bloated.h"
23+
#ifndef SERVER
24+
#include "settings.h"
25+
#include "client/renderingengine.h"
26+
#endif
2327

2428

2529
struct ClientDynamicInfo
2630
{
31+
public:
2732
v2u32 render_target_size;
2833
f32 real_gui_scaling;
2934
f32 real_hud_scaling;
@@ -35,17 +40,36 @@ struct ClientDynamicInfo
3540
abs(real_hud_scaling - other.real_hud_scaling) < 0.001f;
3641
}
3742

38-
static v2f32 calculateMaxFSSize(v2u32 render_target_size) {
43+
#ifndef SERVER
44+
static ClientDynamicInfo getCurrent() {
45+
v2u32 screen_size = RenderingEngine::getWindowSize();
46+
f32 density = RenderingEngine::getDisplayDensity();
47+
f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
48+
f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
49+
f32 real_gui_scaling = gui_scaling * density;
50+
f32 real_hud_scaling = hud_scaling * density;
51+
52+
return {
53+
screen_size, real_gui_scaling, real_hud_scaling,
54+
ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling)
55+
};
56+
}
57+
#endif
58+
59+
private:
60+
#ifndef SERVER
61+
static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling) {
3962
f32 factor =
4063
#ifdef HAVE_TOUCHSCREENGUI
41-
10;
64+
10 / gui_scaling;
4265
#else
43-
15;
66+
15 / gui_scaling;
4467
#endif
4568
f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y;
4669
if (ratio < 1)
4770
return { factor, factor / ratio };
4871
else
4972
return { factor * ratio, factor };
5073
}
74+
#endif
5175
};

src/script/lua_api/l_mainmenu.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -928,25 +928,22 @@ int ModApiMainMenu::l_get_window_info(lua_State *L)
928928
lua_newtable(L);
929929
int top = lua_gettop(L);
930930

931-
const v2u32 &window_size = RenderingEngine::getWindowSize();
932-
f32 density = RenderingEngine::getDisplayDensity();
933-
f32 gui_scaling = g_settings->getFloat("gui_scaling") * density;
934-
f32 hud_scaling = g_settings->getFloat("hud_scaling") * density;
931+
auto info = ClientDynamicInfo::getCurrent();
935932

936933
lua_pushstring(L, "size");
937-
push_v2u32(L, window_size);
934+
push_v2u32(L, info.render_target_size);
938935
lua_settable(L, top);
939936

940937
lua_pushstring(L, "max_formspec_size");
941-
push_v2f(L, ClientDynamicInfo::calculateMaxFSSize(window_size));
938+
push_v2f(L, info.max_fs_size);
942939
lua_settable(L, top);
943940

944941
lua_pushstring(L, "real_gui_scaling");
945-
lua_pushnumber(L, gui_scaling);
942+
lua_pushnumber(L, info.real_gui_scaling);
946943
lua_settable(L, top);
947944

948945
lua_pushstring(L, "real_hud_scaling");
949-
lua_pushnumber(L, hud_scaling);
946+
lua_pushnumber(L, info.real_hud_scaling);
950947
lua_settable(L, top);
951948

952949
return 1;

0 commit comments

Comments
 (0)