CLuaInstance: Add function getRenderWidth()

This commit is contained in:
M. Liebmann
2014-02-21 00:00:56 +01:00
parent 3f0400a23e
commit 6475e77a84
2 changed files with 20 additions and 0 deletions

View File

@@ -340,6 +340,7 @@ const luaL_Reg CLuaInstance::methods[] =
{ "PaintIcon", CLuaInstance::PaintIcon }, { "PaintIcon", CLuaInstance::PaintIcon },
{ "GetInput", CLuaInstance::GetInput }, { "GetInput", CLuaInstance::GetInput },
{ "FontHeight", CLuaInstance::FontHeight }, { "FontHeight", CLuaInstance::FontHeight },
{ "getRenderWidth", CLuaInstance::getRenderWidth },
{ "GetSize", CLuaInstance::GetSize }, { "GetSize", CLuaInstance::GetSize },
{ "DisplayImage", CLuaInstance::DisplayImage }, { "DisplayImage", CLuaInstance::DisplayImage },
{ "Blit", CLuaInstance::Blit }, { "Blit", CLuaInstance::Blit },
@@ -555,6 +556,24 @@ int CLuaInstance::RenderString(lua_State *L)
return 1; return 1;
} }
int CLuaInstance::getRenderWidth(lua_State *L)
{
int f;
const char *text;
DBG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaData *W = CheckData(L, 1);
if (!W)
return 0;
f = luaL_checkint(L, 2); /* font number, use FONT['xxx'] for FONT_TYPE_xxx in the script */
text = luaL_checkstring(L, 3); /* text */
if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0)
f = SNeutrinoSettings::FONT_TYPE_MENU;
lua_pushinteger(L, (int)g_Font[f]->getRenderWidth(text, true));
return 1;
}
int CLuaInstance::GetInput(lua_State *L) int CLuaInstance::GetInput(lua_State *L)
{ {
int numargs = lua_gettop(L); int numargs = lua_gettop(L);

View File

@@ -155,6 +155,7 @@ private:
static int PaintBox(lua_State *L); static int PaintBox(lua_State *L);
static int PaintIcon(lua_State *L); static int PaintIcon(lua_State *L);
static int RenderString(lua_State *L); static int RenderString(lua_State *L);
static int getRenderWidth(lua_State *L);
static int FontHeight(lua_State *L); static int FontHeight(lua_State *L);
static int GetInput(lua_State *L); static int GetInput(lua_State *L);
static int GCWindow(lua_State *L); static int GCWindow(lua_State *L);