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 3 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();
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
28 changes: 25 additions & 3 deletions src/clientdynamicinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,49 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once

#include "irrTypes.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;
v2f32 max_fs_size;

#ifndef SERVER
static const ClientDynamicInfo getCurrent() {
Desour marked this conversation as resolved.
Show resolved Hide resolved
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

bool equal(const ClientDynamicInfo &other) const {
return render_target_size == other.render_target_size &&
abs(real_gui_scaling - other.real_gui_scaling) < 0.001f &&
abs(real_hud_scaling - other.real_hud_scaling) < 0.001f;
}

static v2f32 calculateMaxFSSize(v2u32 render_target_size) {
private:
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)
Expand Down
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