aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/gui/iguielement.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-06-30 16:15:05 -0600
committerAlexander Pickering <alex@cogarr.net>2018-06-30 16:15:05 -0600
commited58795eaf03bdee0b1fae8d05ce5b86d17549f7 (patch)
tree065092f3e95bf74fdba541f6c5f7504757487d3d /src/client/lua_api/gui/iguielement.cpp
parent45e61c74802af739736d33c82f27596b45987eee (diff)
downloadbrokengine-ed58795eaf03bdee0b1fae8d05ce5b86d17549f7.tar.gz
brokengine-ed58795eaf03bdee0b1fae8d05ce5b86d17549f7.tar.bz2
brokengine-ed58795eaf03bdee0b1fae8d05ce5b86d17549f7.zip
Warning-less build
All compile warning for -Wall have been fixed
Diffstat (limited to 'src/client/lua_api/gui/iguielement.cpp')
-rw-r--r--src/client/lua_api/gui/iguielement.cpp181
1 files changed, 112 insertions, 69 deletions
diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp
index d14c18e..bdc13df 100644
--- a/src/client/lua_api/gui/iguielement.cpp
+++ b/src/client/lua_api/gui/iguielement.cpp
@@ -9,21 +9,22 @@ extern "C" {
#include <shared/lua_api/common.hpp>
#include <irrlicht.h>
#include "../guiparts.hpp"
+#include <client/callbackhandeler.hpp>
using namespace irr;
using namespace core;
using namespace gui;
-static LIGUIElement* toiguielement(lua_State* L,int index){
- LIGUIElement* ret = (LIGUIElement*)lua_touserdata(L,index);
- if(ret == NULL)
- luaL_typerror(L,index,"LIGUIButton");
- return ret;
-}
+//static LIGUIElement* toiguielement(lua_State* L,int index){
+ //LIGUIElement* ret = (LIGUIElement*)lua_touserdata(L,index);
+ //if(ret == NULL)
+ //luaL_typerror(L,index,"LIGUIButton");
+ //return ret;
+//}
-static LIGUIElement* toiguielement(lua_State* L){
- return toiguielement(L,1);
-}
+//static LIGUIElement* toiguielement(lua_State* L){
+ //return toiguielement(L,1);
+//}
//move({element},{x,y}) -> nil
int moveiguielement(lua_State* L){
@@ -45,18 +46,16 @@ int moveiguielement(lua_State* L){
int getiguiclippingrect(lua_State* L){
printf("Getting iguiclipping elemnt\n");
lua_getfield(L,-1,"guielement");
- IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);
+ IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);//{element},ud_element
+ lua_pop(L,2);
core::rect<s32> rect = el->getAbsoluteClippingRect();
- position2d<s32> ul = rect.UpperLeftCorner;
- position2d<s32> lr = rect.LowerRightCorner;
- lua_newtable(L);
- lua_pushnumber(L,1);
- double sx,sy,ex,ey;
- pushvector2i(L,ul.X,ul.Y);
- lua_settable(L,-3);
- lua_pushnumber(L,2);
- pushvector2i(L,lr.X,lr.Y);
- lua_settable(L,-3);
+ pushrecti(
+ L,
+ rect.UpperLeftCorner.X,
+ rect.UpperLeftCorner.Y,
+ rect.LowerRightCorner.X,
+ rect.LowerRightCorner.Y
+ );
return 1;
}
/*
@@ -69,15 +68,19 @@ int moveiguielement(lua_State* L){
}
*/
+//setText({guielement},"text") :: nil
int setiguitext(lua_State* L){
- LIGUIElement* ele = toiguielement(L,1);
- const char* str = luaL_optstring(L,2,"");
- int size = strlen(str);
- wchar_t* al = (wchar_t*)malloc(sizeof(wchar_t)*size);
- mbstowcs(al,str,size);
- ele->e->setText(al);
- free(al);
- return 0;
+ const char* text = lua_tostring(L, -1);
+ lua_pop(L,1);//{guielement}
+ lua_getfield(L,-1,"guielement");//{guielement},ud_iguielement
+ IGUIElement* el = (IGUIElement*)lua_touserdata(L,-1);//{guielement},ud_iguielement
+ lua_pop(L,2);
+ int textlen = strlen(text);
+ wchar_t* wtext = (wchar_t*)malloc(sizeof(wchar_t)*textlen);
+ mbstowcs(wtext,text,textlen);
+ el->setText(wtext);
+ free(wtext);
+ return 0;
}
//remove({self})
@@ -89,50 +92,90 @@ int removeiguielement(lua_State* L){
return 0;
}
-int guigethandeler(lua_State* L){
- printf("Called the get index handeler!\n");
- LIGUIElement* button = toiguielement(L);
- if(!lua_isstring(L,2)){
- luaL_error(L,"index of iguibutton must be of type 'string'");
- }
- const char* lstr = lua_tostring(L,2);
- char* hashkey = (char*)malloc(sizeof(char)*strlen(lstr));
- strcpy(hashkey,lstr);
- int ref;
- if(hashmap_get(button->funcmap,hashkey,(void**)&ref) == MAP_OK){
- //We found the value in our hashmap!
- lua_rawgeti(L,LUA_REGISTRYINDEX,ref);
- return 1;
- }else{
- //Could not find in hashmap, check parrent
- lua_getglobal(L,button->type);
- printf("Button's type is %s\n",button->type);
- lua_getfield(L,-1,lstr);
- return 1;
- }
-}
-int guisethandeler(lua_State* L){
- printf("Called the set index handeler\n");
- LIGUIElement* button = toiguielement(L);
- if(!lua_isstring(L,2)){
- luaL_error(L,"index of iguibutton must be of type 'string'");
- }
- const char* lstr = lua_tostring(L,2);
- char* hashkey = (char*)malloc(sizeof(char)*strlen(lstr));
- strcpy(hashkey,lstr);
- int oldref;
- if(hashmap_get(button->funcmap,hashkey,(void**)&oldref) == MAP_OK){
- luaL_unref(L,LUA_REGISTRYINDEX,oldref);
- hashmap_remove(button->funcmap,hashkey);
- }
- int ref = luaL_ref(L,LUA_REGISTRYINDEX);
- if(hashmap_put(button->funcmap,hashkey,(void*)ref) != MAP_OK){
- luaL_error(L,"Error while setting the hashkey on iguibutton");
- }
- return 0;
+class guicallback{
+private:
+ int luaitem;
+ const char* funcname;
+ lua_State* L;
+public:
+ guicallback(lua_State* L, int lf, const char* fn){
+ this->luaitem = lf;
+ this->L = L;
+ this->funcname = fn;
+ }
+ bool operator () (SEvent e) {
+ lua_rawgeti(L,LUA_REGISTRYINDEX,this->luaitem);//{guielement}
+ lua_getfield(L,-1,this->funcname);//{guielement},func()
+ if(!lua_isnil(L,-1)){
+ lua_rawgeti(L,LUA_REGISTRYINDEX,this->luaitem);//{guielement},func(),{guielement}
+ lua_call(L,1,0);//{iguielement}
+ lua_pop(L,1);//{}
+ return true;
+ }else{
+ lua_pop(L,2);//{}
+ return false;
+ }
+ }
+};
+
+//{guielement}
+//popelementcallback(lua_State* L, gui::EGUI_EVENT_TYPE, char*)
+void setelementcallback(lua_State* L,gui::EGUI_EVENT_TYPE et, const char* funcname){
+ //lua_getfield(L,-1,"guielement");//{guielement}
+ //IGUIElement* el = (IGUIElement*)lua_touserdata(L,-1);//{guielement},ud_element
+ //lua_pop(L,1);//{guielement}
+ registerguielement(L);
+ //int ref = luaL_ref(L,LUA_REGISTRYINDEX);//
+ //guicallback* gc = new guicallback(L,ref,funcname);//TODO:Clean this up somehow
+ //popregisterguicallback(el,et, gc);
+ //lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{guielement}
}
+//int guigethandeler(lua_State* L){
+ //printf("Called the get index handeler!\n");
+ //LIGUIElement* button = toiguielement(L);
+ //if(!lua_isstring(L,2)){
+ //luaL_error(L,"index of iguibutton must be of type 'string'");
+ //}
+ //const char* lstr = lua_tostring(L,2);
+ //char* hashkey = (char*)malloc(sizeof(char)*strlen(lstr));
+ //strcpy(hashkey,lstr);
+ //int ref;
+ //if(hashmap_get(button->funcmap,hashkey,(void**)&ref) == MAP_OK){
+ ////We found the value in our hashmap!
+ //lua_rawgeti(L,LUA_REGISTRYINDEX,ref);
+ //return 1;
+ //}else{
+ ////Could not find in hashmap, check parrent
+ //lua_getglobal(L,button->type);
+ //printf("Button's type is %s\n",button->type);
+ //lua_getfield(L,-1,lstr);
+ //return 1;
+ //}
+//}
+
+//int guisethandeler(lua_State* L){
+ //printf("Called the set index handeler\n");
+ //LIGUIElement* button = toiguielement(L);
+ //if(!lua_isstring(L,2)){
+ //luaL_error(L,"index of iguibutton must be of type 'string'");
+ //}
+ //const char* lstr = lua_tostring(L,2);
+ //char* hashkey = (char*)malloc(sizeof(char)*strlen(lstr));
+ //strcpy(hashkey,lstr);
+ //int oldref;
+ //if(hashmap_get(button->funcmap,hashkey,(void**)&oldref) == MAP_OK){
+ //luaL_unref(L,LUA_REGISTRYINDEX,oldref);
+ //hashmap_remove(button->funcmap,hashkey);
+ //}
+ //int ref = luaL_ref(L,LUA_REGISTRYINDEX);
+ //if(hashmap_put(button->funcmap,hashkey,(void*)ref) != MAP_OK){
+ //luaL_error(L,"Error while setting the hashkey on iguibutton");
+ //}
+ //return 0;
+//}
+
//ud_iguielement
int guigetid(lua_State* L){
IGUIElement* el = (IGUIElement*)lua_touserdata(L,-1);