diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-06-23 06:52:55 -0600 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-06-23 06:52:55 -0600 |
| commit | e6faff1394864a1fe0d517584d1c104997dff39f (patch) | |
| tree | d7956fc8aabef903f354578d69d4d7fdf64ec928 /src/client/lua_api/load_video.cpp | |
| parent | 1aaa348ac080c97c0aeb0a02146ae26b74add5a1 (diff) | |
| parent | 9fa5dcc9310a8c6ff8c77a47a86303f7b950dcf3 (diff) | |
| download | brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.gz brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.bz2 brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.zip | |
Merge branch 'master' of ssh://cogarr.net:43/home/git/brokengine
Diffstat (limited to 'src/client/lua_api/load_video.cpp')
| -rw-r--r-- | src/client/lua_api/load_video.cpp | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp index 8662aa0..df3a9aa 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), + NULL, + 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"); + //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); |
