CLuaInstance: Add setText function to ctext

This commit is contained in:
M. Liebmann
2014-03-16 11:56:57 +01:00
parent 81608cbd3f
commit 4df0449e39
2 changed files with 27 additions and 2 deletions

View File

@@ -1537,6 +1537,7 @@ void CLuaInstance::ComponentsTextRegister(lua_State *L)
{ "new", CLuaInstance::ComponentsTextNew },
{ "paint", CLuaInstance::ComponentsTextPaint },
{ "hide", CLuaInstance::ComponentsTextHide },
{ "setText", CLuaInstance::ComponentsTextSetText },
{ "scroll", CLuaInstance::ComponentsTextScroll },
{ "__gc", CLuaInstance::ComponentsTextDelete },
{ NULL, NULL }
@@ -1610,6 +1611,8 @@ int CLuaInstance::ComponentsTextNew(lua_State *L)
*udata = new CLuaComponentsText();
(*udata)->ct = new CComponentsText(x, y, dx, dy, text, mode, g_Font[font_text], pw, has_shadow, (fb_pixel_t)color_text, (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow);
(*udata)->parent = pw;
(*udata)->mode = mode;
(*udata)->font_text = font_text;
luaL_getmetatable(L, "ctext");
lua_setmetatable(L, -2);
return 1;
@@ -1639,8 +1642,28 @@ int CLuaInstance::ComponentsTextHide(lua_State *L)
tableLookup(L, "no_restore", tmp);
bool no_restore = (tmp == "true" || tmp == "1" || tmp == "yes");
m->ct->hide(no_restore);
if (m->parent) {
m->ct->setText("", m->mode, g_Font[m->font_text]);
m->ct->paint();
} else
m->ct->hide(no_restore);
return 0;
}
int CLuaInstance::ComponentsTextSetText(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m) return 0;
std::string text = "";
int mode = m->mode;
int font_text = m->font_text;
tableLookup(L, "text", text);
tableLookup(L, "mode", mode);
tableLookup(L, "font_text", font_text);
m->ct->setText(text, mode, g_Font[font_text]);
return 0;
}

View File

@@ -139,7 +139,8 @@ class CLuaComponentsText
public:
CComponentsText *ct;
CComponentsForm *parent;
CLuaComponentsText() { ct = NULL; parent = NULL;}
int mode, font_text;
CLuaComponentsText() { ct = NULL; parent = NULL; mode = 0; font_text = 0;}
~CLuaComponentsText() { if (parent == NULL) delete ct; }
};
@@ -214,6 +215,7 @@ private:
static int ComponentsTextNew(lua_State *L);
static int ComponentsTextPaint(lua_State *L);
static int ComponentsTextHide(lua_State *L);
static int ComponentsTextSetText(lua_State *L);
static int ComponentsTextScroll(lua_State *L);
static int ComponentsTextDelete(lua_State *L);