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.cpp119
1 files changed, 52 insertions, 67 deletions
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index f98d640..df68957 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -4,7 +4,7 @@
#include "libjin/jin.h"
#include "lua/modules/luax.h"
#include "lua/modules/types.h"
-#include "lua/common/common.h"
+#include "lua/common/je_lua_common.h"
using namespace std;
using namespace JinEngine;
@@ -27,7 +27,7 @@ namespace JinEngine
Font* defaultFont = nullptr;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
Window* wnd = Window::get();
Window::Setting setting;
@@ -45,21 +45,6 @@ namespace JinEngine
{
/* load default font */
Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
- const Color* pixels = bitmap->getPixels();
- ofstream f = ofstream();
- f.open("font.pixels", ios_base::app);
- for (int y = 0; y < bitmap->getHeight(); ++y)
- {
- for (int x = 0; x < bitmap->getWidth(); ++x)
- {
- Color c = pixels[x + y * bitmap->getWidth()];
- f << (int)c.r << ",";
- f << (int)c.g << ",";
- f << (int)c.b << ",";
- f << (int)c.a << ",";
- }
- }
-
TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
context.defaultFont = tf;
delete bitmap;
@@ -70,7 +55,7 @@ namespace JinEngine
return 1;
}
- static int l_setTitle(lua_State* L)
+ LUA_IMPLEMENT int l_setTitle(lua_State* L)
{
Window* wnd = Window::get();
const char* title = luax_checkstring(L, 1);
@@ -78,14 +63,14 @@ namespace JinEngine
return 0;
}
- static int l_destroy(lua_State* L)
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
{
Window* wnd = Window::get();
wnd->quit();
return 0;
}
- static int l_getSize(lua_State* L)
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
@@ -93,21 +78,21 @@ namespace JinEngine
return 2;
}
- static int l_getWidth(lua_State* L)
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
return 1;
}
- static int l_getHeight(lua_State* L)
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getH());
return 1;
}
- static int l_newBitmap(lua_State* L)
+ LUA_IMPLEMENT int l_newBitmap(lua_State* L)
{
Bitmap* bitmap = nullptr;
if (luax_gettop(L) == 2)
@@ -162,7 +147,7 @@ namespace JinEngine
}
/* jin.graphics.newTexture(bitmap) */
- static int l_newTexture(lua_State* L)
+ LUA_IMPLEMENT int l_newTexture(lua_State* L)
{
Texture* texture = nullptr;
if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP))
@@ -182,7 +167,7 @@ namespace JinEngine
return 1;
}
- static int l_newShader(lua_State* L)
+ LUA_IMPLEMENT int l_newShader(lua_State* L)
{
const char* program = luax_checkstring(L, 1);
Shader* jsl = Shader::createShader(program);
@@ -197,7 +182,7 @@ namespace JinEngine
return 1;
}
- static int l_newShaderf(lua_State* L)
+ LUA_IMPLEMENT int l_newShaderf(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
@@ -221,7 +206,7 @@ namespace JinEngine
return 1;
}
- static int l_newCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_newCanvas(lua_State* L)
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
@@ -231,13 +216,13 @@ namespace JinEngine
return 1;
}
- static int l_clear(lua_State* L)
+ LUA_IMPLEMENT int l_clear(lua_State* L)
{
glClear(GL_COLOR_BUFFER_BIT);
return 0;
}
- static int l_setClearColor(lua_State* L)
+ LUA_IMPLEMENT int l_setClearColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -257,13 +242,13 @@ namespace JinEngine
return 0;
}
- static int l_present(lua_State* L)
+ LUA_IMPLEMENT int l_present(lua_State* L)
{
Window::get()->swapBuffers();
return 0;
}
- static void l_draw_texture(lua_State* L)
+ LUA_IMPLEMENT void l_draw_texture(lua_State* L)
{
if (!luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
return;
@@ -279,7 +264,7 @@ namespace JinEngine
tex->render(x, y, sx, sy, r, ox, oy);
}
- static void l_draw_canvas(lua_State* L)
+ LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
{
if (!luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
return;
@@ -296,7 +281,7 @@ namespace JinEngine
}
/* jin.graphics.draw(text, font, x, y) */
- static void l_draw_text(lua_State* L)
+ LUA_IMPLEMENT void l_draw_text(lua_State* L)
{
if (!luax_istype(L, 1, JIN_GRAPHICS_TEXT))
return;
@@ -326,7 +311,7 @@ namespace JinEngine
}
/* jin.graphics.draw(page, x, y) */
- static void l_draw_page(lua_State* L)
+ LUA_IMPLEMENT void l_draw_page(lua_State* L)
{
if (!luax_istype(L, 1, JIN_GRAPHICS_PAGE))
return;
@@ -338,7 +323,7 @@ namespace JinEngine
font->render(page, x, y);
}
- static int l_draw(lua_State* L)
+ LUA_IMPLEMENT int l_draw(lua_State* L)
{
if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
l_draw_texture(L);
@@ -357,7 +342,7 @@ namespace JinEngine
}
// draw(tex, quad, x, y, sx, sy, r, ax, ay)
- static int l_drawq(lua_State* L)
+ LUA_IMPLEMENT int l_drawq(lua_State* L)
{
if (!luax_istable(L, 2))
{
@@ -398,7 +383,7 @@ namespace JinEngine
/* print(string, x, y, lineheight, spacing) */
/* need set font */
- static int l_print(lua_State* L)
+ LUA_IMPLEMENT int l_print(lua_State* L)
{
Font* font = context.curFont;
if (font == nullptr)
@@ -414,7 +399,7 @@ namespace JinEngine
return 0;
}
- static int l_setColor(lua_State* L)
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -436,7 +421,7 @@ namespace JinEngine
return 0;
}
- static int l_getColor(lua_State * L)
+ LUA_IMPLEMENT int l_getColor(lua_State * L)
{
luax_pushnumber(L, context.curRenderColor.r);
luax_pushnumber(L, context.curRenderColor.g);
@@ -445,7 +430,7 @@ namespace JinEngine
return 4;
}
- static int l_bindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_bindCanvas(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -459,13 +444,13 @@ namespace JinEngine
return 0;
}
- static int l_unbindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_unbindCanvas(lua_State* L)
{
Canvas::unbind();
return 0;
}
- static int l_useShader(lua_State* L)
+ LUA_IMPLEMENT int l_useShader(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -485,13 +470,13 @@ namespace JinEngine
return 0;
}
- static int l_setBlend(lua_State* L)
+ LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
return 0;
}
- static RenderMode strtomode(const char* str)
+ LUA_IMPLEMENT RenderMode strtomode(const char* str)
{
std::string s = std::string(str);
if (s == "fill") return RenderMode::FILL;
@@ -499,7 +484,7 @@ namespace JinEngine
else return RenderMode::NONE;
}
- static int l_point(lua_State* L)
+ LUA_IMPLEMENT int l_point(lua_State* L)
{
int x = luax_checknumber(L, 1);
int y = luax_checknumber(L, 2);
@@ -508,7 +493,7 @@ namespace JinEngine
return 0;
}
- static int l_line(lua_State* L)
+ LUA_IMPLEMENT int l_line(lua_State* L)
{
int x1 = luax_checknumber(L, 1);
int y1 = luax_checknumber(L, 2);
@@ -519,7 +504,7 @@ namespace JinEngine
return 0;
}
- static int l_rect(lua_State* L)
+ LUA_IMPLEMENT int l_rect(lua_State* L)
{
const char* modestr = luax_checkstring(L, 1);
RenderMode mode = strtomode(modestr);
@@ -540,7 +525,7 @@ namespace JinEngine
return 0;
}
- static int l_circle(lua_State* L)
+ LUA_IMPLEMENT int l_circle(lua_State* L)
{
const char* modestr = luax_checkstring(L, 1);
RenderMode mode = strtomode(modestr);
@@ -560,7 +545,7 @@ namespace JinEngine
return 0;
}
- static int l_triangle(lua_State* L)
+ LUA_IMPLEMENT int l_triangle(lua_State* L)
{
const char* modestr = luax_checkstring(L, 1);
RenderMode mode = strtomode(modestr);
@@ -586,7 +571,7 @@ namespace JinEngine
return 0;
}
- static int l_polygon(lua_State* L)
+ LUA_IMPLEMENT int l_polygon(lua_State* L)
{
const char* modestr = luax_checkstring(L, 1);
int n = luax_checknumber(L, 2);
@@ -601,7 +586,7 @@ namespace JinEngine
int tn = luax_tableidxlen(L, 3);
if (tn != n * 2)
{
- static char* emsg = \
+ LUA_IMPLEMENT char* emsg = \
"number of polygon vertices doesn't match " \
"provided n, expect %d numbers but get %d";
luax_error(L, emsg, n * 2, tn);
@@ -621,7 +606,7 @@ namespace JinEngine
return 0;
}
- static int l_newTTFData(lua_State* L)
+ LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTFDATA, sizeof(Proxy));
TTFData* fd = nullptr;
@@ -643,7 +628,7 @@ namespace JinEngine
}
/* newText(str[, encode]) */
- static int l_newText(lua_State* L)
+ LUA_IMPLEMENT int l_newText(lua_State* L)
{
Encode encode = Encode::UTF8;
if (luax_gettop(L) == 2)
@@ -667,7 +652,7 @@ namespace JinEngine
}
/* newTextureFont(bitmap, text, color | cellw, cellh) */
- static int l_newTextureFont(lua_State* L)
+ LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
{
Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
Bitmap* bitmap = p->getObject<Bitmap>();
@@ -719,7 +704,7 @@ namespace JinEngine
}
/* setFont(font) */
- static int l_setFont(lua_State* L)
+ LUA_IMPLEMENT int l_setFont(lua_State* L)
{
if (luax_istype(L, 1, JIN_GRAPHICS_TTF))
{
@@ -736,13 +721,13 @@ namespace JinEngine
return 0;
}
- static int l_unsetFont(lua_State* L)
+ LUA_IMPLEMENT int l_unsetFont(lua_State* L)
{
context.curFont = context.defaultFont;
return 0;
}
- static const luaL_Reg f[] = {
+ LUA_IMPLEMENT const luaL_Reg f[] = {
/* window */
{ "init", l_init },
{ "setTitle", l_setTitle },
@@ -786,17 +771,17 @@ namespace JinEngine
{ 0, 0 }
};
- extern int luaopen_Texture(lua_State* L);
- extern int luaopen_Text(lua_State* L);
- extern int luaopen_TTF(lua_State* L);
- extern int luaopen_TextureFont(lua_State* L);
- extern int luaopen_TTFData(lua_State* L);
- extern int luaopen_Page(lua_State* L);
- extern int luaopen_Canvas(lua_State* L);
- extern int luaopen_JSL(lua_State* L);
- extern int luaopen_Bitmap(lua_State* L);
+ LUA_PORT int luaopen_Texture(lua_State* L);
+ LUA_PORT int luaopen_Text(lua_State* L);
+ LUA_PORT int luaopen_TTF(lua_State* L);
+ LUA_PORT int luaopen_TextureFont(lua_State* L);
+ LUA_PORT int luaopen_TTFData(lua_State* L);
+ LUA_PORT int luaopen_Page(lua_State* L);
+ LUA_PORT int luaopen_Canvas(lua_State* L);
+ LUA_PORT int luaopen_JSL(lua_State* L);
+ LUA_PORT int luaopen_Bitmap(lua_State* L);
- int luaopen_graphics(lua_State* L)
+ LUA_EXPORT int luaopen_graphics(lua_State* L)
{
// register types
luaopen_Bitmap(L);