From a28a019db35fee7545cd215c19a9a7022b3931b7 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Fri, 21 Aug 2015 15:59:19 +0200 Subject: [PATCH] Added many things in the gfx.texture lib. --- sdcard/3ds/ctruLua/example.lua | 2 +- source/texture.c | 47 ++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/sdcard/3ds/ctruLua/example.lua b/sdcard/3ds/ctruLua/example.lua index 1908502..ddd619d 100644 --- a/sdcard/3ds/ctruLua/example.lua +++ b/sdcard/3ds/ctruLua/example.lua @@ -65,7 +65,7 @@ while ctr.run() do gfx.text(5, 20, "Hello world, from Lua !", 20) gfx.text(5, 30, "Time: "..os.date()) - texture1:draw(240, 10); + texture1:draw(240, 10, angle); local cx, cy = hid.circle() gfx.rectangle(40, 90, 60, 60, 0, 0xDDDDDDFF) diff --git a/source/texture.c b/source/texture.c index fbe8c01..354e425 100644 --- a/source/texture.c +++ b/source/texture.c @@ -6,7 +6,8 @@ typedef struct { sf2d_texture *texture; - //u32 blendColor = 0xffffffff; + float scaleX; + float scaleY; } texture_userdata; u8 getType(const char *name) { @@ -39,6 +40,9 @@ static int texture_load(lua_State *L) { return 2; } + texture->scaleX = 1.0f; + texture->scaleY = 1.0f; + return 1; } @@ -46,8 +50,28 @@ static int texture_draw(lua_State *L) { texture_userdata *texture = luaL_checkudata(L, 1, "LTexture"); int x = luaL_checkinteger(L, 2); int y = luaL_checkinteger(L, 3); + float rad = luaL_optnumber(L, 4, 0.0f); - sf2d_draw_texture(texture->texture, x, y); + if (rad == 0.0f && texture->scaleX == 1.0f && texture->scaleY == 1.0f) { + sf2d_draw_texture(texture->texture, x, y); + } else { + sf2d_draw_texture_rotate_cut_scale(texture->texture, x, y, rad, 0, 0, texture->texture->width, texture->texture->height, texture->scaleX, texture->scaleY); + } + + return 0; +} + +static int texture_drawPart(lua_State *L) { + texture_userdata *texture = luaL_checkudata(L, 1, "LTexture"); + int x = luaL_checkinteger(L, 2); + int y = luaL_checkinteger(L, 3); + int sx = luaL_checkinteger(L, 4); + int sy = luaL_checkinteger(L, 5); + int w = luaL_checkinteger(L, 6); + int h = luaL_checkinteger(L, 7); + int rad = luaL_optnumber(L, 8, 0.0f); + + sf2d_draw_texture_rotate_cut_scale(texture->texture, x, y, rad, sx, sy, w, h, texture->scaleX, texture->scaleY); return 0; } @@ -61,11 +85,24 @@ static int texture_unload(lua_State *L) { return 0; } +static int texture_scale(lua_State *L) { + texture_userdata *texture = luaL_checkudata(L, 1, "LTexture"); + float sx = luaL_checknumber(L, 2); + float sy = luaL_checknumber(L, 3); + + texture->scaleX = sx; + texture->scaleY = sy; + + return 0; +} + // object static const struct luaL_Reg texture_methods[] = { - {"draw", texture_draw }, - {"unload", texture_unload}, - {"__gc", texture_unload}, + {"draw", texture_draw }, + {"drawPart", texture_drawPart }, + {"scale", texture_scale }, + {"unload", texture_unload }, + {"__gc", texture_unload }, {NULL, NULL} };