#include #include #include #include #include #include extern "C" { #include #include #include } #include #include "../guiparts.hpp" #include "iguielement.hpp" #include "iguiwindow.hpp" #include "iguiutil.hpp" #include "../../callbackhandeler.hpp" #include "../../../shared/lua_api/common.h" using namespace irr; using namespace gui; static bool iguiwindowevent(irr::SEvent e){ int ref = iguielements[e.GUIEvent.Caller]; lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); lua_getfield(tL,-1,"close"); lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); lua_call(tL,1,1); int shouldclose = lua_toboolean(tL,-1); return shouldclose == 1; } //new({posx,posy},{width,height},"title"[,parent]) static int newiguiwindow(lua_State* L){ IGUIElement* parent = NULL; int numargs = lua_gettop(L); if(numargs == 4){ parent = (IGUIElement*)lua_touserdata(L,-1); lua_pop(L,1); } const char* title_c = lua_tostring(L,-1); const wchar_t* title_w = irr::core::stringw(title_c).c_str(); lua_pop(L,1); //Frame position long x,y,w,h; popvector2i(L,&w,&h); popvector2i(L,&x,&y); //Create the window IGUIEnvironment* env = guidevice->getGUIEnvironment(); IGUIWindow* wi = env->addWindow( core::rect(x,y,x+w,y+h), false, title_w, parent, -1 ); lua_pushlightuserdata(L,wi); lua_newtable(L);//{} lua_pushlightuserdata(L,wi);//{},{ud_window} lua_setfield(L,-2,"element");//{element=ud_window} luaL_getmetatable(L,"gui.window");//{element=ud_window},{m_gui.window} lua_setmetatable(L,-2);//{element=ud_window, __meta=gui.window} int ref = luaL_ref(L,LUA_REGISTRYINDEX);//ref lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//ref,{element=ud_window, __meta=gui.window} iguielements[wi] = ref; registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent); return 1; } static const luaL_reg iguiwindow_m[] = { {"move", moveiguielement}, {"settext", setiguitext}, {"remove", removeiguielement}, {"getid", guigetid}, // bool :: iguiwindow:close() -- Called when window is closed, returning // -- Anything but false or nil prevents close {0, 0}, }; int iguiwindow_register(lua_State* L, IrrlichtDevice* d){ luaL_newmetatable(L,"gui.window");//m{gui.checkbox} luaL_register(L,NULL,iguiwindow_m); lua_pop(L,1);// lua_getglobal(L,"gui"); lua_pushcfunction(L,newiguiwindow); lua_setfield(L,-2,"newwindow"); lua_pop(L,1); return 0; }