aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/gui/iguiwindow.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-06-23 06:52:55 -0600
committerAlexander Pickering <alex@cogarr.net>2018-06-23 06:52:55 -0600
commite6faff1394864a1fe0d517584d1c104997dff39f (patch)
treed7956fc8aabef903f354578d69d4d7fdf64ec928 /src/client/lua_api/gui/iguiwindow.cpp
parent1aaa348ac080c97c0aeb0a02146ae26b74add5a1 (diff)
parent9fa5dcc9310a8c6ff8c77a47a86303f7b950dcf3 (diff)
downloadbrokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.gz
brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.bz2
brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.zip
Merge branch 'master' of ssh://cogarr.net:43/home/git/brokengine
Diffstat (limited to 'src/client/lua_api/gui/iguiwindow.cpp')
-rw-r--r--src/client/lua_api/gui/iguiwindow.cpp80
1 files changed, 29 insertions, 51 deletions
diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp
index 9a42dff..150ba68 100644
--- a/src/client/lua_api/gui/iguiwindow.cpp
+++ b/src/client/lua_api/gui/iguiwindow.cpp
@@ -20,82 +20,59 @@ extern "C" {
using namespace irr;
using namespace gui;
-//IrrlichtDevice* guidevice;
-
-static LIGUIElement* checkiguiwindow(lua_State* L, int index){
- void* ud = luaL_checkudata(L,index,"gui.iguiwindow");
- luaL_argcheck(L,ud != NULL, index, "'gui.iguiwindow' expected");
- return (LIGUIElement*) ud;
-}
+static bool iguiwindowevent(irr::SEvent e){
+ int ref = iguielements[e.GUIEvent.Caller];
+ lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
+ lua_getfield(tL,-1,"close");
-static LIGUIElement* checkiguiwindow(lua_State* L){
- return checkiguiwindow(L,1);
-}
+ lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
+ lua_call(tL,1,1);
-static bool iguiwindowevent(irr::SEvent e){
- IGUIElement* caller = (IGUIElement*)e.GUIEvent.Caller;
- int ref = iguielements[caller];
- EGUI_EVENT_TYPE etype = e.GUIEvent.EventType;
- printf("Detected window event\n");
- if(etype == EGET_ELEMENT_CLOSED){
- lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
- printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1));
- LIGUIElement* tbut = checkiguiwindow(tL,-1);
- int hashmapresponse;
- char* hashkey = (char*)"onclose";
- int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse);
- if(terror == MAP_OK){ //Only call if we actually have that function.
- printf("Looks like we have an onclose function, calling!\n");
- lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function
- lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement
- lua_call(tL,1,1);
- //int b = lua_isnoneornil(tL,1);
- int a = lua_toboolean(tL,-1);
- printf("a:%d\n",a);
- return a;
- }
- }
- printf("Oh no! an iguiwindow generated an event!");
- return false;
+ int shouldclose = lua_toboolean(tL,-1);
+ return shouldclose == 1;
}
-//new({width,height},{posx,posy},"title"[,parent])
+//new({posx,posy},{width,height},"title"[,parent])
static int newiguiwindow(lua_State* L){
- printf("Creating window\n");
-
+ IGUIElement* parent = NULL;
int numargs = lua_gettop(L);
-
- int parentid = lua_tointeger(L,-1);
- lua_pop(L,1);
+ 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,&x,&y);
popvector2i(L,&w,&h);
+ popvector2i(L,&x,&y);
- printf("I want to make a frame at (%d,%d) size (%d,%d)\n",x,y,w,h);
-
//Create the window
IGUIEnvironment* env = guidevice->getGUIEnvironment();
IGUIWindow* wi = env->addWindow(
core::rect<s32>(x,y,x+w,y+h),
false,
title_w,
- guielements[parentid],
+ parent,
-1
);
- lua_newtable(L);//{}
lua_pushlightuserdata(L,wi);
- lua_setfield(L,-2,"element");
-
- luaL_getmetatable(L,"gui.window");
- lua_setmetatable(L,-2);
+ 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;
}
@@ -105,11 +82,12 @@ static const luaL_reg iguiwindow_m[] = {
{"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){
- printf("Loading window\n");
luaL_newmetatable(L,"gui.window");//m{gui.checkbox}
luaL_register(L,NULL,iguiwindow_m);
lua_pop(L,1);//