mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Added Text:setFont.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Font>(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 },
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user