CLuaInstance: Add function checkMagicMask() for use the color constants

- Use checkMagicMask() for colors in CComponents-Lua functions
This commit is contained in:
M. Liebmann
2014-07-16 23:34:09 +02:00
parent 0714c7f5ed
commit a3c453c403
2 changed files with 24 additions and 5 deletions

View File

@@ -347,6 +347,14 @@ void CLuaInstance::functionDeprecated(lua_State *L, const char* oldFunc, const c
ar.short_src, ar.currentline);
}
lua_Unsigned CLuaInstance::checkMagicMask(lua_Unsigned &col)
{
if ((col & MAGIC_MASK) == MAGIC_COLOR)
/* use the color constants */
col = CFrameBuffer::getInstance()->realcolor[col & 0x000000ff];
return col;
}
#define SET_VAR1(NAME) \
lua_pushinteger(lua, NAME); \
lua_setglobal(lua, #NAME);
@@ -550,9 +558,7 @@ int CLuaInstance::PaintBox(lua_State *L)
w = W->fbwin->dx - x;
if (h < 0 || y + h > W->fbwin->dy)
h = W->fbwin->dy - y;
/* use the color constants */
if ((c & MAGIC_MASK) == MAGIC_COLOR)
c = CFrameBuffer::getInstance()->realcolor[c & 0x000000ff];
checkMagicMask(c);
W->fbwin->paintBoxRel(x, y, w, h, c, radius, corner);
return 0;
}
@@ -666,8 +672,7 @@ int CLuaInstance::RenderString(lua_State *L)
if (rwidth < w)
x += (w - rwidth) / 2;
}
if ((c & MAGIC_MASK) == MAGIC_COLOR)
c = CFrameBuffer::getInstance()->realcolor[c & 0x000000ff];
checkMagicMask(c);
if (boxh > -1) /* if boxh < 0, don't paint string */
W->fbwin->RenderString(g_Font[f], x, y, w, text, c, boxh);
lua_pushinteger(L, rwidth); /* return renderwidth */
@@ -1500,6 +1505,10 @@ int CLuaInstance::CWindowNew(lua_State *L)
tableLookup(L, "btnYellow", btnYellow);
tableLookup(L, "btnBlue", btnBlue);
checkMagicMask(color_frame);
checkMagicMask(color_body);
checkMagicMask(color_shadow);
tmp1 = "true";
tableLookup(L, "show_header" , tmp1);
bool show_header = (tmp1 == "true" || tmp1 == "show" || tmp1 == "yes");
@@ -1793,6 +1802,11 @@ int CLuaInstance::ComponentsTextNew(lua_State *L)
tableLookup(L, "color_body" , color_body);
tableLookup(L, "color_shadow", color_shadow);
checkMagicMask(color_text);
checkMagicMask(color_frame);
checkMagicMask(color_body);
checkMagicMask(color_shadow);
if (!tmpMode.empty()) {
table_key txt_align[] = {
{ "ALIGN_AUTO_WIDTH", CTextBox::AUTO_WIDTH },
@@ -1974,6 +1988,10 @@ int CLuaInstance::CPictureNew(lua_State *L)
tableLookup(L, "color_shadow" , color_shadow);
tableLookup(L, "transparency" , transparency);
checkMagicMask(color_frame);
checkMagicMask(color_background);
checkMagicMask(color_shadow);
CComponentsForm* pw = (parent && parent->w) ? parent->w->getBodyObject() : NULL;
CLuaPicture **udata = (CLuaPicture **) lua_newuserdata(L, sizeof(CLuaPicture *));

View File

@@ -178,6 +178,7 @@ private:
void registerFunctions();
static void functionDeprecated(lua_State *L, const char* oldFunc, const char* newFunc);
static lua_Unsigned checkMagicMask(lua_Unsigned &col);
static int NewWindow(lua_State *L);
static int PaintBox(lua_State *L);