From dc9cd82e80338a20b71db662abb6192aff118fe3 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 12 Aug 2018 14:51:22 -0400 Subject: Modified iguielement to export it's functions Other gui elements can now register all the base igui functions by registering iguielement_m from iguielement.hpp --- src/client/lua_api/gui/iguicheckbox.cpp | 35 ++++++++++++++++++++++----------- src/client/lua_api/gui/iguielement.cpp | 22 +++++++++++++++++++-- src/client/lua_api/gui/iguielement.hpp | 10 ++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) (limited to 'src/client') diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp index 8e1a643..c0ca740 100644 --- a/src/client/lua_api/gui/iguicheckbox.cpp +++ b/src/client/lua_api/gui/iguicheckbox.cpp @@ -1,4 +1,3 @@ -/*This file defines some things that all igui stuff can do*/ extern "C" { #include #include @@ -9,30 +8,44 @@ extern "C" { #include "iguielement.hpp" #include +/*** +@module gui +*/ using namespace irr; using namespace gui; using namespace core; extern IrrlichtDevice* device; +/*** +@function newcheckbox() +Creates a new checkbox +@tparam dimensions rect The rectangle to place the box at. If the box has a parent, +it is offset from the upper-left of the parent element. +@tparam parent (iguielement | nil) parent The parent element of the edit box +@tparam default_text (string | nil) default_text The default text to have in the edit box +@treturn iguieditbox The edit box element +*/ //new({startx,starty},{endx,endy},"checkbox_name"[,ud_parent]) int newiguicheckbox(lua_State* L){ - IGUIElement* par = 0; - if(lua_gettop(L) > 3){ - par = (IGUIElement*)lua_touserdata(L,-1);//{startx,starty},{endx,endy},"checkbox_name",ud_parent - printf("Checkbox's parent was %p\n",par); - lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name" + IGUIElement* par = NULL; + int nargs = lua_gettop(L); + if(nargs == 3){ + lua_getfield(L,-1,"guielement");//{{sx,sy},{ex,ey}},"label",{parent},ud_parent + par = (IGUIElement*)lua_touserdata(L,-1); + lua_pop(L,2);//{{sx,sy},{ex,ey}},"chekboxname" } - const char* text = lua_tostring(L,-1); + const char* text = lua_tostring(L,-1);//{{sx,sy},{ex,ey}},"label" //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);// + poprecti(L,&startx,&starty,&endx,&endy); irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect(startx,starty,endx,endy),par,-1,stringw(text).c_str()); + lua_newtable(L);//{} lua_pushlightuserdata(L,cb);//*checkbox - luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox} - lua_setmetatable(L,-2);//*checkbox + lua_setfield(L,-2,"guielement");//{checkbox} + luaL_getmetatable(L,"gui.checkbox");//{checkbox},m{gui.checkbox} + lua_setmetatable(L,-2);//{checkbox} return 1; } diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp index 5ba998f..44fb67c 100644 --- a/src/client/lua_api/gui/iguielement.cpp +++ b/src/client/lua_api/gui/iguielement.cpp @@ -1,8 +1,6 @@ /*This file defines some things that all igui stuff can do*/ /*** @module gui - - */ extern "C" { #include @@ -86,6 +84,25 @@ int setiguitext(lua_State* L){ return 0; } + +/*** +@function guielement:gettext() +@treturn string The caption text of the element. For input element like +editboxes, this returns the text that the edit box contains. +*/ +//{guieditbox}:gettext() :: "caption_text" +int getiguitext(lua_State* L){ + lua_getfield(L, -1, "guielement");//{guieditbox},ud_guielement + irr::gui::IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1); + lua_pop(L,2);// + const wchar_t *t = el->getText(); + size_t strlen = wcslen(t); + char output[strlen]; + wcstombs(output,t,strlen); + lua_pushstring(L,output);//"str" + return 1; +} + /*** Removes a gui element, and any child elements @function guielement:remove() @@ -140,3 +157,4 @@ int guigetid(lua_State* L){ lua_pushnumber(L,id); return 1; } + diff --git a/src/client/lua_api/gui/iguielement.hpp b/src/client/lua_api/gui/iguielement.hpp index f860d7e..aafbaab 100644 --- a/src/client/lua_api/gui/iguielement.hpp +++ b/src/client/lua_api/gui/iguielement.hpp @@ -11,8 +11,18 @@ extern "C" { int moveiguielement(lua_State* L); int getiguiclippingrect(lua_State* L); int setiguitext(lua_State* L); +int getiguitext(lua_State* L); int removeiguielement(lua_State* L); void setelementcallback(lua_State* L, irr::gui::EGUI_EVENT_TYPE et, const char* funcname); int guigethandeler(lua_State* L); int guisethandeler(lua_State* L); int guigetid(lua_State* L); + +static const luaL_reg iguielement_m[] = { + {"move", moveiguielement}, + {"getabsrect", getiguiclippingrect}, + {"settext", setiguitext}, + {"gettext", getiguitext}, + {"remove", removeiguielement}, + {NULL, NULL} +}; -- cgit v1.2.3-70-g09d2