aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/gui/iguiwindow.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
commit35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (patch)
treed345f620b51ae1ad1d7923e572a6b07ed8731ee5 /src/client/lua_api/gui/iguiwindow.cpp
parentcc12503339004bae2f945e7f7339fc845b2a194f (diff)
downloadbrokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.gz
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.bz2
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.zip
Major update
Diffstat (limited to 'src/client/lua_api/gui/iguiwindow.cpp')
-rw-r--r--src/client/lua_api/gui/iguiwindow.cpp133
1 files changed, 54 insertions, 79 deletions
diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp
index 34b6cfa..038c9f7 100644
--- a/src/client/lua_api/gui/iguiwindow.cpp
+++ b/src/client/lua_api/gui/iguiwindow.cpp
@@ -15,6 +15,7 @@ extern "C" {
#include "iguiwindow.hpp"
#include "iguiutil.hpp"
#include "../../callbackhandeler.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace gui;
@@ -58,110 +59,84 @@ static bool iguiwindowevent(irr::SEvent e){
return false;
}
+//new({posx,posy},{width,height}[,"title"][,parent])
static int newiguiwindow(lua_State* L){
- printf("Createing label!\n");
- int nargs = lua_gettop(L);
- //The position of the text
+ printf("Creating window\n");
- //Frame position
- int x,y;
- lua_popvector2i(L,1,&x,&y);
-
- printf("got xy\n");
+ int parentid = lua_tointeger(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 size
- int w,h;
- lua_popvector2i(L,2,&w,&h);
+ //Frame position
+ long x,y,w,h;
+ popvector2i(L,&x,&y);
+ popvector2i(L,&w,&h);
printf("I want to make a frame at (%d,%d) size (%d,%d)\n",x,y,w,h);
-
- // int startx = luaL_optint(L,1,0);
- // int starty = luaL_optint(L,2,0);
- // int endx = luaL_optint(L,3,startx+100);
- // int endy = luaL_optint(L,4,starty+100);
-
- //Label
- wchar_t* label;
- const char* labelopt = luaL_optstring(L,3,"Label");
- int bls = strlen(labelopt);
- label = (wchar_t*)calloc(sizeof(wchar_t),(bls));
- mbstowcs(label,labelopt,bls);
- printf("Got the string option\n");
- //
- //If the element has a parrent
- int parent = luaL_optint(L,4,0);
- //
- //
- // //Create the button
+
+ //Create the window
IGUIEnvironment* env = guidevice->getGUIEnvironment();
IGUIWindow* wi = env->addWindow(
core::rect<s32>(x,y,x+w,y+h),
false,
- label,
- guielements[parent],
+ title_w,
+ guielements[parentid],
-1
);
- // /Create the label
- // IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect<s32>(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false);
- // printf("Created the button\n");
- //
- // /Register it's callback
+
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,wi);
+ lua_setfield(L,-2,"element");
+
+ luaL_getmetatable(L,"gui.window");
+ lua_setmetatable(L,-2);
+
registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent);
- //
- //Create it's lua representation
- LIGUIElement* lwindow = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- iguielements[wi] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
- //
- //Set it's metatable
- luaL_getmetatable(L, "gui.iguiwindow");
- lua_setmetatable(L, -2);
- //
- //Create the struct
- lwindow->e = wi;
- lwindow->funcmap = hashmap_new();
- lwindow->type = "iguiwindow";
- //
- // /Free up anything made in this function
- free(label);
- //
- // /Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+ return 1;
}
static const luaL_reg iguiwindow_f[] = {
- {"new", newiguiwindow},
- {"gethandeler", guigethandeler},
- {"sethandeler", guisethandeler},
- {0,0},
+ {"new", newiguiwindow},
+ {0,0},
};
static const luaL_reg iguiwindow_m[] = {
- {"move", moveiguielement},
- {"settext", setiguitext},
- {"remove", removeiguielement},
- {0, 0},
+ {"move", moveiguielement},
+ {"settext", setiguitext},
+ {"remove", removeiguielement},
+ {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);//
+
+ lua_getglobal(L,"gui");
+ lua_pushstring(L,"newwindow");
+ lua_pushcfunction(L,newiguiwindow);
+ lua_settable(L,-3);
+ lua_pop(L,1);
- luaL_newmetatable(L, "gui.iguiwindow");
+ return 0;
+ //luaL_newmetatable(L, "gui.iguiwindow");
- luaL_register(L,"iguiwindow",iguiwindow_f);
+ //luaL_register(L,"iguiwindow",iguiwindow_f);
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ //lua_pushstring(L,"__index");
+ //lua_pushstring(L,"gethandeler");
+ //lua_gettable(L,-3);
+ //lua_settable(L,-4);
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ //lua_pushstring(L,"__newindex");
+ //lua_pushstring(L,"sethandeler");
+ //lua_gettable(L,-3);
+ //lua_settable(L,-4);
- luaL_register(L, NULL, iguiwindow_m);
+ //luaL_register(L, NULL, iguiwindow_m);
- return 1;
+ //return 1;
}