aboutsummaryrefslogtreecommitdiff
path: root/src/lua/graphics/luaopen_graphics.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-14 14:56:47 +0800
committerchai <chaifix@163.com>2018-08-14 14:56:47 +0800
commit5c9af043503f92852a1a765b6ecfbc1aea24d2e9 (patch)
treeeb371092c4137a672e7bfc13dc56ee777623ebfe /src/lua/graphics/luaopen_graphics.cpp
parent5162f84be0a4deb447c6ba1226722b049335d525 (diff)
*update
Diffstat (limited to 'src/lua/graphics/luaopen_graphics.cpp')
-rw-r--r--src/lua/graphics/luaopen_graphics.cpp64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp
index da91c51..31c5719 100644
--- a/src/lua/graphics/luaopen_graphics.cpp
+++ b/src/lua/graphics/luaopen_graphics.cpp
@@ -1,14 +1,23 @@
-#include "libjin/jin.h"
#include "lua/luax.h"
+#include "libjin/jin.h"
#include "lua/luaopen_types.h"
#include "lua/embed/graphics.lua.h"
+#include "Canvas.h"
+#include "Color.h"
+#include "Font.h"
+#include "Image.h"
+#include "JSL.h"
+#include "graphics.h"
namespace jin
{
namespace lua
{
- using namespace jin::graphics;
- using namespace jin::filesystem;
+
+ using namespace lua::graphics;
+ using jin::graphics::Window;
+ using jin::filesystem::Filesystem;
+ using jin::filesystem::Buffer;
/**
* jin.graphics context, storge some module
@@ -17,8 +26,8 @@ namespace lua
static struct
{
color curRenderColor;
- Font* curFont = 0;
- Font* defaultFont = 0;
+ Font* curFont = nullptr;
+ Font* defaultFont = nullptr;
} context;
/**
@@ -78,7 +87,7 @@ namespace lua
fs->read(f, &b);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_IMAGE, sizeof(Proxy));
- Texture* img = Texture::createTexture(b.data, b.size);
+ Image* img = Image::createImage(b.data, b.size);
proxy->bind(img, JIN_GRAPHICS_IMAGE);
return 1;
}
@@ -148,7 +157,7 @@ namespace lua
if (luax_istype(L, 1, JIN_GRAPHICS_IMAGE))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Texture* tex = (Texture*)proxy->object;
+ Image* tex = (Image*)proxy->object;
tex->draw(x, y, sx, sy, r);
}
else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
@@ -251,9 +260,9 @@ namespace lua
static RENDER_MODE strtomode(const char* str)
{
std::string s = std::string(str);
- if (s == "fill") return FILL;
- else if (s == "line") return LINE;
- else return NONE;
+ if (s == "fill") return RENDER_MODE::FILL;
+ else if (s == "line") return RENDER_MODE::LINE;
+ else return RENDER_MODE::NONE;
}
/**
@@ -264,7 +273,7 @@ namespace lua
{
int x = luax_checknumber(L, 1);
int y = luax_checknumber(L, 2);
- point(x, y);
+ jin::graphics::point(x, y);
return 0;
}
@@ -275,7 +284,7 @@ namespace lua
int y1 = luax_checknumber(L, 2);
int x2 = luax_checknumber(L, 3);
int y2 = luax_checknumber(L, 4);
- line(x1, y1, x2, y2);
+ jin::graphics::line(x1, y1, x2, y2);
return 0;
}
@@ -284,7 +293,7 @@ namespace lua
{
const char* modestr = luax_checkstring(L, 1);
RENDER_MODE mode = strtomode(modestr);
- if (mode != NONE)
+ if (mode != RENDER_MODE::NONE)
{
int x = luax_checknumber(L, 2);
int y = luax_checknumber(L, 3);
@@ -305,7 +314,7 @@ namespace lua
{
const char* modestr = luax_checkstring(L, 1);
RENDER_MODE mode = strtomode(modestr);
- if (mode != NONE)
+ if (mode != RENDER_MODE::NONE)
{
int x = luax_checknumber(L, 2);
int y = luax_checknumber(L, 3);
@@ -325,7 +334,7 @@ namespace lua
{
const char* modestr = luax_checkstring(L, 1);
RENDER_MODE mode = strtomode(modestr);
- if (mode != NONE)
+ if (mode != RENDER_MODE::NONE)
{
int x = luax_checknumber(L, 2);
int y = luax_checknumber(L, 3);
@@ -356,7 +365,7 @@ namespace lua
const char* modestr = luax_checkstring(L, 1);
int n = luax_checknumber(L, 2);
RENDER_MODE mode = strtomode(modestr);
- if (mode != NONE)
+ if (mode != RENDER_MODE::NONE)
{
if (!luax_istable(L, 3))
{
@@ -389,18 +398,21 @@ namespace lua
static int l_newFont(lua_State* L)
{
- Font* font = (Font*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Font));
- const char* path = luax_checkstring(L, 1);
- Filesystem* fs = Filesystem::get();
- Buffer b = {};
- if (!fs->exists(path))
+ Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Proxy));
+ Font* font = new Font();
{
- printf("Error: no such font %s\n", path);
- exit(1);
+ const char* path = luax_checkstring(L, 1);
+ Filesystem* fs = Filesystem::get();
+ Buffer b = {};
+ if (!fs->exists(path))
+ {
+ printf("Error: no such font %s\n", path);
+ exit(1);
+ }
+ fs->read(path, &b);
+ font->loadb((const unsigned char*)b.data);
}
- fs->read(path, &b);
- font->loadb((const unsigned char*)b.data);
-
+ proxy->bind(font, JIN_GRAPHICS_FONT);
return 1;
}