aboutsummaryrefslogtreecommitdiff
path: root/src/lua/graphics/luaopen_graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/graphics/luaopen_graphics.cpp')
-rw-r--r--src/lua/graphics/luaopen_graphics.cpp58
1 files changed, 4 insertions, 54 deletions
diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp
index b86b523..42e8f3c 100644
--- a/src/lua/graphics/luaopen_graphics.cpp
+++ b/src/lua/graphics/luaopen_graphics.cpp
@@ -13,10 +13,6 @@ namespace lua
typedef Texture Image;
- /**
- * jin.graphics context, storge some module
- * shared variables.
- */
static struct
{
color curRenderColor;
@@ -24,10 +20,6 @@ namespace lua
Font* defaultFont = nullptr;
} context;
- /**
- * Init video system.
- * jin.graphics.init(width, height, title)
- */
static int l_init(lua_State* L)
{
Window* wnd = Window::get();
@@ -54,9 +46,6 @@ namespace lua
return 0;
}
- /**
- * Get windows size.
- */
static int l_getSize(lua_State* L)
{
Window* wnd = Window::get();
@@ -65,9 +54,6 @@ namespace lua
return 2;
}
- /**
- * Create a image userdata and set metatable for it.
- */
static int l_newImage(lua_State* L)
{
Filesystem* fs = Filesystem::get();
@@ -82,35 +68,26 @@ namespace lua
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_IMAGE, sizeof(Proxy));
Image* img = Image::createTexture(b.data, b.size);
- proxy->bind(new Ref<Image>(img), JIN_GRAPHICS_IMAGE);
+ proxy->bind(new Ref<Image>(img, JIN_GRAPHICS_IMAGE));
return 1;
}
- /**
- * Create a new JSL program.
- * graphics.Shader(program)
- */
static int l_newShader(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
const char* program = luax_checkstring(L, 1);
JSLProgram* jsl = JSLProgram::createJSLProgram(program);
- proxy->bind(new Ref<JSLProgram>(jsl), JIN_GRAPHICS_SHADER);
+ proxy->bind(new Ref<JSLProgram>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
- /**
- * Create a new Canvas, don't use it in loop, very slow.
- * jin.graphics.newCanvas(w, h)
- */
static int l_newCanvas(lua_State* L)
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
Canvas* cvs = Canvas::createCanvas(w, h);
- Ref<Canvas>* ref = new Ref<Canvas>(cvs);
- proxy->bind(ref, JIN_GRAPHICS_CANVAS);
+ proxy->bind(new Ref<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
return 1;
}
@@ -132,16 +109,12 @@ namespace lua
return 0;
}
- /**
- * Swap render buffers, present current buffer to front.
- */
static int l_present(lua_State* L)
{
Window::get()->swapBuffers();
return 0;
}
- // jin.graphics.draw(x, y, scalex, scaley, r)
static int l_draw(lua_State* L)
{
int x = luax_optnumber(L, 2, 0);
@@ -171,8 +144,6 @@ namespace lua
static int l_setColor(lua_State* L)
{
- // jin.graphics.color() to set back to default
- // render color
if (luax_gettop(L) == 0)
{
glColor4f(1, 1, 1, 1);
@@ -260,10 +231,6 @@ namespace lua
else return RENDER_MODE::NONE;
}
- /**
- * draw pixel to screen
- * jin.graphics.pixel(x, y)
- */
static int l_drawpoint(lua_State* L)
{
int x = luax_checknumber(L, 1);
@@ -351,10 +318,6 @@ namespace lua
return 0;
}
- /**
- * draw polygon.
- * jin.graphics.polygon(mode, n, {{}, {}, {}...})
- */
static int l_drawPolygon(lua_State* L)
{
const char* modestr = luax_checkstring(L, 1);
@@ -407,13 +370,10 @@ namespace lua
fs->read(path, &b);
font->loadb((const unsigned char*)b.data);
}
- proxy->bind(new Ref<Font>(font), JIN_GRAPHICS_FONT);
+ proxy->bind(new Ref<Font>(font, JIN_GRAPHICS_FONT));
return 1;
}
- /**
- * study font, 0 args for study default font.
- */
static int l_study(lua_State* L)
{
int n = luax_gettop(L);
@@ -434,10 +394,6 @@ namespace lua
return 0;
}
- /**
- * draw text with current font(after study). befor write, must
- * study a font.
- */
static int l_write(lua_State* L)
{
if (context.curFont == 0)
@@ -456,9 +412,6 @@ namespace lua
return 0;
}
- /**
- * get text bound box
- */
static int l_box(lua_State* L)
{
const char* text = luax_checkstring(L, 1);
@@ -502,11 +455,8 @@ namespace lua
};
extern int luaopen_Image(lua_State* L);
-
extern int luaopen_Font(lua_State* L);
-
extern int luaopen_Canvas(lua_State* L);
-
extern int luaopen_JSL(lua_State* L);
int luaopen_graphics(lua_State* L)