Add Lua function get_video_modes() for main menu
authorCraig Robbins <kde.psych@gmail.com>
Sat, 28 Mar 2015 01:05:39 +0000 (11:05 +1000)
committerCraig Robbins <kde.psych@gmail.com>
Sat, 28 Mar 2015 03:26:03 +0000 (13:26 +1000)
Also updates and uses porting::getSupportedVideoModes()

src/porting.cpp
src/porting.h
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_mainmenu.h

index 5b0de1305e41628f76f277011b79456ca7bc647e..797a2cf39e846a9ed5e7ab446d37f4f356523d83 100644 (file)
@@ -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;
 }
 
index 3d26775643de69c2aeac78a5e9dca3984cc90c56..ddb56cf7d3852a8fe0bfdb042fff526f0ca7e879 100644 (file)
@@ -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);
index f905080128ce9cfc07bd97155ef681d056185f40..22fc176bf89a08c2d7d760dc045d5229430fb7ad 100644 (file)
@@ -1056,6 +1056,28 @@ int ModApiMainMenu::l_get_video_drivers(lua_State *L)
        return 1;
 }
 
+/******************************************************************************/
+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)
 {
@@ -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);
index 8b21a93aa08f9d2826d90c9cd15a93f9e8ea2ef7..9c1fed272d7c7706be59e38a6803093849c7ceb6 100644 (file)
@@ -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);