From 0bfff69053e27fbb6e541a6b8afa6c8e61a62403 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Nov 2018 00:51:15 +0800 Subject: =?UTF-8?q?*shared=20=E5=A2=9E=E5=8A=A0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/modules/graphics/je_lua_ttf.cpp | 50 ++++++--------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) (limited to 'src/lua/modules/graphics/je_lua_ttf.cpp') 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 = &proxy->getShared(); - 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(); + Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); + Shared& shrTTF = pxyTTF->getShared(); + TTF* ttf = pxyTTF->getObject(); 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(); + Proxy* pxyText = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); + Text* text = pxyText->getObject(); page = ttf->typeset(*text, lineheight, spacing); } - Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE); + Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE); Shared* refPage = new Shared(page, JIN_GRAPHICS_PAGE); - { - /* retain related ttf */ - Shared& refTTF = p->getShared(); - refTTF.retain(); - refPage->setUserdata(&refTTF); - } - proxy->bind(refPage); + refPage->setDependency(DEP_TTF, &shrTTF); + pxyPage->bind(refPage); return 1; } -- cgit v1.1-26-g67d0