aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/load_video.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/lua_api/load_video.cpp')
-rw-r--r--src/client/lua_api/load_video.cpp63
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);