diff options
Diffstat (limited to 'src/client/lua_api')
| -rw-r--r-- | src/client/lua_api/gui/iguibutton.cpp | 6 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguicheckbox.cpp | 14 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguielement.cpp | 50 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguielement.hpp | 1 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguiimage.cpp | 60 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguiwindow.cpp | 1 | ||||
| -rw-r--r-- | src/client/lua_api/load_video.cpp | 61 | ||||
| -rw-r--r-- | src/client/lua_api/video/iimage.cpp | 53 | ||||
| -rw-r--r-- | src/client/lua_api/video/itexture.cpp | 37 |
9 files changed, 233 insertions, 50 deletions
diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp index 3295e6e..8732bd6 100644 --- a/src/client/lua_api/gui/iguibutton.cpp +++ b/src/client/lua_api/gui/iguibutton.cpp @@ -13,9 +13,9 @@ extern "C" { #include <irrlicht.h> #include "../guiparts.hpp" #include "iguielement.hpp" -#include "../../callbackhandeler.hpp" -#include "../../util/hashmap.h" -#include "../../../shared/lua_api/common.h" +#include "client/callbackhandeler.hpp" +#include "client/util/hashmap.h" +#include "shared/lua_api/common.h" using namespace irr; using namespace core; diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp index c6e5955..74dd12e 100644 --- a/src/client/lua_api/gui/iguicheckbox.cpp +++ b/src/client/lua_api/gui/iguicheckbox.cpp @@ -10,21 +10,26 @@ extern "C" { #include "../../../shared/lua_api/common.h" using namespace irr; +using namespace gui; using namespace core; extern IrrlichtDevice* device; -//new({startx,starty},{endx,endy},"checkbox_name",parent) +//new({startx,starty},{endx,endy},"checkbox_name"[,ud_parent]) int newiguicheckbox(lua_State* L){ - int parentid = lua_tointeger(L,-1); - lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name" + IGUIElement* par = 0; + if(lua_gettop(L) > 3){ + par = (IGUIElement*)lua_touserdata(L,-1);//{startx,starty},{endx,endy},"checkbox_name",ud_parent + printf("Checkbox's parent was %s\n",par); + lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name" + } const char* text = lua_tostring(L,-1); int tlen = strlen(text); lua_pop(L,1);//{startx,starty},{endx,endy} long startx,starty,endx,endy; popvector2i(L,&endx,&endy);//{startx,starty} popvector2i(L,&startx, &starty);// - irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),0,-1,stringw(text).c_str()); + irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),par,-1,stringw(text).c_str()); lua_pushlightuserdata(L,cb);//*checkbox luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox} lua_setmetatable(L,-2);//*checkbox @@ -48,7 +53,6 @@ int iguicheckbox_register(lua_State* L){// lua_getglobal(L,"gui");//{gui} lua_pushstring(L,"newcheckbox");//{gui},new(),"newcheckbox" lua_pushcfunction(L,newiguicheckbox);//{gui},new() - printf("I have registered the newcheckbox function\n"); lua_settable(L,-3);//{gui} lua_pop(L,1); return 0; diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp index c01fa70..b62efef 100644 --- a/src/client/lua_api/gui/iguielement.cpp +++ b/src/client/lua_api/gui/iguielement.cpp @@ -4,6 +4,9 @@ extern "C" { #include <lauxlib.h> #include <lualib.h> } + + +#include "../../../shared/lua_api/common.h" #include <irrlicht.h> #include "../guiparts.hpp" @@ -22,6 +25,41 @@ static LIGUIElement* toiguielement(lua_State* L){ return toiguielement(L,1); } +//move({element},{x,y}) -> nil +int moveiguielement(lua_State* L){ + printf("Got call to move element\n"); + long x,y; + popvector2i(L,&x,&y); //{element} + printf("I want to move to %d %d\n",x,y); + lua_getfield(L,-1,"guielement");//{element},*element + IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1); + printf("Found element to move: %p\n",el); + lua_pop(L,2);// + + el->move(position2d<s32>(x,y)); + el->updateAbsolutePosition(); + return 0; +} + +//getabsrect({element})-> {{sx,sy},{ex,ey}} +int getiguiclippingrect(lua_State* L){ + printf("Getting iguiclipping elemnt\n"); + lua_getfield(L,-1,"guielement"); + IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1); + 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); + return 1; +} +/* int moveiguielement(lua_State* L){ LIGUIElement* ele = toiguielement(L,1); int x = luaL_optint(L,2,0); @@ -29,6 +67,7 @@ int moveiguielement(lua_State* L){ ele->e->move(position2d<s32>(x,y)); return 0; } +*/ int setiguitext(lua_State* L){ LIGUIElement* ele = toiguielement(L,1); @@ -41,12 +80,13 @@ int setiguitext(lua_State* L){ return 0; } +//remove({self}) int removeiguielement(lua_State* L){ - LIGUIElement* ele = toiguielement(L,1); - ele->e->remove(); - hashmap_free(ele->funcmap); - free(ele); - return 0; + lua_getfield(L,-1,"guielement"); + IGUIElement *ele = (IGUIElement*)lua_touserdata(L,-1); + ele->remove(); + lua_pop(L,2); + return 0; } int guigethandeler(lua_State* L){ diff --git a/src/client/lua_api/gui/iguielement.hpp b/src/client/lua_api/gui/iguielement.hpp index a036fd5..84fc2c9 100644 --- a/src/client/lua_api/gui/iguielement.hpp +++ b/src/client/lua_api/gui/iguielement.hpp @@ -9,6 +9,7 @@ extern "C" { #include <irrlicht.h> int moveiguielement(lua_State* L); +int getiguiclippingrect(lua_State* L); int setiguitext(lua_State* L); int removeiguielement(lua_State* L); int guigethandeler(lua_State* L); diff --git a/src/client/lua_api/gui/iguiimage.cpp b/src/client/lua_api/gui/iguiimage.cpp index fea283b..af1e133 100644 --- a/src/client/lua_api/gui/iguiimage.cpp +++ b/src/client/lua_api/gui/iguiimage.cpp @@ -31,33 +31,34 @@ extern IGUIEnvironment* env; //EGUI_EVENT_TYPE etype = e.GUIEvent.EventType; //printf("Detected image event\n"); //if(etype == EGET_ELEMENT_CLOSED){ - //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); - //printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1)); - //LIGUIElement* tbut = checkiguiwindow(tL,-1); - //int hashmapresponse; - //char* hashkey = (char*)"onclose"; - //int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse); - //if(terror == MAP_OK){ //Only call if we actually have that function. - //printf("Looks like we have an onclose function, calling!\n"); - //lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function - //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement - //lua_call(tL,1,1); - ////int b = lua_isnoneornil(tL,1); - //int a = lua_toboolean(tL,-1); - //printf("a:%d\n",a); - //return a; - //} + //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); + //printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1)); + //LIGUIElement* tbut = checkiguiwindow(tL,-1); + //int hashmapresponse; + //char* hashkey = (char*)"onclose"; + //int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse); + //if(terror == MAP_OK){ //Only call if we actually have that function. + //printf("Looks like we have an onclose function, calling!\n"); + //lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function + //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement + //lua_call(tL,1,1); + ////int b = lua_isnoneornil(tL,1); + //int a = lua_toboolean(tL,-1); + //printf("a:%d\n",a); + //return a; + //} //} //printf("Oh no! an iguiimage generated an event!"); //return false; //} -//new({startx,starty},alpha,itexture) +//new({startx,starty},alpha,{itexture}) -> {guielement} static int newiguiimage(lua_State* L){ printf("Creating iguiimage\n"); + lua_getfield(L,-1,"texture");//{startx,starty},alpha,{itexture},*itexture video::ITexture* tex = (video::ITexture*)lua_touserdata(L,-1); - lua_pop(L,1); + lua_pop(L,2);//{startx,starty},alpha, bool usealpha = lua_toboolean(L,-1); lua_pop(L,1); @@ -68,18 +69,33 @@ static int newiguiimage(lua_State* L){ IGUIEnvironment* env = device->getGUIEnvironment(); IGUIImage* img = env->addImage(tex,core::position2d<s32>(sx,sy),usealpha,0,-1,L""); img->setImage(tex); - + + lua_newtable(L); lua_pushlightuserdata(L,img);//ud_iguiimg + lua_setfield(L,-2,"guielement"); luaL_getmetatable(L,"iguiimage");//ud_iguiimg,{m_iguiimg} - lua_setmetatable(L,-1);//ud_iguiimg + lua_setmetatable(L,-2);//ud_iguiimg return 1; } +//setcolor(self,{r,g,b,a}) +int setcolor(lua_State* L){ + long r,g,b,a; + popvector4i(L,&r,&g,&b,&a); + lua_getfield(L,-1,"guielement"); + IGUIImage *img = (IGUIImage*)lua_touserdata(L,-1); + img->setColor(video::SColor(a,r,g,b)); + lua_pop(L,2); + return 0; +} + static const luaL_reg iguiimage_m[] = { - //{"move", moveiguielement}, + {"move", moveiguielement}, + {"getabsrect", getiguiclippingrect}, + {"setcolor", setcolor}, //{"settext", setiguitext}, - //{"remove", removeiguielement}, + {"remove", removeiguielement}, {0, 0}, }; diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp index f11fbd6..150ba68 100644 --- a/src/client/lua_api/gui/iguiwindow.cpp +++ b/src/client/lua_api/gui/iguiwindow.cpp @@ -88,7 +88,6 @@ static const luaL_reg iguiwindow_m[] = { }; int iguiwindow_register(lua_State* L, IrrlichtDevice* d){ - printf("Loading window\n"); luaL_newmetatable(L,"gui.window");//m{gui.checkbox} luaL_register(L,NULL,iguiwindow_m); lua_pop(L,1);// diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp index 8662aa0..746489a 100644 --- a/src/client/lua_api/load_video.cpp +++ b/src/client/lua_api/load_video.cpp @@ -9,11 +9,72 @@ extern "C" { #include "video/itexture.hpp" #include "video/iimage.hpp" +#include "shared/lua_api/common.h" + +using namespace irr; +using namespace video; +using namespace core; + +extern IrrlichtDevice* device; +extern IVideoDriver* driver; + +//{texture},{x,y} +//{texture},{x,y},{sourcerect},,{color},use_alpha +int draw2dimage(lua_State* L){ + int nargs = lua_gettop(L); + printf("Drawing a 2d image\n"); + if(nargs == 2){ + printf("2-argument version\n"); + long x,y; + popvector2i(L,&x,&y); + lua_getfield(L,-1,"texture"); + ITexture *tex = (ITexture*)lua_touserdata(L,-1); + lua_pop(L,2); + driver->draw2DImage(tex,position2d<s32>(x,y)); + }else if(nargs == 5){ + printf("5-argument version\n"); + int usealpha = lua_toboolean(L,-1); + lua_pop(L,1); + printf("Got usealpha: %d\n",usealpha); + long r,g,b,a; + popvector4i(L,&r,&g,&b,&a); + long ssx,ssy,sex,sey; + poprecti(L,&ssx,&ssy,&sex,&sey); + long x,y; + popvector2i(L,&x,&y); + lua_getfield(L,-1,"texture"); + ITexture *tex = (ITexture*)lua_touserdata(L,-1); + if(tex == NULL){ + lua_pushstring(L,"Tried to draw a NULL texture"); + lua_error(L); + } + lua_pop(L,2); + rect<s32> clipedto; + driver->draw2DImage( + tex, + position2d<s32>(x,y), + rect<s32>(ssx,ssy,sex,sey), + &clipedto, + SColor(a,r,g,b), + usealpha == 1 + ); + }else{ + lua_pushstring(L,"Incorrect number of arguments to video.drawtexture() (expected 2 or 6)"); + lua_error(L); + } + return 0; +} + void load_videofuncs(lua_State* L){ printf("Loading video libraries...\n"); lua_newtable(L);//{} lua_setglobal(L,"video");// + lua_getglobal(L,"video");//{} + lua_pushcfunction(L,draw2dimage);//{},draw2dimage() + lua_setfield(L,-2,"drawtexture");//{} + lua_pop(L,1);// + smaterial_register(L); itexture_register(L); iimage_register(L); diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp index b832783..586085e 100644 --- a/src/client/lua_api/video/iimage.cpp +++ b/src/client/lua_api/video/iimage.cpp @@ -10,7 +10,7 @@ using namespace video; extern IrrlichtDevice* device; extern IVideoDriver* driver; -//newiimage(ECOLOR_FORMAT,{width,height}) +//newiimage(ECOLOR_FORMAT,{width,height}) -> {image} int newiimage(lua_State* L){ printf("Attempting to create new iimage\n"); long w,h; @@ -19,25 +19,62 @@ int newiimage(lua_State* L){ lua_pop(L,1); printf("All data collected, creating...\n"); IImage* img = driver->createImage((irr::video::ECOLOR_FORMAT)format,irr::core::dimension2d<u32>(w,h)); + lua_newtable(L); lua_pushlightuserdata(L,img); + lua_setfield(L,-2,"image"); luaL_getmetatable(L,"iimage"); lua_setmetatable(L,-2); printf("Everything sets up, returning\n"); return 1; } -//setPixel({x,y},{r,g,b,a},bool_shouldblend) +//newiimagefromfile("/path/to/file") -> {image} +int newiimagefromfile(lua_State* L){ + printf("Creating new iimage from file"); + const char* strpath = lua_tostring(L,-1); + lua_pop(L,1); + int numloaders = driver->getImageLoaderCount(); + bool hasloaded = false; + IImage* img; + for(int j = 0; j < numloaders; j++){ + IImageLoader* loader = driver->getImageLoader(j); + io::IReadFile* f = device->getFileSystem()->createAndOpenFile(strpath); + if(!loader->isALoadableFileExtension(strpath)) + continue; + if(!loader->isALoadableFileFormat(f)) + continue; + hasloaded = true; + img = loader->loadImage(f); + } + if(!hasloaded){ + lua_pushstring(L,"Failed to load file"); + lua_error(L); + } + if(!img){ + lua_pushstring(L,"Failed to load image"); + lua_error(L); + } + lua_newtable(L); + lua_pushlightuserdata(L,img); + lua_setfield(L,-2,"image"); + luaL_getmetatable(L,"iimage"); + lua_setmetatable(L,-2); + printf("IImage made, returning!"); + return 1; +} + +//setPixel({self},{x,y},{r,g,b,a},bool_shouldblend) int setiimagepixel(lua_State* L){ - printf("Setpixel called\n"); bool sb = lua_toboolean(L,-1);//{ud_iimage},{x,y},{r,g,b,a},bool_shouldblend lua_pop(L,1);//{ud_iimage},{x,y},{r,g,b,a} - long r,g,b,a; - popvector4i(L,&r,&g,&b,&a);//{ud_iimage},{x,y} + double r,g,b,a; + popvector4d(L,&r,&g,&b,&a);//{ud_iimage},{x,y} long x,y; popvector2i(L,&x,&y);//{ud_iimage} + lua_getfield(L,-1,"image"); IImage* img = (IImage*)lua_touserdata(L,-1);//{ud_iimage} img->setPixel(x,y,SColor(a,r,g,b),sb); - lua_pop(L,1); + lua_pop(L,2); return 0; } @@ -49,7 +86,6 @@ static const luaL_reg iimage_m[] = { #define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3); void iimage_register(lua_State* L){ - printf("Registering iimage...\n"); driver = device->getVideoDriver(); lua_getglobal(L,"video");//{} @@ -66,6 +102,8 @@ void iimage_register(lua_State* L){ lua_pushcfunction(L,newiimage);//{},newiimage() lua_setfield(L,-2,"newiimage");//{} + lua_pushcfunction(L,newiimagefromfile);//{},newiimagefromfile() + lua_setfield(L,-2,"newiimagefromfile");//{} lua_pop(L,1);// luaL_newmetatable(L,"iimage");//{m_iimage} @@ -77,5 +115,4 @@ void iimage_register(lua_State* L){ lua_pop(L,1);// - printf("registered iimage!\n"); } diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp index a7f4652..599a448 100644 --- a/src/client/lua_api/video/itexture.cpp +++ b/src/client/lua_api/video/itexture.cpp @@ -14,20 +14,42 @@ using namespace video; extern IrrlichtDevice* device; extern IVideoDriver* driver; -//newtexture(string name,IImage* image) +//newtexture(string name,{image}) -> {texture} int newitexture(lua_State* L){ + printf("About to create new texture\n"); + lua_getfield(L,-1,"image");//"name",{image},image* IImage* im = (IImage*) lua_touserdata(L,-1); - lua_pop(L,1); + lua_pop(L,2);//"name" const char* name = lua_tostring(L,-1); - lua_pop(L,1); + lua_pop(L,1);// + printf("About to create texture\n"); ITexture* tex = driver->addTexture(name,im); if(!tex){ lua_pushstring(L,"Failed to create texture!"); lua_error(L); } + lua_newtable(L); + lua_pushlightuserdata(L,tex); + lua_setfield(L,-2,"texture"); + + return 1; +} + +//newtexturefromfile(string file_name) -> {texture} +int newitexturefromfile(lua_State* L){ + const char* strpath = lua_tostring(L,-1); + lua_pop(L,1); + ITexture* tex = driver->getTexture(strpath); + if(!tex){ + lua_pushstring(L,"Failed to create texture!"); + lua_error(L); + } + + lua_newtable(L); lua_pushlightuserdata(L,tex); + lua_setfield(L,-2,"texture"); return 1; } @@ -35,7 +57,10 @@ int newitexture(lua_State* L){ void itexture_register(lua_State* L){ - lua_getglobal(L,"video"); - lua_pushcfunction(L,newitexture); - lua_setfield(L,-2,"newtexture"); + lua_getglobal(L,"video");//{} + lua_pushcfunction(L,newitexture);//{},newitexture + lua_setfield(L,-2,"newtexture");//{} + lua_pushcfunction(L,newitexturefromfile); + lua_setfield(L,-2,"newtexturefromfile"); + lua_pop(L,1); } |
