diff options
Diffstat (limited to 'src/lua/modules/graphics/je_lua_ttf.cpp')
-rw-r--r-- | src/lua/modules/graphics/je_lua_ttf.cpp | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp index 31af310..6cade75 100644 --- a/src/lua/modules/graphics/je_lua_ttf.cpp +++ b/src/lua/modules/graphics/je_lua_ttf.cpp @@ -2,7 +2,7 @@ #include "lua/modules/types.h" #include "lua/common/je_lua_common.h" #include "libjin/jin.h" -#include "je_lua_ttf.h" +#include "je_lua_page.h" using namespace JinEngine::Graphics; using namespace JinEngine::Graphics::Fonts; @@ -12,37 +12,9 @@ namespace JinEngine namespace Lua { - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - // TTFData - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - - TTF* TTFData::createTTF(unsigned fontSize) - { - TTF* ttf; - try - { - ttf = new TTF(this, fontSize); - } - catch (...) - { - return nullptr; - } - return ttf; - } - - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - // TTF - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - LUA_IMPLEMENT int l_gc(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); - { - /* release ttf data */ - Shared<TTF>* ttf = &proxy->getShared<TTF>(); - SharedBase* data = (SharedBase*)ttf->getUserdata(); - data->release(); - } proxy->release(); return 0; } @@ -50,8 +22,9 @@ namespace JinEngine /* typeset(Text | string, lineheight, spacing) */ LUA_IMPLEMENT int l_typeset(lua_State* L) { - Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); - TTF* ttf = p->getObject<TTF>(); + Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); + Shared<TTF>& shrTTF = pxyTTF->getShared<TTF>(); + TTF* ttf = pxyTTF->getObject<TTF>(); int lineheight = luax_optnumber(L, 3, ttf->getFontSize()); int spacing = luax_optnumber(L, 4, 0); Page* page = nullptr; @@ -64,19 +37,14 @@ namespace JinEngine } else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT)) { - Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); - Text* text = p2->getObject<Text>(); + Proxy* pxyText = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); + Text* text = pxyText->getObject<Text>(); page = ttf->typeset(*text, lineheight, spacing); } - Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE); + Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE); Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE); - { - /* retain related ttf */ - Shared<TTF>& refTTF = p->getShared<TTF>(); - refTTF.retain(); - refPage->setUserdata(&refTTF); - } - proxy->bind(refPage); + refPage->setDependency(DEP_TTF, &shrTTF); + pxyPage->bind(refPage); return 1; } |