aboutsummaryrefslogtreecommitdiff
path: root/src/client
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
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')
-rw-r--r--src/client/callbackhandeler.cpp15
-rw-r--r--src/client/callbackhandeler.hpp2
-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
-rw-r--r--src/client/main.cpp11
10 files changed, 149 insertions, 18 deletions
diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp
index 783656d..87a0acf 100644
--- a/src/client/callbackhandeler.cpp
+++ b/src/client/callbackhandeler.cpp
@@ -21,7 +21,7 @@ std::map<IGUIElement*, int> guielements;
//For basic events
//{guielement}
-void registerguielement(lua_State* L){
+void registerguielement(lua_State* L, gui::EGUI_EVENT_TYPE et, const char* funcname){
int ref = luaL_ref(L,LUA_REGISTRYINDEX);//
lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{guielement}
lua_getfield(L,-1,"guielement");//{guielement},ud_guielement
@@ -59,7 +59,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
//printf("Gui event\n");
IGUIElement* caller = e.GUIEvent.Caller;
EGUI_EVENT_TYPE get = e.GUIEvent.EventType;
- //printf("detected gui event: %d\n",get);
+ printf("detected gui event: %d\n",get);
if(guielements.find(caller) == guielements.end())
return false;
int ref = guielements[caller];
@@ -108,8 +108,15 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
}
lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{guielement},func(),{guielement}
lua_call(L,1,0);//{guielement}
+ int n = lua_gettop(L);
+ printf("Found %d arguments on top\n",n);
+ if(n > 1){
+ int ans = lua_toboolean(L,-1);
+ lua_pop(L,n);
+ return ans;
+ }
lua_pop(L,1);//
- return true;
+ return false;
}
break;
case EET_MOUSE_INPUT_EVENT:{
@@ -162,6 +169,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
break;
case EMIE_COUNT:break;
}
+ return false;
}
break;
case EET_KEY_INPUT_EVENT:{
@@ -179,6 +187,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
}else{
lua_pop(L,2);
}
+ return false;
break;
}
default:{
diff --git a/src/client/callbackhandeler.hpp b/src/client/callbackhandeler.hpp
index a48213d..3d4894f 100644
--- a/src/client/callbackhandeler.hpp
+++ b/src/client/callbackhandeler.hpp
@@ -13,7 +13,7 @@ using namespace gui;
//void registerguicallback(IGUIElement* element, EGUI_EVENT_TYPE event, bool (*func)(irr::SEvent));
-void registerguielement(lua_State* L);
+void registerguielement(lua_State* L, gui::EGUI_EVENT_TYPE et, const char* funcname);
class GlobalEventReceiver : public irr::IEventReceiver{
public:
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},
};
diff --git a/src/client/main.cpp b/src/client/main.cpp
index eb8eca6..5462e31 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -78,7 +78,7 @@ void QuaternionToEuler(const btQuaternion &TQuat, btVector3 &TEuler) {
}
void UpdateElement(btRigidBody* TObject){
-
+
if(TObject->getUserPointer() != NULL){
//UpdateRender(*Iterator);
scene::ISceneNode *Node = static_cast<scene::ISceneNode *>((TObject)->getUserPointer());
@@ -92,7 +92,7 @@ void UpdateElement(btRigidBody* TObject){
QuaternionToEuler(TObject->getOrientation(), EulerRotation);
Node->setRotation(core::vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));
}
-
+
}
SColor background = SColor(255,100,101,140);
@@ -110,7 +110,7 @@ int main(int argc, char *argv[]){
// Initialize bullet
phys_genesis();
-
+
//Create a new lua state, this gets shared everywhere
lua_State *state = luaL_newstate();
L = state;
@@ -157,8 +157,12 @@ int main(int argc, char *argv[]){
printf("About to check if device run\n");
printf("Device is %p\n",device);
while(device->run()){
+ //printf("Start gameloop net\n");
gameloop_net(L);
+ //printf("End gameloop net\n");
+ //printf("Start gameloop phys\n");
gameloop_phys(UpdateElement);
+ //printf("End gameloop phys\n");
if(device->isWindowActive()){
driver->beginScene(true, true, background);
@@ -183,7 +187,6 @@ int main(int argc, char *argv[]){
lua_call(state,0,0);
lua_pop(state,1);
}else{
- printf("Tick was nil...\n");
lua_pop(state,2);
}
}