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_bitmap.cpp36
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp18
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp50
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp24
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp18
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp2
9 files changed, 83 insertions, 71 deletions
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
index 8d4897b..2a35ed5 100644
--- a/src/lua/modules/graphics/je_lua_bitmap.cpp
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -10,9 +10,9 @@ namespace JinEngine
namespace Lua
{
- typedef Shared<Bitmap>& BitmapRef;
+ typedef Shared<Bitmap>& SharedBitmap;
- LUA_IMPLEMENT inline BitmapRef checkBitmap(lua_State* L)
+ LUA_IMPLEMENT inline SharedBitmap checkBitmap(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
return proxy->getShared<Bitmap>();
@@ -20,32 +20,32 @@ namespace JinEngine
LUA_IMPLEMENT int l_gc(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
- ref.release();
+ SharedBitmap shared = checkBitmap(L);
+ shared.release();
return 0;
}
LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
luax_pushinteger(L, w);
return 1;
}
LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
- int h = ref->getHeight();
+ SharedBitmap shared = checkBitmap(L);
+ int h = shared->getHeight();
luax_pushinteger(L, h);
return 1;
}
LUA_IMPLEMENT int l_getSize(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- int h = ref->getHeight();
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ int h = shared->getHeight();
luax_pushinteger(L, w);
luax_pushinteger(L, h);
return 2;
@@ -53,10 +53,10 @@ namespace JinEngine
LUA_IMPLEMENT int l_getPixel(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
+ SharedBitmap shared = checkBitmap(L);
int x = luax_checkinteger(L, 2);
int y = luax_checkinteger(L, 3);
- Color col = ref->getPixel(x, y);
+ Color col = shared->getPixel(x, y);
luax_pushinteger(L, col.r);
luax_pushinteger(L, col.g);
luax_pushinteger(L, col.b);
@@ -66,7 +66,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_setPixel(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
+ SharedBitmap shared = checkBitmap(L);
int x = luax_checkinteger(L, 2);
int y = luax_checkinteger(L, 3);
if (!luax_istable(L, 4))
@@ -78,16 +78,16 @@ namespace JinEngine
unsigned int g = luax_rawgetnumber(L, 4, 2);
unsigned int b = luax_rawgetnumber(L, 4, 3);
unsigned int a = luax_rawgetnumber(L, 4, 4);
- ref->setPixel(Color(r, g, b, a), x, y);
+ shared->setPixel(Color(r, g, b, a), x, y);
return 0;
}
LUA_IMPLEMENT int l_clone(lua_State* L)
{
- BitmapRef ref = checkBitmap(L);
- Bitmap* bitmap = ref.getObject();
+ SharedBitmap shared = checkBitmap(L);
+ Bitmap* bitmap = shared.getObject();
Bitmap* b = Bitmap::clone(bitmap);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_BITMAP);
proxy->bind(new Shared<Bitmap>(b, JIN_GRAPHICS_BITMAP));
return 1;
}
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
index 87516b3..42570b2 100644
--- a/src/lua/modules/graphics/je_lua_canvas.cpp
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -10,9 +10,9 @@ namespace JinEngine
namespace Lua
{
- typedef Shared<Canvas>& CanvasRef;
+ typedef Shared<Canvas>& SharedCanvas;
- LUA_IMPLEMENT inline CanvasRef checkCanvas(lua_State* L)
+ LUA_IMPLEMENT inline SharedCanvas checkCanvas(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
return proxy->getShared<Canvas>();
@@ -20,23 +20,23 @@ namespace JinEngine
LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
return 1;
}
LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getHeight());
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getHeight());
return 1;
}
LUA_IMPLEMENT int l_getSize(lua_State* L)
{
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
return 2;
}
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 639a542..24cdf59 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -164,7 +164,7 @@ namespace JinEngine
return 1;
}
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_BITMAP);
proxy->bind(new Shared<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
return 1;
}
@@ -185,7 +185,7 @@ namespace JinEngine
const char* path = luax_checkstring(L, 1);
texture = Texture::createTexture(path);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TEXTURE);
proxy->bind(new Shared<Texture>(texture, JIN_GRAPHICS_TEXTURE));
return 1;
}
@@ -200,7 +200,7 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_SHADER);
proxy->bind(new Shared<Shader>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
@@ -224,7 +224,7 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_SHADER);
proxy->bind(new Shared<Shader>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
@@ -233,7 +233,7 @@ namespace JinEngine
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_CANVAS);
Canvas* cvs = Canvas::createCanvas(w, h);
proxy->bind(new Shared<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
return 1;
@@ -462,8 +462,8 @@ namespace JinEngine
return 0;
}
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- Shared<Canvas>& ref = proxy->getShared<Canvas>();
- Canvas::bind(ref.getObject());
+ Shared<Canvas>& shared = proxy->getShared<Canvas>();
+ Canvas::bind(shared.getObject());
return 0;
}
@@ -496,10 +496,18 @@ namespace JinEngine
LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
- return 0;
+ return 0;
}
-#define IntToRenderMode(I) static_cast<RenderMode>(I)
+ LUA_IMPLEMENT RenderMode strtomode(const char* str)
+ {
+ std::string s = std::string(str);
+ if (s == "fill")
+ return RenderMode::FILL;
+ else if (s == "line")
+ return RenderMode::LINE;
+ else return RenderMode::NONE;
+ }
LUA_IMPLEMENT int l_point(lua_State* L)
{
@@ -523,7 +531,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_rect(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -543,7 +552,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_circle(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -562,7 +572,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_triangle(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -587,8 +598,9 @@ namespace JinEngine
LUA_IMPLEMENT int l_polygon(lua_State* L)
{
- RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
- int n = luax_checknumber(L, 2);
+ const char* modestr = luax_checkstring(L, 1);
+ int n = luax_checknumber(L, 2);
+ RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
if (!luax_istable(L, 3))
@@ -621,7 +633,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTFDATA, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TTFDATA);
TTFData* fd = nullptr;
{
const char* path = luax_checkstring(L, 1);
@@ -659,7 +671,7 @@ namespace JinEngine
unsigned length;
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXT, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TEXT);
proxy->bind(new Shared<Text>(text, JIN_GRAPHICS_TEXT));
return 1;
}
@@ -711,7 +723,7 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT);
proxy->bind(new Shared<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
return 1;
}
@@ -798,7 +810,7 @@ namespace JinEngine
LUA_EXPORT int luaopen_graphics(lua_State* L)
{
- // Register types.
+ // register types
luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
@@ -809,7 +821,7 @@ namespace JinEngine
luaopen_Page(L);
luaopen_JSL(L);
- // Load whole lib.
+ // load whole lib
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
index f3c2517..29e3ff8 100644
--- a/src/lua/modules/graphics/je_lua_page.cpp
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -14,7 +14,7 @@ namespace JinEngine
namespace Lua
{
- typedef Shared<Font>& FontRef;
+ typedef Shared<Font>& SharedFont;
Page* getPage(lua_State* L)
{
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
index e2e1413..9913bc3 100644
--- a/src/lua/modules/graphics/je_lua_shader.cpp
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -24,36 +24,36 @@ namespace JinEngine
*/
LUA_IMPLEMENT int l_sendNumber(lua_State* L)
{
- ShaderRef ref = checkShader(L);
+ ShaderRef shared = checkShader(L);
const char* variable = luax_checkstring(L, 2);
float number = luax_checknumber(L, 3);
- ref->sendFloat(variable, number);
+ shared->sendFloat(variable, number);
return 0;
}
LUA_IMPLEMENT int l_sendTexture(lua_State* L)
{
- ShaderRef ref = checkShader(L);
+ ShaderRef shared = checkShader(L);
const char* variable = luax_checkstring(L, 2);
Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE);
Shared<Texture>& tex = proxy->getShared<Texture>();
- ref->sendTexture(variable, tex.getObject());
+ shared->sendTexture(variable, tex.getObject());
return 0;
}
LUA_IMPLEMENT int l_sendCanvas(lua_State* L)
{
- ShaderRef ref = checkShader(L);
+ ShaderRef shared = checkShader(L);
const char* variable = luax_checkstring(L, 2);
Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS);
Shared<Canvas>& canvas = proxy->getShared<Canvas>();
- ref->sendCanvas(variable, canvas.getObject());
+ shared->sendCanvas(variable, canvas.getObject());
return 0;
}
LUA_IMPLEMENT int l_sendVec2(lua_State* L)
{
- ShaderRef ref = checkShader(L);
+ ShaderRef shared = checkShader(L);
const char* variable = luax_checkstring(L, 2);
if (!luax_istable(L, 3))
{
@@ -62,13 +62,13 @@ namespace JinEngine
}
float x = luax_rawgetnumber(L, 3, 1);
float y = luax_rawgetnumber(L, 3, 2);
- ref->sendVec2(variable, x, y);
+ shared->sendVec2(variable, x, y);
return 0;
}
LUA_IMPLEMENT int l_sendVec3(lua_State* L)
{
- ShaderRef ref = checkShader(L);
+ ShaderRef shared = checkShader(L);
const char* variable = luax_checkstring(L, 2);
if (!luax_istable(L, 3))
{
@@ -78,13 +78,13 @@ namespace JinEngine
float x = luax_rawgetnumber(L, 3, 1);
float y = luax_rawgetnumber(L, 3, 2);
float z = luax_rawgetnumber(L, 3, 3);
- ref->sendVec3(variable, x, y, z);
+ shared->sendVec3(variable, x, y, z);
return 0;
}
LUA_IMPLEMENT int l_sendVec4(lua_State* L)
{
- ShaderRef ref = checkShader(L);
+ ShaderRef shared = checkShader(L);
const char* variable = luax_checkstring(L, 2);
if (!luax_istable(L, 3))
{
@@ -95,7 +95,7 @@ namespace JinEngine
float y = luax_rawgetnumber(L, 3, 2);
float z = luax_rawgetnumber(L, 3, 3);
float w = luax_rawgetnumber(L, 3, 4);
- ref->sendVec4(variable, x, y, z, w);
+ shared->sendVec4(variable, x, y, z, w);
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
index a643dae..5236438 100644
--- a/src/lua/modules/graphics/je_lua_texture.cpp
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -10,9 +10,9 @@ namespace JinEngine
namespace Lua
{
- typedef Shared<Texture>& TextureRef;
+ typedef Shared<Texture>& SharedTexture;
- LUA_IMPLEMENT inline TextureRef checkTexture(lua_State* L)
+ LUA_IMPLEMENT inline SharedTexture checkTexture(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
return proxy->getShared<Texture>();
@@ -20,23 +20,23 @@ namespace JinEngine
LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
return 1;
}
LUA_IMPLEMENT int l_getHeight(lua_State *L)
{
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getHeight());
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getHeight());
return 1;
}
LUA_IMPLEMENT int l_getSize(lua_State* L)
{
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
return 2;
}
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index 58011a7..dbaa997 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -39,7 +39,7 @@ namespace JinEngine
Text* text = p2->getObject<Text>();
page = tf->typeset(*text, lineheight, spacing);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
{
/* retain related ttf */
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
index 4c56ae1..3e6050b 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -45,7 +45,7 @@ namespace JinEngine
Text* text = p2->getObject<Text>();
page = ttf->typeset(*text, lineheight, spacing);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
{
/* retain related ttf */
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
index d076ab8..e46fca6 100644
--- a/src/lua/modules/graphics/je_lua_ttf_data.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -17,7 +17,7 @@ namespace JinEngine
int fontsize = luax_checkinteger(L, 2);
Shared<TTFData>& refFontData = p->getShared<TTFData>();
TTFData* fontData = refFontData.getObject();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTF, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TTF);
TTF* font = fontData->createTTF(fontsize);
Shared<TTF>* refTTF = new Shared<TTF>(font, JIN_GRAPHICS_TTF);
{