diff options
Diffstat (limited to 'src/lua/modules/graphics/je_lua_graphics.cpp')
-rw-r--r-- | src/lua/modules/graphics/je_lua_graphics.cpp | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 900b26b..2bc3a78 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -21,6 +21,7 @@ using namespace std; using namespace JinEngine; +using namespace JinEngine::Math; using namespace JinEngine::Graphics; using namespace JinEngine::Graphics::Fonts; using namespace JinEngine::Graphics::Shaders; @@ -391,8 +392,13 @@ namespace JinEngine if (!luax_istype(L, 1, Jin_Lua_Sprite)) return; Proxy* pxySprite = (Proxy*)luax_toudata(L, 1); - Sprite* spr = pxySprite->getObject<Sprite>(); - spr->render(); + Sprite* sprite = pxySprite->getObject<Sprite>(); + float x = luax_checknumber(L, 2); + float y = luax_checknumber(L, 3); + float sx = luax_checknumber(L, 4); + float sy = luax_checknumber(L, 5); + float r = luax_checknumber(L, 6); + sprite->render(x, y, sx, sy, r); } LUA_IMPLEMENT int l_draw(lua_State* L) @@ -710,10 +716,66 @@ namespace JinEngine return 1; } + // newSprite(Texture tex, Quad quad, Origin origin) + // newSprite(Texture tex, Quad quad, Number ox, Number oy) + // newSprite(Texture tex, Origin origin) + // newSprite(Texture tex, Number ox, Number oy) LUA_IMPLEMENT int l_newSprite(lua_State* L) { - Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); - p->bind(new Shared<Sprite>(new Sprite(), Jin_Lua_Sprite)); + int n = luax_gettop(L); + Proxy* pxyGraphic = nullptr; + if (luax_istype(L, 1, Jin_Lua_Texture)) + pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture); + else if (luax_istype(L, 1, Jin_Lua_Canvas)) + pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas); + Graphic* graphic = pxyGraphic->getObject<Graphic>(); + if (pxyGraphic != nullptr) + { + if (n == 3 && luax_istable(L, 2)) + { + Quad quad; + quad.x = luax_rawgetnumberthenpop(L, 2, 1); + quad.y = luax_rawgetnumberthenpop(L, 2, 2); + quad.w = luax_rawgetnumberthenpop(L, 2, 3); + quad.h = luax_rawgetnumberthenpop(L, 2, 4); + int o = luax_checkinteger(L, 3); + Sprite::Origin origin = static_cast<Sprite::Origin>(o); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); + p->bind(new Shared<Sprite>(new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); + } + else if (n == 4) + { + Quad quad; + quad.x = luax_rawgetnumberthenpop(L, 2, 1); + quad.y = luax_rawgetnumberthenpop(L, 2, 2); + quad.w = luax_rawgetnumberthenpop(L, 2, 3); + quad.h = luax_rawgetnumberthenpop(L, 2, 4); + int ox = luax_checkinteger(L, 3); + int oy = luax_checkinteger(L, 4); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); + p->bind(new Shared<Sprite>(new Sprite(graphic, quad, ox, oy), Jin_Lua_Sprite)); + } + else if (n == 2) + { + int o = luax_checkinteger(L, 2); + Sprite::Origin origin = static_cast<Sprite::Origin>(o); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); + p->bind(new Shared<Sprite>(new Sprite(graphic, origin), Jin_Lua_Sprite)); + } + else if (n == 3) + { + int ox = luax_checkinteger(L, 2); + int oy = luax_checkinteger(L, 3); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); + p->bind(new Shared<Sprite>(new Sprite(graphic, ox, oy), Jin_Lua_Sprite)); + } + else + { + luax_error(L, "No matched overloaded functions."); + return 1; + } + } + return 1; } |