aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics')
-rw-r--r--src/lua/modules/graphics/je_lua_animation.cpp33
-rw-r--r--src/lua/modules/graphics/je_lua_animator.cpp9
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp7
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp51
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.cpp6
-rw-r--r--src/lua/modules/graphics/je_lua_text.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp7
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp7
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp7
13 files changed, 75 insertions, 72 deletions
diff --git a/src/lua/modules/graphics/je_lua_animation.cpp b/src/lua/modules/graphics/je_lua_animation.cpp
index 9c4eaeb..d054761 100644
--- a/src/lua/modules/graphics/je_lua_animation.cpp
+++ b/src/lua/modules/graphics/je_lua_animation.cpp
@@ -85,17 +85,34 @@ namespace JinEngine
return 1;
}
+ LUA_IMPLEMENT int l_getFrame(lua_State* L)
+ {
+ SharedAnimation shrAnimation = checkAnimation(L);
+ int i = luax_checkinteger(L, 2);
+ SharedBase* shrFrame = shrAnimation.getDependency((int)AnimationDependency::DEP_SPRITES + i);
+ luax_getobject(L, shrFrame);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int getFrameCount(lua_State* L)
+ {
+ SharedAnimation shrAnimation = checkAnimation(L);
+ int n = shrAnimation->getFrameCount();
+ luax_pushinteger(L, n);
+ return 1;
+ }
+
LUA_EXPORT void luaopen_Animation(lua_State* L)
{
luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "addFrame", l_addFrame },
- { "addFrames", l_addFrames },
- { "isLoop", l_isLoop },
- { "getSpeed", l_getSpeed },
- { "getFrameCount", l_getSpeed },
- //{ "getFrame", l_getFrame },
- { 0, 0 }
+ { "__gc", l_gc },
+ { "addFrame", l_addFrame },
+ { "addFrames", l_addFrames },
+ { "isLoop", l_isLoop },
+ { "getSpeed", l_getSpeed },
+ { "getFrameCount", getFrameCount },
+ { "getFrame", l_getFrame },
+ { 0, 0 }
};
luax_newtype(L, Jin_Lua_Animation, methods);
}
diff --git a/src/lua/modules/graphics/je_lua_animator.cpp b/src/lua/modules/graphics/je_lua_animator.cpp
index 519bc75..857d375 100644
--- a/src/lua/modules/graphics/je_lua_animator.cpp
+++ b/src/lua/modules/graphics/je_lua_animator.cpp
@@ -132,6 +132,14 @@ namespace JinEngine
return 0;
}
+ LUA_IMPLEMENT int l_getSpeed(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ float speed = shrAnimator->getSpeed();
+ luax_pushnumber(L, speed);
+ return 1;
+ }
+
LUA_EXPORT void luaopen_Animator(lua_State* L)
{
luaL_Reg methods[] = {
@@ -148,6 +156,7 @@ namespace JinEngine
{ "setDefaultSpeed", l_setDefaultSpeed },
{ "setLoop", l_setLoop },
{ "setDefaultLoop", l_setDefaultLoop },
+ { "getSpeed", l_getSpeed },
{ 0, 0 }
};
luax_newtype(L, Jin_Lua_Animator, methods);
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
index 24641a0..2495fb3 100644
--- a/src/lua/modules/graphics/je_lua_bitmap.cpp
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -90,14 +90,13 @@ namespace JinEngine
SharedBitmap shared = checkBitmap(L);
Bitmap* bitmap = shared.getObject();
Bitmap* b = Bitmap::clone(bitmap);
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
- proxy->bind(new Shared<Bitmap>(b, Jin_Lua_Bitmap));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(b, Jin_Lua_Bitmap));
return 1;
}
LUA_EXPORT void luaopen_Bitmap(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "getWidth", l_getWidth },
{ "getHeight", l_getHeight },
@@ -107,7 +106,7 @@ namespace JinEngine
{ "clone", l_clone },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_Bitmap, f);
+ luax_newtype(L, Jin_Lua_Bitmap, methods);
}
} // namespace Graphics
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
index 3c1e606..5cbcf98 100644
--- a/src/lua/modules/graphics/je_lua_canvas.cpp
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -52,14 +52,14 @@ namespace JinEngine
LUA_EXPORT void luaopen_Canvas(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "getWidth", l_getWidth },
{ "getHeight", l_getHeight },
{ "getSize", l_getSize },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_Canvas, f);
+ luax_newtype(L, Jin_Lua_Canvas, methods);
}
} // namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 4ebd1ee..cc67055 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -208,8 +208,7 @@ namespace JinEngine
return 1;
}
}
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
- proxy->bind(new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap));
return 1;
}
@@ -229,8 +228,7 @@ namespace JinEngine
const char* path = luax_checkstring(L, 1);
texture = Texture::createTexture(path);
}
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture);
- proxy->bind(new Shared<Texture>(texture, Jin_Lua_Texture));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture, new Shared<Texture>(texture, Jin_Lua_Texture));
return 1;
}
@@ -244,8 +242,7 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
- proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
@@ -268,8 +265,7 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
- proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
@@ -277,9 +273,8 @@ namespace JinEngine
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas);
Canvas* cvs = Canvas::createCanvas(w, h);
- proxy->bind(new Shared<Canvas>(cvs, Jin_Lua_Canvas));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas, new Shared<Canvas>(cvs, Jin_Lua_Canvas));
return 1;
}
@@ -676,7 +671,6 @@ namespace JinEngine
LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
- Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData);
TTFData* fd = nullptr;
{
const char* path = luax_checkstring(L, 1);
@@ -691,7 +685,7 @@ namespace JinEngine
fs->read(path, b);
fd = TTFData::createTTFData(&b, b.size());
}
- proxy->bind(new Shared<TTFData>(fd, Jin_Lua_TTFData));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData, new Shared<TTFData>(fd, Jin_Lua_TTFData));
return 1;
}
@@ -714,8 +708,7 @@ namespace JinEngine
unsigned length;
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
- Proxy* proxy = luax_newinstance(L, Jin_Lua_Text);
- proxy->bind(new Shared<Text>(text, Jin_Lua_Text));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Text, new Shared<Text>(text, Jin_Lua_Text));
return 1;
}
@@ -743,8 +736,7 @@ namespace JinEngine
quad.h = luax_rawgetnumberthenpop(L, 2, 4);
int o = luax_checkinteger(L, 3);
Origin origin = static_cast<Origin>(o);
- Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
- p->bind(new Shared<Sprite>(new Sprite(graphic, quad, origin), Jin_Lua_Sprite));
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, quad, origin), Jin_Lua_Sprite));
}
else if (n == 4)
{
@@ -755,22 +747,19 @@ namespace JinEngine
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));
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, quad, ox, oy), Jin_Lua_Sprite));
}
else if (n == 2)
{
int o = luax_checkinteger(L, 2);
Origin origin = static_cast<Origin>(o);
- Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
- p->bind(new Shared<Sprite>(new Sprite(graphic, origin), Jin_Lua_Sprite));
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, 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));
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, ox, oy), Jin_Lua_Sprite));
}
else
{
@@ -791,12 +780,11 @@ namespace JinEngine
pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
if (pxyGraphic != nullptr)
{
- Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet);
Graphic* graphic = pxyGraphic->getObject<Graphic>();
Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), Jin_Lua_SpriteSheet);
Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>();
shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
- pxySSheet->bind(shrSSheet);
+ Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet, shrSSheet);
return 1;
}
else
@@ -830,8 +818,7 @@ namespace JinEngine
(*shrAnimation)->setLoop(loop);
(*shrAnimation)->setSpeed(speed);
}
- Proxy* pxyAnimation = luax_newinstance(L, Jin_Lua_Animation);
- pxyAnimation->bind(shrAnimation);
+ Proxy* pxyAnimation = luax_newinstance(L, Jin_Lua_Animation, shrAnimation);
return 1;
}
@@ -847,8 +834,7 @@ namespace JinEngine
(*shrAniamtor)->setAnimation(shrAnimtion.getObject());
(*shrAniamtor).setDependency((int)AnimatorDependency::DEP_ANIMATION, &shrAnimtion);
}
- Proxy* pxyAnimator = luax_newinstance(L, Jin_Lua_Animator);
- pxyAnimator->bind(shrAniamtor);
+ Proxy* pxyAnimator = luax_newinstance(L, Jin_Lua_Animator, shrAniamtor);
return 1;
}
@@ -899,8 +885,7 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont);
- proxy->bind(new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont, new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont));
return 1;
}
@@ -985,7 +970,7 @@ namespace JinEngine
luaopen_Animation(L);
luaopen_Animator(L);
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
/* window */
{ "init", l_init },
{ "setTitle", l_setTitle },
@@ -1041,10 +1026,8 @@ namespace JinEngine
{ "scale", l_scale },
{ 0, 0 }
};
-
// Load whole lib.
- luax_newlib(L, f);
-
+ luax_newlib(L, methods);
return 1;
}
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
index 00a9302..c3fdc7e 100644
--- a/src/lua/modules/graphics/je_lua_page.cpp
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -55,14 +55,14 @@ namespace JinEngine
LUA_EXPORT void luaopen_Page(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "getSize", l_getSize },
{ "getWidth", l_getWidth },
{ "getHeight", l_getHeight },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_Page, f);
+ luax_newtype(L, Jin_Lua_Page, methods);
}
} // namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
index c04b360..cfe2260 100644
--- a/src/lua/modules/graphics/je_lua_shader.cpp
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -119,7 +119,7 @@ namespace JinEngine
LUA_EXPORT void luaopen_Shader(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "sendNumber", l_sendNumber },
{ "sendTexture", l_sendTexture },
@@ -130,7 +130,7 @@ namespace JinEngine
{ "sendColor", l_sendColor },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_Shader, f);
+ luax_newtype(L, Jin_Lua_Shader, methods);
}
} // namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp
index 9496fbf..57b610c 100644
--- a/src/lua/modules/graphics/je_lua_spritesheet.cpp
+++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp
@@ -48,10 +48,9 @@ namespace JinEngine
origin = static_cast<Origin>(o);
spr = sheet->createSprite(quad, origin);
}
- Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite);
Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, Jin_Lua_Sprite);
shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet);
- pxySprite->bind(shrSprite);
+ Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite, shrSprite);
return 1;
}
@@ -98,10 +97,9 @@ namespace JinEngine
for (int i = 0; i < sprs.size(); ++i)
{
Sprite* spr = sprs[i];
- Proxy* pxys = (Proxy*)luax_newinstance(L, Jin_Lua_Sprite);
Shared<Sprite>* shrSpr = new Shared<Sprite>(spr, Jin_Lua_Sprite);
shrSpr->setDependency((int)SpriteDependency::DEP_GRAPHIC, shrGraphic);
- pxys->bind(shrSpr);
+ Proxy* pxys = (Proxy*)luax_newinstance(L, Jin_Lua_Sprite, shrSpr);
luax_rawseti(L, -2, i + 1);
}
return 1;
diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp
index 0db6c32..6509e73 100644
--- a/src/lua/modules/graphics/je_lua_text.cpp
+++ b/src/lua/modules/graphics/je_lua_text.cpp
@@ -21,11 +21,11 @@ namespace JinEngine
LUA_EXPORT void luaopen_Text(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_Text, f);
+ luax_newtype(L, Jin_Lua_Text, methods);
}
} // namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
index 712c4ac..5402a99 100644
--- a/src/lua/modules/graphics/je_lua_texture.cpp
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -52,14 +52,14 @@ namespace JinEngine
LUA_EXPORT void luaopen_Texture(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "getWidth", l_getWidth },
{ "getHeight", l_getHeight },
{ "getSize", l_getSize },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_Texture, f);
+ luax_newtype(L, Jin_Lua_Texture, methods);
}
}// namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index 5bbe154..61c559b 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -45,21 +45,20 @@ namespace JinEngine
Text* text = p2->getObject<Text>();
page = tf->typeset(*text, lineheight, spacing);
}
- Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
Shared<Page>* shrPage = new Shared<Page>(page, Jin_Lua_Page);
shrPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, &shrTexFont);
- pxyPage->bind(shrPage);
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page, shrPage);
return 1;
}
LUA_EXPORT void luaopen_TextureFont(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "typeset", l_typeset },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_TextureFont, f);
+ luax_newtype(L, Jin_Lua_TextureFont, methods);
}
} // namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
index a1da345..7fea04b 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -45,21 +45,20 @@ namespace JinEngine
Text* text = pxyText->getObject<Text>();
page = ttf->typeset(*text, lineheight, spacing);
}
- Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
Shared<Page>* refPage = new Shared<Page>(page, Jin_Lua_Page);
refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF);
- pxyPage->bind(refPage);
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page, refPage);
return 1;
}
LUA_EXPORT void luaopen_TTF(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "typeset", l_typeset },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_TTF, f);
+ luax_newtype(L, Jin_Lua_TTF, methods);
}
} // namespace Lua
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
index dedf082..aa2280f 100644
--- a/src/lua/modules/graphics/je_lua_ttf_data.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -22,11 +22,10 @@ namespace JinEngine
int fontsize = luax_checkinteger(L, 2);
Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>();
TTFData* fontData = shrFontData.getObject();
- Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF);
TTF* font = fontData->createTTF(fontsize);
Shared<TTF>* shrTTF = new Shared<TTF>(font, Jin_Lua_TTF);
shrTTF->setDependency((int)TTFDependency::DEP_TTFDATA, &shrFontData);
- pxyTTF->bind(shrTTF);
+ Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF, shrTTF);
return 1;
}
@@ -39,12 +38,12 @@ namespace JinEngine
LUA_EXPORT void luaopen_TTFData(lua_State* L)
{
- luaL_Reg f[] = {
+ luaL_Reg methods[] = {
{ "__gc", l_gc },
{ "newTTF", l_newTTF },
{ 0, 0 }
};
- luax_newtype(L, Jin_Lua_TTFData, f);
+ luax_newtype(L, Jin_Lua_TTFData, methods);
}