aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_sprite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/je_lua_sprite.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp210
1 files changed, 14 insertions, 196 deletions
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
index 76d6c1f..0a56de8 100644
--- a/src/lua/modules/graphics/je_lua_sprite.cpp
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -8,6 +8,7 @@
#include "je_lua_texture.h"
#include "je_lua_shader.h"
+using namespace JinEngine::Math;
using namespace JinEngine::Graphics;
using namespace JinEngine::Graphics::Shaders;
@@ -32,217 +33,34 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT int l_setRotation(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- float r = luax_checknumber(L, 2);
- sprite->setRotation(r);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setOrigin(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- switch (luax_gettop(L))
- {
- case 2:
- {
- int origin = luax_checkinteger(L, 2);
- sprite->setOrigin(static_cast<Sprite::Origin>(origin));
- }
- break;
- case 3:
- {
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- sprite->setOrigin(x, y);
- }
- break;
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setPosition(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- float x = luax_checknumber(L, 2);
- float y = luax_checknumber(L, 3);
- sprite->setPosition(x, y);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setScale(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- float sx = luax_checknumber(L, 2);
- float sy = luax_checknumber(L, 3);
- sprite->setScale(sx, sy);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setColor(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- Channel r = luax_checkinteger(L, 2);
- Channel g = luax_checkinteger(L, 3);
- Channel b = luax_checkinteger(L, 4);
- Channel a = luax_checkinteger(L, 5);
- sprite->setColor(Color(r, g, b, a));
- return 0;
- }
-
- LUA_IMPLEMENT int l_setGraphic(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- Graphic* graphic = nullptr;
- Proxy* p = nullptr;
- if (luax_istype(L, 2, Jin_Lua_Texture))
- p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Texture);
- else if (luax_istype(L, 2, Jin_Lua_Canvas))
- p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Canvas);
- if (p != nullptr)
- {
- sprite->setGraphic(p->getObject<Graphic>());
- sprite.setDependency((int)SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_move(lua_State* L)
+ LUA_IMPLEMENT int l_render(lua_State* L)
{
SharedSprite sprite = checkSprite(L);
float x = luax_checknumber(L, 2);
float y = luax_checknumber(L, 3);
- sprite->move(x, y);
+ 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);
return 0;
}
- LUA_IMPLEMENT int l_scale(lua_State* L)
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
{
SharedSprite sprite = checkSprite(L);
- float sx = luax_checknumber(L, 2);
- float sy = luax_checknumber(L, 3);
- sprite->scale(sx, sy);
- return 0;
- }
-
- LUA_IMPLEMENT int l_rotate(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- float r = luax_checknumber(L, 2);
- sprite->rotate(r);
- return 0;
- }
-
- LUA_IMPLEMENT int l_getRotation(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- float r = sprite->getRotation();
- luax_pushnumber(L, r);
+ Vector2<int> size = sprite->getSize();
+ luax_pushinteger(L, size.x);
+ luax_pushinteger(L, size.y);
return 1;
}
- LUA_IMPLEMENT int l_getPosition(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- const Math::Vector2<float>& pos = sprite->getPosition();
- luax_pushnumber(L, pos.x);
- luax_pushnumber(L, pos.y);
- return 2;
- }
-
- LUA_IMPLEMENT int l_getOrigin(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- const Math::Vector2<float>& origin = sprite->getOrigin();
- luax_pushinteger(L, origin.x);
- luax_pushinteger(L, origin.y);
- return 2;
- }
-
- LUA_IMPLEMENT int l_getScale(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- const Math::Vector2<float> scale = sprite->getScale();
- luax_pushnumber(L, scale.x);
- luax_pushnumber(L, scale.y);
- return 2;
- }
-
- LUA_IMPLEMENT int l_getColor(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- const Color& c = sprite->getColor();
- luax_pushinteger(L, c.r);
- luax_pushinteger(L, c.g);
- luax_pushinteger(L, c.b);
- luax_pushinteger(L, c.a);
- return 4;
- }
-
- LUA_IMPLEMENT int l_render(lua_State* L)
- {
- SharedSprite sprite = checkSprite(L);
- sprite->render();
- return 0;
- }
-
- 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 },
- { "render", l_render },
- { "setRotation", l_setRotation },
- { "setOrigin", l_setOrigin },
- { "setPosition", l_setPosition },
- { "setScale", l_setScale },
- { "setColor", l_setColor },
- { "setGraphic", l_setGraphic },
- { "move", l_move },
- { "scale", l_scale },
- { "rotate", l_rotate },
- { "getRotation", l_getRotation },
- { "getPosition", l_getPosition },
- { "getOrigin", l_getOrigin },
- { "getScale", l_getScale },
- { "getColor", l_getColor },
- { "getShader", l_getShader },
- { "getGraphic", l_getGraphic },
- { 0, 0 }
+ { "__gc", l_gc },
+ { "render", l_render },
+ { "getSize", l_getSize },
+ { 0, 0 }
};
luax_newtype(L, Jin_Lua_Sprite, methods);
}