aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_sprite.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-15 19:29:27 +0800
committerchai <chaifix@163.com>2018-11-15 19:29:27 +0800
commit7e51ff3bfae0becc260452a427a1fc1232a4b348 (patch)
treee2c4cddcd5ed719a611be4c92edf1991a63203c5 /src/lua/modules/graphics/je_lua_sprite.cpp
parenta6f2d5fff89b7322009c46a9272668ca4c32ce64 (diff)
*修改代码结构
Diffstat (limited to 'src/lua/modules/graphics/je_lua_sprite.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
index ec5887c..97128a9 100644
--- a/src/lua/modules/graphics/je_lua_sprite.cpp
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -197,7 +197,41 @@ namespace JinEngine
return 0;
}
- LUA_EXPORT int luaopen_Sprite(lua_State* L)
+ LUA_IMPLEMENT int l_getGraphic(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrGraphic = shrSprite.getDependency((int)SpriteDependency::DEP_GRAPHIC);
+ if (shrGraphic->isType(Jin_Lua_Canvas))
+ {
+ Proxy* pxyCanvas = luax_newinstance(L, Jin_Lua_Canvas);
+ pxyCanvas->bind(shrGraphic);
+ return 1;
+ }
+ else if (shrGraphic->isType(Jin_Lua_Texture))
+ {
+ Proxy* pxyTexture = luax_newinstance(L, Jin_Lua_Texture);
+ pxyTexture->bind(shrGraphic);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getShader(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrShader = shrSprite.getDependency((int)SpriteDependency::DEP_SHADER);
+ if (shrShader != nullptr && shrShader->isType(Jin_Lua_Shader))
+ {
+ Proxy* pxyShader = luax_newinstance(L, Jin_Lua_Shader);
+ pxyShader->bind(shrShader);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Sprite(lua_State* L)
{
luaL_Reg methods[] = {
{ "__gc", l_gc },
@@ -217,10 +251,11 @@ namespace JinEngine
{ "getOrigin", l_getOrigin },
{ "getScale", l_getScale },
{ "getColor", l_getColor },
+ { "getShader", l_getShader },
+ { "getGraphic", l_getGraphic },
{ 0, 0 }
};
luax_newtype(L, Jin_Lua_Sprite, methods);
- return 0;
}
} // namespace Lua