From 4a797a4226893b382ffc3c1f92e844f6743c7220 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 20 Oct 2018 14:05:30 -0400 Subject: Added more documentation Added documentation for several gui elements also moved documentation of generic iguielements to an iguielement class Also added a setvisible() function to iguielements --- src/client/lua_api/gui/iguibutton.cpp | 8 +++++- src/client/lua_api/gui/iguicheckbox.cpp | 34 ++++++++++++++++++++++++- src/client/lua_api/gui/iguielement.cpp | 44 +++++++++++++++++++++++++++++++-- src/client/lua_api/gui/iguielement.hpp | 17 ++++--------- src/client/lua_api/gui/iguitreeview.cpp | 4 +-- 5 files changed, 89 insertions(+), 18 deletions(-) (limited to 'src/client') diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp index aabc992..42d2846 100644 --- a/src/client/lua_api/gui/iguibutton.cpp +++ b/src/client/lua_api/gui/iguibutton.cpp @@ -28,8 +28,14 @@ extern IrrlichtDevice* device; char lhashkey[20]; /*** +Creates a new button. +Buttons may have the following fields set for callbacks: +`.onClick(self)` +`.onFocus(self)` +`.onUnfocus(self)` +`.onHover(self)` +`.onLeave(self)` @function newbutton() -Creates a new checkbox @tparam rect dimensions The rectangle to place the button at. If the box has a parent, it is offset from the upper-left of the parent element. @tparam string default_text The default text to have in the button diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp index 794b8f1..6413883 100644 --- a/src/client/lua_api/gui/iguicheckbox.cpp +++ b/src/client/lua_api/gui/iguicheckbox.cpp @@ -18,8 +18,15 @@ using namespace core; extern IrrlichtDevice* device; /*** +Creates a new checkbox. +Creates a new checkbox that can be checked and unchecked. Checkboxes may have the +following fields, which they will call for callbacks: + + .onCheck(self) + +It may additionally call any @{iguielement} callbacks + @function newcheckbox() -Creates a new checkbox @tparam rect dimensions 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 string default_text The default text to have in the edit box @@ -47,10 +54,35 @@ int newiguicheckbox(lua_State* L){ luaL_getmetatable(L,"gui.checkbox");//{checkbox},m{gui.checkbox} lua_setmetatable(L,-2);//{checkbox} + setelementcallback(L,EGET_CHECKBOX_CHANGED,"onCheck"); + return 1; } +//ischecked(self) +int ischecked(lua_State *L){ + lua_getfield(L,-1,"guielement"); + IGUICheckBox *e = (IGUICheckBox*)lua_touserdata(L,-1); + lua_pop(L,2); + bool checked = e->isChecked(); + lua_pushboolean(L,checked ? 1 : 0); + return 1; +} + +//setchecked(self, checked) +int setchecked(lua_State *L){ + int should = lua_toboolean(L,-1); + lua_pop(L,1); + lua_getfield(L,-1,"guielement"); + IGUICheckBox *e = (IGUICheckBox*)lua_touserdata(L,-1); + lua_pop(L,2); + e->setChecked(should == 1); + return 0; +} + static const luaL_reg iguicheckbox_m[] = { + {"ischecked", ischecked}, + {"setchecked", setchecked}, {0,0}, }; diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp index 81d339f..4ef5026 100644 --- a/src/client/lua_api/gui/iguielement.cpp +++ b/src/client/lua_api/gui/iguielement.cpp @@ -1,6 +1,15 @@ /*This file defines some things that all igui stuff can do*/ /*** -@module gui +All gui elements inherit from iguielement. +Some functions (like settext()) do different things for different elements. +All gui elements can call the following callbacks: + + onFocus(self) + onUnfous(self) + onHover(self) + onLeave(self) + +@classmod iguielement */ extern "C" { #include @@ -19,7 +28,7 @@ using namespace core; using namespace gui; /*** -Move a window (by an offset) +Move an element (by an offset) from it's current position @function guielement:move() @tparam vector2d position The offset to move this element by */ @@ -39,6 +48,24 @@ int moveiguielement(lua_State* L){ return 0; } +/*** +Set the visibility of this element +@function guielement:setvisible() +@tparam boolean visible Should this element be visible? +*/ +int setvisible(lua_State *L){ + int v = lua_toboolean(L,-1); + lua_pop(L,1); + + lua_getfield(L,-1,"guielement"); + IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);//{element},ud_element + lua_pop(L,2); + + el->setVisible(v == 1); + + return 0; +} + /*** Find the rectangle that an element occupies @function guielement:getabsrect() @@ -60,6 +87,7 @@ int getiguiclippingrect(lua_State* L){ return 1; } + /*** Find the rectangle that an element occupies that is visible to the user @function guielement:getabsclippingrect() @@ -212,3 +240,15 @@ int guigetid(lua_State* L){ return 1; } +extern const luaL_reg iguielement_m[] = { + {"move", moveiguielement}, + {"setvisible", setvisible}, + {"setrect", setrelrect}, + {"getabsrect", getiguiclippingrect}, + {"getabsclippingrect", getiguiabsclippingrect}, + {"getrelrect", getiguirelrect}, + {"settext", setiguitext}, + {"gettext", getiguitext}, + {"remove", removeiguielement}, + {NULL, NULL} +}; diff --git a/src/client/lua_api/gui/iguielement.hpp b/src/client/lua_api/gui/iguielement.hpp index 7969c65..b3a776b 100644 --- a/src/client/lua_api/gui/iguielement.hpp +++ b/src/client/lua_api/gui/iguielement.hpp @@ -1,4 +1,5 @@ - +#ifndef __H_BROKEN_IGUIELEMENT +#define __H_BROKEN_IGUIELEMENT #include #include extern "C" { @@ -9,6 +10,7 @@ extern "C" { #include int moveiguielement(lua_State* L); +int setvisible(lua_State *L); int getiguiclippingrect(lua_State* L); int getiguiabsclippingrect(lua_State *L); int getiguirelrect(lua_State *L); @@ -21,14 +23,5 @@ int guisethandeler(lua_State* L); int guigetid(lua_State* L); int setrelrect(lua_State *L); -static const luaL_reg iguielement_m[] = { - {"move", moveiguielement}, - {"setrect", setrelrect}, - {"getabsrect", getiguiclippingrect}, - {"getabsclippingrect", getiguiabsclippingrect}, - {"getrelrect", getiguirelrect}, - {"settext", setiguitext}, - {"gettext", getiguitext}, - {"remove", removeiguielement}, - {NULL, NULL} -}; +extern const luaL_reg iguielement_m[]; +#endif diff --git a/src/client/lua_api/gui/iguitreeview.cpp b/src/client/lua_api/gui/iguitreeview.cpp index ca7b38d..68aa3cc 100644 --- a/src/client/lua_api/gui/iguitreeview.cpp +++ b/src/client/lua_api/gui/iguitreeview.cpp @@ -75,7 +75,7 @@ static int newiguitreeview(lua_State* L){ return 1; } -//iguitreeview:getroot() +//iguitreeview:getroot() :: treenode int getRootNode(lua_State *L){ lua_getfield(L,-1,"guielement");//{treeview},ud_TreeView IGUITreeView *v = (IGUITreeView*)lua_touserdata(L,-1); @@ -91,7 +91,7 @@ int getRootNode(lua_State *L){ return 1; } -//iguitreeviewnode:append_child("text"[,"icon"]) +//iguitreeviewnode:append_child("text"[,"icon"]) :: treenode int appendChild(lua_State *L){ const char *text_c = ""; const char *icon_c = ""; -- cgit v1.2.3-70-g09d2