diff --git a/builtin/mainmenu/tab_about.lua b/builtin/mainmenu/tab_about.lua index a84ebce3f6950..609b0cb71aa87 100644 --- a/builtin/mainmenu/tab_about.lua +++ b/builtin/mainmenu/tab_about.lua @@ -165,7 +165,7 @@ return { fs = fs .. "style[label_button2;border=false]" .. "button[0.1,6;5.3,1;label_button2;" .. fgettext("Active renderer:") .. "\n" .. - core.formspec_escape(core.get_screen_info().render_info) .. "]" + core.formspec_escape(core.get_active_renderer()) .. "]" if PLATFORM == "Android" then fs = fs .. "button[0.5,5.1;4.5,0.8;share_debug;" .. fgettext("Share debug log") .. "]" diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index ad07ea7328e8c..e8d7b6e400f02 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -203,17 +203,42 @@ GUI will be added to fieldname value is set to formname itself * if `is_file_select` is `true`, a file and not a folder will be selected * returns nil or selected file/folder -* `core.get_screen_info()` - * returns +* `core.get_active_renderer()`: Ex: "OpenGL 4.6". +* `core.get_window_info()`: Same as server-side `get_player_window_information` API. + + -- Note that none of these things are constant, they are likely to change + -- as the player resizes the window and moves it between monitors + -- + -- real_gui_scaling and real_hud_scaling can be used instead of DPI. + -- OSes don't necessarily give the physical DPI, as they may allow user configuration. + -- real_*_scaling is just OS DPI / 96 but with another level of user configuration. + { + -- Current size of the in-game render target. + -- + -- This is usually the window size, but may be smaller in certain situations, + -- such as side-by-side mode. + size = { + x = 1308, + y = 577, + }, + + -- Estimated maximum formspec size before Minetest will start shrinking the + -- formspec to fit. For a fullscreen formspec, use a size 10-20% larger than + -- this and `padding[-0.01,-0.01]`. + max_formspec_size = { + x = 20, + y = 11.25 + }, + + -- GUI Scaling multiplier + -- Equal to the setting `gui_scaling` multiplied by `dpi / 96` + real_gui_scaling = 1, + + -- HUD Scaling multiplier + -- Equal to the setting `hud_scaling` multiplied by `dpi / 96` + real_hud_scaling = 1, + } - { - density = , - display_width = , - display_height = , - window_width = , - window_height = , - render_info = - } Content and Packages diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index e53ec5fedac23..4c25d4ba1b6ae 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "network/networkprotocol.h" #include "content/mod_configuration.h" #include "threading/mutex_auto_lock.h" +#include "common/c_converter.h" /******************************************************************************/ std::string ModApiMainMenu::getTextData(lua_State *L, std::string name) @@ -922,26 +923,38 @@ int ModApiMainMenu::l_gettext(lua_State *L) } /******************************************************************************/ -int ModApiMainMenu::l_get_screen_info(lua_State *L) +int ModApiMainMenu::l_get_window_info(lua_State *L) { lua_newtable(L); int top = lua_gettop(L); - lua_pushstring(L,"density"); - lua_pushnumber(L,RenderingEngine::getDisplayDensity()); - lua_settable(L, top); const v2u32 &window_size = RenderingEngine::getWindowSize(); - lua_pushstring(L,"window_width"); - lua_pushnumber(L, window_size.X); + f32 density = RenderingEngine::getDisplayDensity(); + f32 gui_scaling = g_settings->getFloat("gui_scaling") * density; + f32 hud_scaling = g_settings->getFloat("hud_scaling") * density; + + lua_pushstring(L, "size"); + push_v2u32(L, window_size); lua_settable(L, top); - lua_pushstring(L,"window_height"); - lua_pushnumber(L, window_size.Y); + lua_pushstring(L, "max_formspec_size"); + push_v2f(L, ClientDynamicInfo::calculateMaxFSSize(window_size)); lua_settable(L, top); - lua_pushstring(L, "render_info"); - lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str()); + lua_pushstring(L, "real_gui_scaling"); + lua_pushnumber(L, gui_scaling); lua_settable(L, top); + + lua_pushstring(L, "real_hud_scaling"); + lua_pushnumber(L, hud_scaling); + lua_settable(L, top); + + return 1; +} + +int ModApiMainMenu::l_get_active_renderer(lua_State *L) +{ + lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str()); return 1; } @@ -1086,7 +1099,8 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(download_file); API_FCT(gettext); API_FCT(get_video_drivers); - API_FCT(get_screen_info); + API_FCT(get_window_info); + API_FCT(get_active_renderer); API_FCT(get_min_supp_proto); API_FCT(get_max_supp_proto); API_FCT(open_url); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index a731f77a8ea5b..bb5c93cd599f8 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -104,7 +104,9 @@ class ModApiMainMenu: public ModApiBase static int l_set_formspec_prepend(lua_State *L); - static int l_get_screen_info(lua_State *L); + static int l_get_window_info(lua_State *L); + + static int l_get_active_renderer(lua_State *L); //filesystem