summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-03-28 11:05:39 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-03-28 13:26:03 +1000
commit2430b2e9981a56a4c407dc835ee74e7862e785f3 (patch)
treec4d580982780c4b4ad5de6b2d6221a367d3e23c0
parent3ef0b4e6379944ec7e3ccbfc7fe26ab7f9158fc9 (diff)
downloadminetest-2430b2e9981a56a4c407dc835ee74e7862e785f3.tar.gz
minetest-2430b2e9981a56a4c407dc835ee74e7862e785f3.tar.bz2
minetest-2430b2e9981a56a4c407dc835ee74e7862e785f3.zip
Add Lua function get_video_modes() for main menu
Also updates and uses porting::getSupportedVideoModes()
-rw-r--r--src/porting.cpp10
-rw-r--r--src/porting.h1
-rw-r--r--src/script/lua_api/l_mainmenu.cpp23
-rw-r--r--src/script/lua_api/l_mainmenu.h2
4 files changed, 34 insertions, 2 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index 5b0de1305..797a2cf39 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -570,16 +570,20 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
}
#ifndef SERVER
+
v2u32 getWindowSize()
{
return device->getVideoDriver()->getScreenSize();
}
-std::vector<core::vector3d<u32> > getVideoModes()
+std::vector<core::vector3d<u32> > getSupportedVideoModes()
{
+ IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
+ sanity_check(nulldevice != NULL);
+
std::vector<core::vector3d<u32> > mlist;
- video::IVideoModeList *modelist = device->getVideoModeList();
+ video::IVideoModeList *modelist = nulldevice->getVideoModeList();
u32 num_modes = modelist->getVideoModeCount();
for (u32 i = 0; i != num_modes; i++) {
@@ -588,6 +592,8 @@ std::vector<core::vector3d<u32> > getVideoModes()
mlist.push_back(core::vector3d<u32>(mode_res.Width, mode_res.Height, mode_depth));
}
+ nulldevice->drop();
+
return mlist;
}
diff --git a/src/porting.h b/src/porting.h
index 3d2677564..ddb56cf7d 100644
--- a/src/porting.h
+++ b/src/porting.h
@@ -371,6 +371,7 @@ float getDisplayDensity();
v2u32 getDisplaySize();
v2u32 getWindowSize();
+std::vector<core::vector3d<u32> > getSupportedVideoModes();
std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index f90508012..22fc176bf 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -1057,6 +1057,28 @@ int ModApiMainMenu::l_get_video_drivers(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_get_video_modes(lua_State *L)
+{
+ std::vector<core::vector3d<u32> > videomodes
+ = porting::getSupportedVideoModes();
+
+ lua_newtable(L);
+ for (u32 i = 0; i != videomodes.size(); i++) {
+ lua_newtable(L);
+ lua_pushnumber(L, videomodes[i].X);
+ lua_setfield(L, -2, "w");
+ lua_pushnumber(L, videomodes[i].Y);
+ lua_setfield(L, -2, "h");
+ lua_pushnumber(L, videomodes[i].Z);
+ lua_setfield(L, -2, "depth");
+
+ lua_rawseti(L, -2, i + 1);
+ }
+
+ return 1;
+}
+
+/******************************************************************************/
int ModApiMainMenu::l_gettext(lua_State *L)
{
std::wstring wtext = wstrgettext((std::string) luaL_checkstring(L, 1));
@@ -1164,6 +1186,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(sound_stop);
API_FCT(gettext);
API_FCT(get_video_drivers);
+ API_FCT(get_video_modes);
API_FCT(get_screen_info);
API_FCT(get_min_supp_proto);
API_FCT(get_max_supp_proto);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index 8b21a93aa..9c1fed272 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -137,6 +137,8 @@ private:
static int l_get_video_drivers(lua_State *L);
+ static int l_get_video_modes(lua_State *L);
+
//version compatibility
static int l_get_min_supp_proto(lua_State *L);