Skip to content

Commit

Permalink
Add to main menu API
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Jan 8, 2023
1 parent 73d538a commit 1611add
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion builtin/mainmenu/tab_about.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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") .. "]"
Expand Down
45 changes: 35 additions & 10 deletions doc/menu_lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
display_width = <width of display>,
display_height = <height of display>,
window_width = <current window width>,
window_height = <current window height>,
render_info = <active render information>
}


Content and Packages
Expand Down
36 changes: 25 additions & 11 deletions src/script/lua_api/l_mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/script/lua_api/l_mainmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1611add

Please sign in to comment.