aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/je_lua_graphics.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp256
1 files changed, 128 insertions, 128 deletions
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 2eeb1d6..fba77d7 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -41,7 +41,7 @@ namespace JinEngine
static struct
{
Color curRenderColor;
- Color curClearColor;
+ Color curClearColor;
Font* defaultFont = nullptr;
bool initialized = false;
} context;
@@ -283,25 +283,25 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT int l_setClearColor(lua_State* L)
- {
- if (luax_gettop(L) == 0)
- {
- glClearColor(0, 0, 0, 1);
- return 0;
- }
+ LUA_IMPLEMENT int l_setClearColor(lua_State* L)
+ {
+ if (luax_gettop(L) == 0)
+ {
+ glClearColor(0, 0, 0, 1);
+ return 0;
+ }
- context.curClearColor.r = luax_checknumber(L, 1);
- context.curClearColor.g = luax_checknumber(L, 2);
- context.curClearColor.b = luax_checknumber(L, 3);
- context.curClearColor.a = luax_checknumber(L, 4);
+ context.curClearColor.r = luax_checknumber(L, 1);
+ context.curClearColor.g = luax_checknumber(L, 2);
+ context.curClearColor.b = luax_checknumber(L, 3);
+ context.curClearColor.a = luax_checknumber(L, 4);
gl.setClearColor(context.curClearColor.r,
- context.curClearColor.g,
- context.curClearColor.b,
- context.curClearColor.a);
- return 0;
- }
+ context.curClearColor.g,
+ context.curClearColor.b,
+ context.curClearColor.a);
+ return 0;
+ }
LUA_IMPLEMENT int l_present(lua_State* L)
{
@@ -309,80 +309,80 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT void l_draw_texture(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Texture))
- return;
- int x = luax_optnumber(L, 2, 0);
- int y = luax_optnumber(L, 3, 0);
- float sx = luax_optnumber(L, 4, 1);
- float sy = luax_optnumber(L, 5, 1);
- float r = luax_optnumber(L, 6, 0);
+ LUA_IMPLEMENT void l_draw_texture(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Texture))
+ return;
+ int x = luax_optnumber(L, 2, 0);
+ int y = luax_optnumber(L, 3, 0);
+ float sx = luax_optnumber(L, 4, 1);
+ float sy = luax_optnumber(L, 5, 1);
+ float r = luax_optnumber(L, 6, 0);
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
- LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
- Texture* tex = luaObj->getObject<Texture>();
- tex->render(x, y, sx, sy, r, ox, oy);
- }
-
- LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Canvas))
- return;
- int x = luax_optnumber(L, 2, 0);
- int y = luax_optnumber(L, 3, 0);
- float sx = luax_optnumber(L, 4, 1);
- float sy = luax_optnumber(L, 5, 1);
- float r = luax_optnumber(L, 6, 0);
+ LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
+ Texture* tex = luaObj->getObject<Texture>();
+ tex->render(x, y, sx, sy, r, ox, oy);
+ }
+
+ LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Canvas))
+ return;
+ int x = luax_optnumber(L, 2, 0);
+ int y = luax_optnumber(L, 3, 0);
+ float sx = luax_optnumber(L, 4, 1);
+ float sy = luax_optnumber(L, 5, 1);
+ float r = luax_optnumber(L, 6, 0);
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
- LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
- Canvas* canvas = luaObj->getObject<Canvas>();
+ LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
+ Canvas* canvas = luaObj->getObject<Canvas>();
canvas->render(x, y, sx, sy, r, ox, oy);
- }
-
- /* jin.graphics.draw(text, font, x, y) */
- LUA_IMPLEMENT void l_draw_text(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Text))
- return;
- LuaObject* p = (LuaObject*)luax_toudata(L, 1);
- Text* text = p->getObject<Text>();
- int x = luax_optnumber(L, 3, 0);
- int y = luax_optnumber(L, 4, 0);
- int spacing = luax_optnumber(L, 6, 0);
+ }
+
+ /* jin.graphics.draw(text, font, x, y) */
+ LUA_IMPLEMENT void l_draw_text(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Text))
+ return;
+ LuaObject* p = (LuaObject*)luax_toudata(L, 1);
+ Text* text = p->getObject<Text>();
+ int x = luax_optnumber(L, 3, 0);
+ int y = luax_optnumber(L, 4, 0);
+ int spacing = luax_optnumber(L, 6, 0);
Font* font = nullptr;
LuaObject* p2 = (LuaObject*)luax_toudata(L, 2);
- if (luax_istype(L, 2, Jin_Lua_TextureFont))
- {
- TextureFont* tf = p2->getObject<TextureFont>();
+ if (luax_istype(L, 2, Jin_Lua_TextureFont))
+ {
+ TextureFont* tf = p2->getObject<TextureFont>();
font = tf;
- }
- else if (luax_istype(L, 2, Jin_Lua_TTF))
- {
- TTF* ttf = p2->getObject<TTF>();
+ }
+ else if (luax_istype(L, 2, Jin_Lua_TTF))
+ {
+ TTF* ttf = p2->getObject<TTF>();
font = ttf;
- }
+ }
else
{
font = context.defaultFont;
}
int lineheight = luax_optnumber(L, 5, font->getFontSize());
font->render(*text, x, y, lineheight, spacing);
- }
-
- /* jin.graphics.draw(page, x, y) */
- LUA_IMPLEMENT void l_draw_page(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Page))
- return;
- int x = luax_optnumber(L, 2, 0);
- int y = luax_optnumber(L, 3, 0);
- LuaObject* p = (LuaObject*)luax_toudata(L, 1);
- Page* page = p->getObject<Page>();
- Font* font = page->font;
- font->render(page, x, y);
- }
+ }
+
+ /* jin.graphics.draw(page, x, y) */
+ LUA_IMPLEMENT void l_draw_page(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Page))
+ return;
+ int x = luax_optnumber(L, 2, 0);
+ int y = luax_optnumber(L, 3, 0);
+ LuaObject* p = (LuaObject*)luax_toudata(L, 1);
+ Page* page = p->getObject<Page>();
+ Font* font = page->font;
+ font->render(page, x, y);
+ }
LUA_IMPLEMENT void l_draw_sprite(lua_State* L)
{
@@ -513,7 +513,7 @@ namespace JinEngine
return 0;
}
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
- Canvas* canvas = luaObj->getObject<Canvas>();
+ Canvas* canvas = luaObj->getObject<Canvas>();
gl.bindCanvas(canvas);
return 0;
}
@@ -688,28 +688,28 @@ namespace JinEngine
return 1;
}
- /* newText(str[, encode]) */
- LUA_IMPLEMENT int l_newText(lua_State* L)
- {
- Encode encode = Encode::UTF8;
- if (luax_gettop(L) == 2)
- {
- const char* e = luax_checkstring(L, 2);
- if (strcmp(e, "UTF8") == 0) encode = Encode::UTF8;
- //else if (strcmp(e, "UTF16") == 0) encode = Encode::UTF16;
- else if (strcmp(e, "ASCII") == 0) encode = Encode::ASCII;
- else
- {
- luax_error(L, "wrong text encode %s", e);
- return 0;
- }
- }
- unsigned length;
- const char* data = luax_checklstring(L, 1, &length);
- Text* text = new Text(encode, data, length);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Text, new Shared(text));
- return 1;
- }
+ /* newText(str[, encode]) */
+ LUA_IMPLEMENT int l_newText(lua_State* L)
+ {
+ Encode encode = Encode::UTF8;
+ if (luax_gettop(L) == 2)
+ {
+ const char* e = luax_checkstring(L, 2);
+ if (strcmp(e, "UTF8") == 0) encode = Encode::UTF8;
+ //else if (strcmp(e, "UTF16") == 0) encode = Encode::UTF16;
+ else if (strcmp(e, "ASCII") == 0) encode = Encode::ASCII;
+ else
+ {
+ luax_error(L, "wrong text encode %s", e);
+ return 0;
+ }
+ }
+ unsigned length;
+ const char* data = luax_checklstring(L, 1, &length);
+ Text* text = new Text(encode, data, length);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Text, new Shared(text));
+ return 1;
+ }
// newSprite(Texture tex, Quad quad, Origin origin)
// newSprite(Texture tex, Quad quad, Number ox, Number oy)
@@ -843,11 +843,11 @@ namespace JinEngine
return 1;
}
- /* newTextureFont(bitmap, text, color | cellw, cellh) */
+ /* newTextureFont(bitmap, text, color | cellw, cellh) */
LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
- Bitmap* bitmap = p->getObject<Bitmap>();
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ Bitmap* bitmap = p->getObject<Bitmap>();
Text* text;
if (luax_istype(L, 2, Jin_Lua_Text))
{
@@ -865,21 +865,21 @@ namespace JinEngine
luax_typerror(L, 2, "Text or string");
return 1;
}
- float cellh = luax_checknumber(L, 4);
- TextureFont* textureFont = nullptr;
- if (luax_istable(L, 3))
- {
- unsigned int r = luax_rawgetnumber(L, 3, 1);
- unsigned int g = luax_rawgetnumber(L, 3, 2);
- unsigned int b = luax_rawgetnumber(L, 3, 3);
- unsigned int a = luax_rawgetnumber(L, 3, 4);
- textureFont = new TextureFont(bitmap, *text, Color(r, g, b, a), cellh);
- }
- else if (luax_isnumber(L, 3))
- {
- float cellw = luax_checknumber(L, 3);
- textureFont = new TextureFont(bitmap, *text, cellw, cellh);
- }
+ float cellh = luax_checknumber(L, 4);
+ TextureFont* textureFont = nullptr;
+ if (luax_istable(L, 3))
+ {
+ unsigned int r = luax_rawgetnumber(L, 3, 1);
+ unsigned int g = luax_rawgetnumber(L, 3, 2);
+ unsigned int b = luax_rawgetnumber(L, 3, 3);
+ unsigned int a = luax_rawgetnumber(L, 3, 4);
+ textureFont = new TextureFont(bitmap, *text, Color(r, g, b, a), cellh);
+ }
+ else if (luax_isnumber(L, 3))
+ {
+ float cellw = luax_checknumber(L, 3);
+ textureFont = new TextureFont(bitmap, *text, cellw, cellh);
+ }
else
{
luax_error(L, "bad arguments #3 to 'newTextureFont', need to be table or number");
@@ -890,9 +890,9 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_TextureFont, new Shared(textureFont));
- return 1;
- }
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_TextureFont, new Shared(textureFont));
+ return 1;
+ }
LUA_IMPLEMENT int l_newParticleSystem(lua_State* L)
{
@@ -901,8 +901,8 @@ namespace JinEngine
}
/* setFont(font) */
- LUA_IMPLEMENT int l_setFont(lua_State* L)
- {
+ LUA_IMPLEMENT int l_setFont(lua_State* L)
+ {
if (luax_istype(L, 1, Jin_Lua_TTF))
{
LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
@@ -915,8 +915,8 @@ namespace JinEngine
TextureFont* tf = p->getObject<TextureFont>();
gl.setFont(tf);
}
- return 0;
- }
+ return 0;
+ }
LUA_IMPLEMENT int l_unsetFont(lua_State* L)
{
@@ -971,9 +971,9 @@ namespace JinEngine
luaopen_Texture(L);
luaopen_Canvas(L);
luaopen_TTFData(L);
- luaopen_TTF(L);
- luaopen_Text(L);
- luaopen_TextureFont(L);
+ luaopen_TTF(L);
+ luaopen_Text(L);
+ luaopen_TextureFont(L);
luaopen_Page(L);
luaopen_Shader(L);
luaopen_Sprite(L);