mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 08:51:10 +02:00
CLuaInstance: Add various CComponentsText fuctions
- Added: new, paint, hide, scroll
This commit is contained in:
@@ -388,6 +388,7 @@ void CLuaInstance::registerFunctions()
|
||||
HintboxRegister(lua);
|
||||
MessageboxRegister(lua);
|
||||
CWindowRegister(lua);
|
||||
ComponentsTextRegister(lua);
|
||||
SignalBoxRegister(lua);
|
||||
}
|
||||
|
||||
@@ -1442,3 +1443,151 @@ int CLuaInstance::SignalBoxDelete(lua_State *L)
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
CLuaComponentsText *CLuaInstance::ComponentsTextCheck(lua_State *L, int n)
|
||||
{
|
||||
return *(CLuaComponentsText **) luaL_checkudata(L, n, "componentstext");
|
||||
}
|
||||
|
||||
void CLuaInstance::ComponentsTextRegister(lua_State *L)
|
||||
{
|
||||
luaL_Reg meth[] = {
|
||||
{ "new", CLuaInstance::ComponentsTextNew },
|
||||
{ "paint", CLuaInstance::ComponentsTextPaint },
|
||||
{ "hide", CLuaInstance::ComponentsTextHide },
|
||||
{ "scroll", CLuaInstance::ComponentsTextScroll },
|
||||
{ "__gc", CLuaInstance::ComponentsTextDelete },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
luaL_newmetatable(L, "componentstext");
|
||||
luaL_setfuncs(L, meth, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -1, "__index");
|
||||
lua_setglobal(L, "componentstext");
|
||||
}
|
||||
|
||||
int CLuaInstance::ComponentsTextNew(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
|
||||
int x=10, y=10, dx=100, dy=100;
|
||||
std::string text = "";
|
||||
std::string tmpMode = "";
|
||||
int mode = CTextBox::AUTO_WIDTH;
|
||||
int font_text = SNeutrinoSettings::FONT_TYPE_MENU;
|
||||
lua_Integer color_text = (lua_Integer)COL_MENUCONTENT_TEXT;
|
||||
lua_Integer color_frame = (lua_Integer)COL_MENUCONTENT_PLUS_6;
|
||||
lua_Integer color_body = (lua_Integer)COL_MENUCONTENT_PLUS_0;
|
||||
lua_Integer color_shadow = (lua_Integer)COL_MENUCONTENTDARK_PLUS_0;
|
||||
std::string tmp1 = "false";
|
||||
|
||||
tableLookup(L, "x" , x);
|
||||
tableLookup(L, "y" , y);
|
||||
tableLookup(L, "dx" , dx);
|
||||
tableLookup(L, "dy" , dy);
|
||||
tableLookup(L, "text" , text);
|
||||
tableLookup(L, "mode" , tmpMode);
|
||||
tableLookup(L, "font_text" , font_text);
|
||||
if (font_text >= SNeutrinoSettings::FONT_TYPE_COUNT || font_text < 0)
|
||||
font_text = SNeutrinoSettings::FONT_TYPE_MENU;
|
||||
tableLookup(L, "has_shadow" , tmp1);
|
||||
bool has_shadow = (tmp1 == "true" || tmp1 == "1" || tmp1 == "yes");
|
||||
tableLookup(L, "color_text" , color_text);
|
||||
tableLookup(L, "color_frame" , color_frame);
|
||||
tableLookup(L, "color_body" , color_body);
|
||||
tableLookup(L, "color_shadow", color_shadow);
|
||||
|
||||
if (!tmpMode.empty()) {
|
||||
table_key txt_align[] = {
|
||||
{ "ALIGN_AUTO_WIDTH", CTextBox::AUTO_WIDTH },
|
||||
{ "ALIGN_AUTO_HIGH", CTextBox::AUTO_HIGH },
|
||||
{ "ALIGN_SCROLL", CTextBox::SCROLL },
|
||||
{ "ALIGN_CENTER", CTextBox::CENTER },
|
||||
{ "ALIGN_RIGHT", CTextBox::RIGHT },
|
||||
{ "ALIGN_TOP", CTextBox::TOP },
|
||||
{ "ALIGN_BOTTOM", CTextBox::BOTTOM },
|
||||
{ "ALIGN_NO_AUTO_LINEBREAK", CTextBox::NO_AUTO_LINEBREAK },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
mode = 0;
|
||||
for (int i = 0; txt_align[i].name; i++) {
|
||||
if (tmpMode.find(txt_align[i].name) != std::string::npos)
|
||||
mode |= txt_align[i].code;
|
||||
}
|
||||
}
|
||||
|
||||
CLuaComponentsText **udata = (CLuaComponentsText **) lua_newuserdata(L, sizeof(CLuaComponentsText *));
|
||||
*udata = new CLuaComponentsText();
|
||||
(*udata)->ct = new CComponentsText(x, y, dx, dy, text, mode, g_Font[font_text], has_shadow, (fb_pixel_t)color_text, (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow);
|
||||
luaL_getmetatable(L, "componentstext");
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaInstance::ComponentsTextPaint(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
std::string tmp = "true";
|
||||
tableLookup(L, "do_save_bg", tmp);
|
||||
bool do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes");
|
||||
|
||||
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
|
||||
m->ct->paint(do_save_bg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstance::ComponentsTextHide(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
std::string tmp = "false";
|
||||
tableLookup(L, "no_restore", tmp);
|
||||
bool no_restore = (tmp == "true" || tmp == "1" || tmp == "yes");
|
||||
|
||||
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
|
||||
m->ct->hide(no_restore);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstance::ComponentsTextScroll(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
std::string tmp = "true";
|
||||
tableLookup(L, "dir", tmp);
|
||||
bool scrollDown = (tmp == "down" || tmp == "1");
|
||||
|
||||
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
|
||||
//get the textbox instance from lua object and use CTexBbox scroll methods
|
||||
CTextBox* ctb = m->ct->getCTextBoxObject();
|
||||
if (ctb) {
|
||||
ctb->enableBackgroundPaint(true);
|
||||
if (scrollDown)
|
||||
ctb->scrollPageDown(1);
|
||||
else
|
||||
ctb->scrollPageUp(1);
|
||||
ctb->enableBackgroundPaint(false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstance::ComponentsTextDelete(lua_State *L)
|
||||
{
|
||||
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
|
||||
m->ct->kill();
|
||||
delete m;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user