aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-07-31 16:42:13 -0400
committerAlexander Pickering <alex@cogarr.net>2018-07-31 16:42:13 -0400
commit1d677927e73e2d66591738777f6a1559527dbab2 (patch)
treea4a0190ac748191dd863c19440c82e8d4f5aa427 /src/client/lua_api
parent11857adbdce423ca93980c884d3dc94a974f735f (diff)
downloadbrokengine-1d677927e73e2d66591738777f6a1559527dbab2.tar.gz
brokengine-1d677927e73e2d66591738777f6a1559527dbab2.tar.bz2
brokengine-1d677927e73e2d66591738777f6a1559527dbab2.zip
Added an editbox
Added bindings to Irrlicht's EditBox gui element.
Diffstat (limited to 'src/client/lua_api')
-rw-r--r--src/client/lua_api/gui/iguieditbox.cpp87
-rw-r--r--src/client/lua_api/gui/iguieditbox.hpp12
-rw-r--r--src/client/lua_api/gui/iguielement.cpp4
-rw-r--r--src/client/lua_api/gui/iguilabel.cpp2
-rw-r--r--src/client/lua_api/gui/iguiwindow.cpp10
-rw-r--r--src/client/lua_api/load_gui.cpp8
-rw-r--r--src/client/lua_api/video/iimage.cpp16
7 files changed, 129 insertions, 10 deletions
diff --git a/src/client/lua_api/gui/iguieditbox.cpp b/src/client/lua_api/gui/iguieditbox.cpp
new file mode 100644
index 0000000..7b79f34
--- /dev/null
+++ b/src/client/lua_api/gui/iguieditbox.cpp
@@ -0,0 +1,87 @@
+
+#include <stdio.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "../guiparts.hpp"
+#include "iguielement.hpp"
+#include "client/callbackhandeler.hpp"
+#include <shared/util/hashmap.hpp>
+#include <shared/lua_api/common.hpp>
+
+using namespace irr;
+using namespace core;
+using namespace gui;
+
+extern IrrlichtDevice* device;
+
+//gui.neweditbox({{sx,sy},{ex,ey}}[,parent][,"default text"])
+static int newiguieditbox(lua_State* L){
+ printf("Creating edit box!\n");
+
+ int nargs = lua_gettop(L);
+ IGUIElement* parent = NULL;
+ const wchar_t* defaulttext = L"";
+ if(nargs >= 3){
+ printf("Getting default text");
+ const char* text_c = lua_tostring(L,-1);
+ defaulttext = irr::core::stringw(text_c).c_str();
+ lua_pop(L,1);//{{sx,sy},{ex,ey}}[,parent]
+ }
+
+ if(nargs >= 2){
+ printf("Getting parent\n");
+ lua_getfield(L,-1,"guielement");
+ parent = (IGUIElement*)lua_touserdata(L,-1);
+ lua_pop(L,2);//{{sx,sy},{ex,ey}}
+ }
+
+ long sx,sy,ex,ey;
+ poprecti(L,&sx,&sy,&ex,&ey);//
+
+ rect<s32> dim = rect<s32>(sx,sy,ex,ey);
+ IGUIEnvironment* env = device->getGUIEnvironment();
+ IGUIEditBox* eb = env->addEditBox(defaulttext,dim,true,parent,-1);
+
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,eb);//{},ud_editbox
+ lua_setfield(L,-2,"guielement");//{editbox}
+ luaL_getmetatable(L,"gui.iguieditbox");//{editbox}{m_editbox}
+ lua_setmetatable(L,-2);//{editbox}
+
+ setelementcallback(L,EGET_EDITBOX_ENTER,"onEnter");
+ setelementcallback(L,EGET_EDITBOX_CHANGED,"onChanged");
+ setelementcallback(L,EGET_EDITBOX_MARKING_CHANGED,"onMarkChange");
+
+ printf("Done creating editbox\n");
+
+ return 1;
+}
+
+static const luaL_reg iguieditbox_f[] = {
+ {"neweditbox",newiguieditbox},
+ {0,0},
+};
+
+static const luaL_reg iguieditbox_m[] = {
+ {"move", moveiguielement},
+ {"settext", setiguitext},
+ {"remove", removeiguielement},
+ {0,0},
+};
+
+void iguieditbox_register(lua_State* L){
+ luaL_newmetatable(L, "gui.iguieditbox");
+ lua_newtable(L);
+ luaL_register(L,NULL,iguieditbox_m);
+ lua_setfield(L,-2,"__index");
+
+ lua_pop(L,1);
+
+ lua_getglobal(L,"gui");
+ luaL_register(L,NULL,iguieditbox_f);
+ lua_pop(L,1);
+}
diff --git a/src/client/lua_api/gui/iguieditbox.hpp b/src/client/lua_api/gui/iguieditbox.hpp
new file mode 100644
index 0000000..51bf832
--- /dev/null
+++ b/src/client/lua_api/gui/iguieditbox.hpp
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+void iguieditbox_register(lua_State* L);
+
diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp
index 0fb25f1..fa3d480 100644
--- a/src/client/lua_api/gui/iguielement.cpp
+++ b/src/client/lua_api/gui/iguielement.cpp
@@ -101,8 +101,8 @@ public:
//{guielement}
//popelementcallback(lua_State* L, gui::EGUI_EVENT_TYPE, char*)
-void setelementcallback(lua_State* L,gui::EGUI_EVENT_TYPE et, const char* funcname){
- registerguielement(L);
+void setelementcallback(lua_State* L, gui::EGUI_EVENT_TYPE et, const char* funcname){
+ registerguielement(L,et,funcname);
}
//ud_iguielement
diff --git a/src/client/lua_api/gui/iguilabel.cpp b/src/client/lua_api/gui/iguilabel.cpp
index 578bca7..436844e 100644
--- a/src/client/lua_api/gui/iguilabel.cpp
+++ b/src/client/lua_api/gui/iguilabel.cpp
@@ -59,7 +59,7 @@ static int newiguilabel(lua_State* L){
lua_setfield(L,-2,"guielement");//{guielement}
luaL_getmetatable(L,"gui.iguilabel");//{guielement},{m_guielement}
lua_setmetatable(L,-2);//{guielement}
- registerguielement(L);
+ //registerguielement(L);
return 1;
}
diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp
index fc85217..e5c3193 100644
--- a/src/client/lua_api/gui/iguiwindow.cpp
+++ b/src/client/lua_api/gui/iguiwindow.cpp
@@ -24,7 +24,7 @@ using namespace gui;
static int newiguiwindow(lua_State* L){
IGUIElement* parent = NULL;
int numargs = lua_gettop(L);
-
+
if(numargs == 4){
lua_getfield(L,-1,"guielement");//{{sx,sy},{ex,ey}},"title",{guielement=parent},parent
parent = (IGUIElement*)lua_touserdata(L,-1);
@@ -34,11 +34,11 @@ static int newiguiwindow(lua_State* L){
const char* title_c = lua_tostring(L,-1);
const wchar_t* title_w = irr::core::stringw(title_c).c_str();
lua_pop(L,1);//{{sx,sy},{ex,ey}}
-
+
//Frame position
long sx,sy,ex,ey;
poprecti(L,&sx,&sy,&ex,&ey);//
-
+
//Create the window
IGUIEnvironment* env = guidevice->getGUIEnvironment();
IGUIWindow* wi = env->addWindow(
@@ -58,7 +58,7 @@ static int newiguiwindow(lua_State* L){
int ref = luaL_ref(L,LUA_REGISTRYINDEX);//
lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{element=ud_window, __meta=gui.window}
- registerguielement(L);
+ registerguielement(L,EGET_ELEMENT_CLOSED,"onClose");
iguielements[wi] = ref;
//registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent);
@@ -79,7 +79,7 @@ int iguiwindow_register(lua_State* L, IrrlichtDevice* d){
luaL_newmetatable(L,"gui.window");//m{gui.checkbox}
luaL_register(L,NULL,iguiwindow_m);
lua_pop(L,1);//
-
+
lua_getglobal(L,"gui");
lua_pushcfunction(L,newiguiwindow);
lua_setfield(L,-2,"newwindow");
diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp
index 598f842..4ad5438 100644
--- a/src/client/lua_api/load_gui.cpp
+++ b/src/client/lua_api/load_gui.cpp
@@ -1,3 +1,8 @@
+/***
+Utilities for drawing GUI things on the screen
+@module gui
+*/
+
#include <stdio.h>
#include <stdlib.h>
#include <vector>
@@ -15,6 +20,7 @@ extern "C" {
#include "gui/iguiskin.hpp"
#include "gui/iguicheckbox.hpp"
#include "gui/iguiimage.hpp"
+#include "gui/iguieditbox.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"
@@ -57,6 +63,8 @@ void load_guifuncs(lua_State* L){
//printf("Registering button\n");
iguibutton_register(L);
+ iguieditbox_register(L);
+
lua_pushcfunction(L,screenwidth);
lua_setglobal(L,"scrw");
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp
index aa51d29..9fb6ec2 100644
--- a/src/client/lua_api/video/iimage.cpp
+++ b/src/client/lua_api/video/iimage.cpp
@@ -47,7 +47,7 @@ int newiimagefromfile(lua_State* L){
img = loader->loadImage(f);
}
if(!hasloaded){
- lua_pushstring(L,"Failed to load file");
+ lua_pushstring(L,"Failed to load file, no image loader for this type.");
lua_error(L);
}
if(!img){
@@ -78,8 +78,20 @@ int setiimagepixel(lua_State* L){
return 0;
}
+//getpixel({self},{x,y})
+int getiimagepixel(lua_State* L){
+ long x,y;
+ popvector2i(L,&x,&y);
+ lua_getfield(L,-1,"image");
+ IImage* img = (IImage*)lua_touserdata(L,-1);
+ SColor color = img->getPixel(x,y);
+ pushvector4i(L,color.getRed(), color.getBlue(), color.getGreen(), color.getAlpha());
+ return 1;
+}
+
static const luaL_reg iimage_m[] = {
- {"setPixel", setiimagepixel},
+ {"setpixel", setiimagepixel},
+ {"getpixel", getiimagepixel},
{0,0},
};