Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix max_formspec_size not taking gui_scaling into account #13493

Merged
merged 5 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,6 @@ class Game {
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];

f32 getSensitivityScaleFactor() const;
ClientDynamicInfo getCurrentDynamicInfo() const;

InputHandler *input = nullptr;

Expand Down Expand Up @@ -1209,7 +1208,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;
Expand Down Expand Up @@ -2590,19 +2589,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
Expand Down
32 changes: 28 additions & 4 deletions src/clientdynamicinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,17 +40,36 @@ 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)
return { factor, factor / ratio };
else
return { factor * ratio, factor };
}
#endif
};
13 changes: 5 additions & 8 deletions src/script/lua_api/l_mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down