diff options
| -rw-r--r-- | Makefile | 16 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguifiledialog.cpp | 120 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguifiledialog.hpp | 12 | ||||
| -rw-r--r-- | src/client/lua_api/load_gui.cpp | 2 |
4 files changed, 144 insertions, 6 deletions
@@ -150,7 +150,7 @@ SHARED_CLIENT_FILES = lua_api/common phys/physcommon lua_api/phys/bphysbox util/ SHARED_CLIENT_OBJS = $(SHARED_CLIENT_FILES:%=$(BUILD_DIR)/$(CLIENTNAME)/%.o) # The client-side only stuff -LAPI_GUI = iguibutton iguicheckbox iguielement iguiimage iguilabel iguiwindow iguieditbox iguicolorselector +LAPI_GUI = iguibutton iguicheckbox iguielement iguiimage iguilabel iguiwindow iguieditbox iguicolorselector iguifiledialog LAPI_PHYS = bphysmodel cbphysbox LAPI_SCENE = icamera igeneric ilight imesh LAPI_VIDEO = iimage itexture smaterial @@ -309,12 +309,16 @@ $(LNNGDIR)/Makefile : $(LNNGDIR)/CMakeLists.txt $(LNNGDIR)/libnng.dll.a : $(LNNGDIR)/Makefile cd $(LNNGDIR)/dyn_lib && $(MAKE) nng +TEST_BIN_NAMES=brokengine_client.exe Irrlicht.dll libnanomsg.dll libnng.dll lua51.dll +TEST_BINS=$(TEST_BIN_NAMES:%=test/bin/%) + #compile & run tests -test: $(TEST_PATH)test_stream $(TEST_PATH)test_phys - @$(ECHO) "Testing stream : " - @./$(TEST_PATH)test_stream - @$(ECHO) "Testing physics: " - @./$(TEST_PATH)test_phys +test: $(TEST_BINS) + @$(ECHO) "Running busted tests" + @./busted busted.spec + +$(TEST_BINS) : test/bin/% : bin/client/bin/% + cp $^ $@ $(TEST_PATH)test_stream : $(TEST_SRC)test_streams.cpp $(SHARED_SRC)/lua_api/stream.cpp $(SHARED_SRC)/lua_api/stream.hpp @$(CC) $(CFLAGS) -o $(TEST_PATH)test_stream $(TEST_SRC)test_streams.cpp $(SHARED_SRC)/lua_api/stream.cpp $(SHARED_SRC)/lua_api/stream.hpp diff --git a/src/client/lua_api/gui/iguifiledialog.cpp b/src/client/lua_api/gui/iguifiledialog.cpp new file mode 100644 index 0000000..c277ce4 --- /dev/null +++ b/src/client/lua_api/gui/iguifiledialog.cpp @@ -0,0 +1,120 @@ +#include <stdio.h> +#include <stdlib.h> +#include <vector> +#include <memory> +#include <map> +#include <string> +#include <functional> +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> + +/*** +@module gui +*/ +using namespace irr; +using namespace core; +using namespace gui; + +extern IrrlichtDevice* device; + +/*** +@function newfileopendialog() +Creates a new dialog to open a file +@tparam title string 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 path string The path to open the file dialog to +@tparam parent (iguielement | nil) parent The parent element of the button. +@tparam modal boolean If other gui elements can be interacted with before this element is closed +@treturn iguifileopendialog The button element +*/ +//gui.newfileopendialog(["title"][,"path"][,parent][,modal]) +static int newfileopendialog(lua_State* L){ + wchar_t *title = NULL;// = L"File open dialog"; + io::path::char_type *path = NULL;// = L""; + bool modal = true; + IGUIElement* parent = NULL; + + int nargs = lua_gettop(L); + if(nargs > 3){ + modal = lua_toboolean(L,-1) == 1;//"title","path",{parent},modal + lua_pop(L,1);//"title","path",{parent} + } + if(nargs > 2){ + lua_getfield(L,-1,"guielement");//"title","path",{parent},ud_parent + parent = (IGUIElement*)lua_touserdata(L,-1);//"title","path",{parent},ud_parent + lua_pop(L,2);//"title","path" + } + if(nargs > 1){ + const char *pathc = lua_tostring(L,-1);//"title","path" + lua_pop(L,1);//"title" + path = (io::path::char_type*)pathc; + //size_t pathcslen = strlen(pathc); + //path = (wchar_t*)malloc(sizeof(wchar_t) * (pathcslen + 1));// +1 for null + //mbstowcs(path,pathc,pathcslen); + //path[pathcslen] = L'\0'; + } + if(nargs > 0){ + const char *titlec = lua_tostring(L,-1); + lua_pop(L,1);// + size_t titlecslen = strlen(titlec); + title = (wchar_t*)malloc(sizeof(wchar_t) * (titlecslen + 1)); + mbstowcs(title,titlec,titlecslen); + title[titlecslen] = L'\0'; + } + + IGUIEnvironment *env = device->getGUIEnvironment(); + IGUIFileOpenDialog *but = env->addFileOpenDialog(title,modal,parent,-1,false,path); + + printf("Added file open dialog\n"); + lua_newtable(L);//{} + lua_pushlightuserdata(L,but);//{},ud_iguibutton + lua_setfield(L,-2,"guielement");//{guielement} + luaL_getmetatable(L,"gui.iguifileopendialog");//{guielement},{m_iguibutton} + lua_setmetatable(L,-2);//{guielement} + + printf("Created lua representation\n"); + setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectory");// + setelementcallback(L,EGET_FILE_SELECTED,"onFileSelected"); + setelementcallback(L,EGET_FILE_CHOOSE_DIALOG_CANCELLED,"onCanceled"); + printf("Finished registering callback\n"); + + free(title); + free(path); + return 1; +} + +static const luaL_reg iguifileopendialog_f[] = { + {"new", newfileopendialog}, + {0,0}, +}; + +static const luaL_reg iguifileopendialog_m[] = { + {0,0}, +}; + +void iguidialog_register(lua_State* L){ + tL = L; + + luaL_newmetatable(L, "gui.iguifileopendialog");//{m_iguibutton} + lua_newtable(L);//{m_iguibutton},{} + luaL_register(L,NULL,iguielement_m); + luaL_register(L,NULL,iguifileopendialog_m);//{m_iguibutton},{} + lua_setfield(L,-2,"__index");//{m_iguibutton} + + lua_pop(L,1); + + lua_getglobal(L,"gui"); + lua_pushcfunction(L,newfileopendialog); + lua_setfield(L,-2,"newfileopendialog"); + + lua_pop(L,1); +} diff --git a/src/client/lua_api/gui/iguifiledialog.hpp b/src/client/lua_api/gui/iguifiledialog.hpp new file mode 100644 index 0000000..85b4b7d --- /dev/null +++ b/src/client/lua_api/gui/iguifiledialog.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 iguidialog_register(lua_State* L); diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp index 32d139a..f62fb14 100644 --- a/src/client/lua_api/load_gui.cpp +++ b/src/client/lua_api/load_gui.cpp @@ -21,6 +21,7 @@ extern "C" { #include "gui/iguiimage.hpp" #include "gui/iguieditbox.hpp" #include "gui/iguicolorselector.hpp" +#include "gui/iguifiledialog.hpp" #include "../callbackhandeler.hpp" #include "guiparts.hpp" @@ -64,6 +65,7 @@ void load_guifuncs(lua_State* L){ iguiimage_register(L); iguibutton_register(L); iguicolorselector_register(L); + iguidialog_register(L); iguieditbox_register(L); |
