aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-10-20 14:05:30 -0400
committerAlexander Pickering <alex@cogarr.net>2018-10-20 14:05:30 -0400
commit4a797a4226893b382ffc3c1f92e844f6743c7220 (patch)
tree5645ee6e58c0ac38e71230338901578ee572df2a
parent6543a9aa301a8ebc67ff50a880bcff2e496fa17e (diff)
downloadbrokengine-4a797a4226893b382ffc3c1f92e844f6743c7220.tar.gz
brokengine-4a797a4226893b382ffc3c1f92e844f6743c7220.tar.bz2
brokengine-4a797a4226893b382ffc3c1f92e844f6743c7220.zip
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
-rw-r--r--src/client/lua_api/gui/iguibutton.cpp8
-rw-r--r--src/client/lua_api/gui/iguicheckbox.cpp34
-rw-r--r--src/client/lua_api/gui/iguielement.cpp44
-rw-r--r--src/client/lua_api/gui/iguielement.hpp17
-rw-r--r--src/client/lua_api/gui/iguitreeview.cpp4
5 files changed, 89 insertions, 18 deletions
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 <lua.h>
@@ -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
*/
@@ -40,6 +49,24 @@ int moveiguielement(lua_State* L){
}
/***
+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()
@treturn rect The rectangle that this element occupies
@@ -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 <stdio.h>
#include <stdlib.h>
extern "C" {
@@ -9,6 +10,7 @@ extern "C" {
#include <irrlicht.h>
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 = "";