diff options
author | chai <chaifix@163.com> | 2018-10-15 13:51:56 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-15 13:51:56 +0800 |
commit | bd3c1f268d959d351631b51d32d9912370144ddd (patch) | |
tree | a724836aa121fd4406a45915e6ece7cec7e3ba05 /src/lua/modules/graphics/graphics.cpp | |
parent | 252e074c41a73312be3e235b07be266a9aee59fb (diff) |
*修改打印文字接口
Diffstat (limited to 'src/lua/modules/graphics/graphics.cpp')
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 645ae4a..700c8a5 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -164,6 +164,30 @@ namespace lua return 1; } + static int l_newShaderf(lua_State* L) + { + const char* path = luax_checkstring(L, 1); + Filesystem* fs = Filesystem::get(); + if (!fs->exists(path)) + { + error(L, "No such shader file %s\n", path); + luax_pushnil(L); + return 1; + } + Buffer b; + fs->read(path, &b); + Shader* jsl = Shader::createShader((char*)b.data); + if (jsl == nullptr) + { + error(L, "Failed to compile shader"); + luax_pushnil(L); + return 1; + } + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy)); + proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER)); + return 1; + } + static int l_newCanvas(lua_State* L) { int w = luax_checknumber(L, 1); @@ -277,24 +301,6 @@ namespace lua font->print(page, x, y); } - /* print(string, x, y, lineheight, spacing) */ - /* need set font */ - static int l_print(lua_State* L) - { - Font* font = context.curFont; - if (font == nullptr) - return 0; - unsigned length; - const char* str = luax_checklstring(L, 1, &length); - Text text(Encode::UTF8, str, length); - int x = luax_optnumber(L, 2, 0); - int y = luax_optnumber(L, 3, 0); - int lineheight = luax_optnumber(L, 4, font->getFontSize()); - int spacing = luax_optnumber(L, 5, 0); - font->print(text, x, y, lineheight, spacing); - return 0; - } - static int l_draw(lua_State* L) { if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE)) @@ -305,8 +311,6 @@ namespace lua l_draw_text(L); else if (luax_istype(L, 1, JIN_GRAPHICS_PAGE)) l_draw_page(L); - else if (luax_isstring(L, 1)) - l_print(L); else { luax_typerror(L, 1, "texture or canvas"); @@ -355,6 +359,24 @@ namespace lua } } + /* print(string, x, y, lineheight, spacing) */ + /* need set font */ + static int l_print(lua_State* L) + { + Font* font = context.curFont; + if (font == nullptr) + return 0; + unsigned length; + const char* str = luax_checklstring(L, 1, &length); + Text text(Encode::UTF8, str, length); + int x = luax_optnumber(L, 2, 0); + int y = luax_optnumber(L, 3, 0); + int lineheight = luax_optnumber(L, 4, font->getFontSize()); + int spacing = luax_optnumber(L, 5, 0); + font->print(text, x, y, lineheight, spacing); + return 0; + } + static int l_setColor(lua_State* L) { if (luax_gettop(L) == 0) @@ -670,6 +692,7 @@ namespace lua { "newBitmap", l_newBitmap }, { "newTexture", l_newTexture }, { "newShader", l_newShader }, + { "newShaderf", l_newShaderf }, { "newCanvas", l_newCanvas }, { "newTTFData", l_newTTFData }, { "newText", l_newText }, |