From 7c7c7e55a4be89cc6969e48a8f262ec3514fb2e1 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 7 Apr 2013 18:18:38 +0200 Subject: [PATCH] luainstance: remove utf8 parameter from RenderString, add center Everybody should always be using utf8 anyway, so remove the "utf8" parameter from RenderString and replace it with a "center" parameter which centers the string horizontally in its box. new usage: RenderString(font, text, x, y, color, boxwidth, boxheight, center) defaults: color = COL_MENUCONTENT, boxwidth = window's width minus x boxheight = 0, center = 0 --- src/gui/luainstance.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index 9e3a0bb98..b1a83ddde 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -430,14 +430,14 @@ int CLuaInstance::PaintIcon(lua_State *L) int CLuaInstance::RenderString(lua_State *L) { - int x, y, w, boxh, utf8, f; + int x, y, w, boxh, f, center; unsigned int c; const char *text; int numargs = lua_gettop(L); DBG("CLuaInstance::%s %d\n", __func__, numargs); c = COL_MENUCONTENT; boxh = 0; - utf8 = 1; + center = 0; CLuaData *W = CheckData(L, 1); if (!W || !W->fbwin) @@ -455,11 +455,16 @@ int CLuaInstance::RenderString(lua_State *L) if (numargs > 7) boxh = luaL_checkint(L, 8); if (numargs > 8) - utf8 = luaL_checkint(L, 9); - if (f >= FONT_TYPE_COUNT || f < 0) + center = luaL_checkint(L, 9); + if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0) f = SNeutrinoSettings::FONT_TYPE_MENU; + if (center) { /* center the text inside the box */ + int rwidth = g_Font[f]->getRenderWidth(text, true); + if (rwidth < w) + x += (w - rwidth) / 2; + } c &= 0x000000FF; /* TODO: colors that are not in the palette? */ - W->fbwin->RenderString(g_Font[f], x, y, w, text, c, boxh, utf8); + W->fbwin->RenderString(g_Font[f], x, y, w, text, c, boxh, true); return 0; } @@ -497,7 +502,7 @@ int CLuaInstance::FontHeight(lua_State *L) if (!W) return 0; f = luaL_checkint(L, 2); /* font number, use FONT['xxx'] for FONT_TYPE_xxx in the script */ - if (f >= FONT_TYPE_COUNT || f < 0) + if (f >= SNeutrinoSettings::FONT_TYPE_COUNT || f < 0) f = SNeutrinoSettings::FONT_TYPE_MENU; lua_pushinteger(L, (int)g_Font[f]->getHeight()); return 1;