aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/lua_api/gui')
-rw-r--r--src/client/lua_api/gui/iguicheckbox.cpp55
-rw-r--r--src/client/lua_api/gui/iguicheckbox.hpp10
-rw-r--r--src/client/lua_api/gui/iguiwindow.cpp133
3 files changed, 119 insertions, 79 deletions
diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp
new file mode 100644
index 0000000..c6e5955
--- /dev/null
+++ b/src/client/lua_api/gui/iguicheckbox.cpp
@@ -0,0 +1,55 @@
+/*This file defines some things that all igui stuff can do*/
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "../guiparts.hpp"
+#include "iguielement.hpp"
+#include "../../../shared/lua_api/common.h"
+
+using namespace irr;
+using namespace core;
+
+extern IrrlichtDevice* device;
+
+//new({startx,starty},{endx,endy},"checkbox_name",parent)
+int newiguicheckbox(lua_State* L){
+ int parentid = lua_tointeger(L,-1);
+ lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name"
+ const char* text = lua_tostring(L,-1);
+ int tlen = strlen(text);
+ lua_pop(L,1);//{startx,starty},{endx,endy}
+ long startx,starty,endx,endy;
+ popvector2i(L,&endx,&endy);//{startx,starty}
+ popvector2i(L,&startx, &starty);//
+ irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),0,-1,stringw(text).c_str());
+ lua_pushlightuserdata(L,cb);//*checkbox
+ luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox}
+ lua_setmetatable(L,-2);//*checkbox
+
+ return 1;
+}
+
+static const luaL_reg iguicheckbox_m[] = {
+ {"move", moveiguielement},
+ {"setText", setiguitext},
+ {"remove", guisethandeler},
+ {0,0},
+};
+
+int iguicheckbox_register(lua_State* L){//
+
+ luaL_newmetatable(L,"gui.checkbox");//m{gui.checkbox}
+ luaL_register(L,NULL,iguicheckbox_m);
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"gui");//{gui}
+ lua_pushstring(L,"newcheckbox");//{gui},new(),"newcheckbox"
+ lua_pushcfunction(L,newiguicheckbox);//{gui},new()
+ printf("I have registered the newcheckbox function\n");
+ lua_settable(L,-3);//{gui}
+ lua_pop(L,1);
+ return 0;
+}
diff --git a/src/client/lua_api/gui/iguicheckbox.hpp b/src/client/lua_api/gui/iguicheckbox.hpp
new file mode 100644
index 0000000..ee2f2bc
--- /dev/null
+++ b/src/client/lua_api/gui/iguicheckbox.hpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+int iguicheckbox_register(lua_State* L);
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;
}