From 90a3c2b8bae38c5a995ff5eef31731b6ae07c114 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 27 Apr 2015 04:19:03 -0300 Subject: [PATCH] Added Text:setFont. --- src/modules/graphics/opengl/Text.cpp | 10 ++++++++++ src/modules/graphics/opengl/Text.h | 1 + src/modules/graphics/opengl/wrap_Text.cpp | 9 +++++++++ src/modules/graphics/opengl/wrap_Text.h | 1 + 4 files changed, 21 insertions(+) diff --git a/src/modules/graphics/opengl/Text.cpp b/src/modules/graphics/opengl/Text.cpp index aad35d787..94cd434ee 100644 --- a/src/modules/graphics/opengl/Text.cpp +++ b/src/modules/graphics/opengl/Text.cpp @@ -265,6 +265,16 @@ void Text::draw(float x, float y, float angle, float sx, float sy, float ox, flo glDisableVertexAttribArray(ATTRIB_POS); } +void Text::setFont(Font *f) +{ + font.set(f); + + // Invalidate the texture cache ID since the font is different. We also have + // to re-upload all the vertices based on the new font's textures. + texture_cache_id = (uint32) -1; + regenerateVertices(); +} + Font *Text::getFont() const { return font.get(); diff --git a/src/modules/graphics/opengl/Text.h b/src/modules/graphics/opengl/Text.h index f5c04a9f5..598a7ce4b 100644 --- a/src/modules/graphics/opengl/Text.h +++ b/src/modules/graphics/opengl/Text.h @@ -52,6 +52,7 @@ public: // Implements Drawable. virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void setFont(Font *f); Font *getFont() const; /** diff --git a/src/modules/graphics/opengl/wrap_Text.cpp b/src/modules/graphics/opengl/wrap_Text.cpp index c60af4304..1f53871d5 100644 --- a/src/modules/graphics/opengl/wrap_Text.cpp +++ b/src/modules/graphics/opengl/wrap_Text.cpp @@ -135,6 +135,14 @@ int w_Text_clear(lua_State *L) return 0; } +int w_Text_setFont(lua_State *L) +{ + Text *t = luax_checktext(L, 1); + Font *f = luax_checktype(L, 2, GRAPHICS_FONT_ID); + luax_catchexcept(L, [&](){ t->setFont(f); }); + return 0; +} + int w_Text_getFont(lua_State *L) { Text *t = luax_checktext(L, 1); @@ -164,6 +172,7 @@ static const luaL_Reg functions[] = { "add", w_Text_add }, { "addf", w_Text_addf }, { "clear", w_Text_clear }, + { "setFont", w_Text_setFont }, { "getFont", w_Text_getFont }, { "getWidth", w_Text_getWidth }, { "getHeight", w_Text_getHeight }, diff --git a/src/modules/graphics/opengl/wrap_Text.h b/src/modules/graphics/opengl/wrap_Text.h index b156b71a6..fb867b85b 100644 --- a/src/modules/graphics/opengl/wrap_Text.h +++ b/src/modules/graphics/opengl/wrap_Text.h @@ -37,6 +37,7 @@ int w_Text_setf(lua_State *L); int w_Text_add(lua_State *L); int w_Text_addf(lua_State *L); int w_Text_clear(lua_State *L); +int w_Text_setFont(lua_State *L); int w_Text_getFont(lua_State *L); int w_Text_getWidth(lua_State *L); int w_Text_getHeight(lua_State *L);