forked from Mirrorlandia_minetest/minetest
Fix max_formspec_size not taking gui_scaling into account (#13493)
This commit is contained in:
parent
078bd95a49
commit
0218963f1b
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user