CLuaInstance: Move ccomponents functions in separate classes / files

- cwindow (CComponentsWindow)
 - ctext (CComponentsText)
 - cpicture (CComponentsPicture)
 - signalbox (CSignalBox)

 - No api changes, code only


Origin commit data
------------------
Branch: ni/coolstream
Commit: ad17505888
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2015-12-12 (Sat, 12 Dec 2015)

Origin message was:
------------------
CLuaInstance: Move ccomponents functions in separate classes / files

 - cwindow  (CComponentsWindow)
 - ctext   (CComponentsText)
 - cpicture (CComponentsPicture)
 - signalbox (CSignalBox)

 - No api changes, code only


------------------
This commit was generated by Migit
This commit is contained in:
Michael Liebmann
2015-12-12 10:21:59 +01:00
parent 7fe7dd701c
commit 672e1ca1d0
11 changed files with 1159 additions and 860 deletions

View File

@@ -37,6 +37,10 @@
#include <neutrino.h>
#include "luainstance.h"
#include "lua_cc_picture.h"
#include "lua_cc_signalbox.h"
#include "lua_cc_text.h"
#include "lua_cc_window.h"
#include "lua_configfile.h"
#include "lua_menue.h"
#include "lua_video.h"
@@ -540,10 +544,10 @@ void CLuaInstance::registerFunctions()
HintboxRegister(lua);
MessageboxRegister(lua);
CWindowRegister(lua);
ComponentsTextRegister(lua);
SignalBoxRegister(lua);
CPictureRegister(lua);
CLuaInstCCPicture::getInstance()->CCPictureRegister(lua);
CLuaInstCCSignalbox::getInstance()->CCSignalBoxRegister(lua);
CLuaInstCCText::getInstance()->CCTextRegister(lua);
CLuaInstCCWindow::getInstance()->CCWindowRegister(lua);
CLuaInstConfigFile::getInstance()->LuaConfigFileRegister(lua);
CLuaInstMenu::getInstance()->MenuRegister(lua);
}
@@ -1383,783 +1387,6 @@ int CLuaInstance::MessageboxExec(lua_State *L)
// --------------------------------------------------------------------------------
void CLuaInstance::CWindowRegister(lua_State *L)
{
luaL_Reg meth[] = {
{ "new", CLuaInstance::CWindowNew },
{ "paint", CLuaInstance::CWindowPaint },
{ "hide", CLuaInstance::CWindowHide },
{ "setCaption", CLuaInstance::CWindowSetCaption },
{ "setWindowColor", CLuaInstance::CWindowSetWindowColor },
{ "paintHeader", CLuaInstance::CWindowPaintHeader },
{ "headerHeight", CLuaInstance::CWindowGetHeaderHeight },
{ "footerHeight", CLuaInstance::CWindowGetFooterHeight },
{ "header_height", CLuaInstance::CWindowGetHeaderHeight_dep }, /* function 'header_height' is deprecated */
{ "footer_height", CLuaInstance::CWindowGetFooterHeight_dep }, /* function 'footer_height' is deprecated */
{ "setCenterPos", CLuaInstance::CWindowSetCenterPos },
{ "__gc", CLuaInstance::CWindowDelete },
{ NULL, NULL }
};
luaL_newmetatable(L, "cwindow");
luaL_setfuncs(L, meth, 0);
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
lua_setglobal(L, "cwindow");
}
int CLuaInstance::CWindowNew(lua_State *L)
{
lua_assert(lua_istable(L,1));
std::string name, icon = std::string(NEUTRINO_ICON_INFO);
lua_Unsigned color_frame = (lua_Unsigned)COL_MENUCONTENT_PLUS_6;
lua_Unsigned color_body = (lua_Unsigned)COL_MENUCONTENT_PLUS_0;
lua_Unsigned color_shadow = (lua_Unsigned)COL_MENUCONTENTDARK_PLUS_0;
std::string tmp1 = "false";
std::string btnRed = "";
std::string btnGreen = "";
std::string btnYellow = "";
std::string btnBlue = "";
lua_Integer x = 100, y = 100, dx = 450, dy = 250;
tableLookup(L, "x", x);
tableLookup(L, "y", y);
tableLookup(L, "dx", dx);
tableLookup(L, "dy", dy);
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
tableLookup(L, "icon", icon);
bool has_shadow = false;
if (!tableLookup(L, "has_shadow", has_shadow))
{
tmp1 = "false";
if (tableLookup(L, "has_shadow", tmp1))
paramBoolDeprecated(L, tmp1.c_str());
has_shadow = (tmp1 == "true" || tmp1 == "1" || tmp1 == "yes");
}
tableLookup(L, "color_frame" , color_frame);
tableLookup(L, "color_body" , color_body);
tableLookup(L, "color_shadow", color_shadow);
tableLookup(L, "btnRed", btnRed);
tableLookup(L, "btnGreen", btnGreen);
tableLookup(L, "btnYellow", btnYellow);
tableLookup(L, "btnBlue", btnBlue);
checkMagicMask(color_frame);
checkMagicMask(color_body);
checkMagicMask(color_shadow);
bool show_header = true;
if (!tableLookup(L, "show_header", show_header))
{
tmp1 = "true";
if (tableLookup(L, "show_header", tmp1))
paramBoolDeprecated(L, tmp1.c_str());
show_header = (tmp1 == "true" || tmp1 == "1" || tmp1 == "yes");
}
bool show_footer = true;
if (!tableLookup(L, "show_footer", show_footer))
{
tmp1 = "true";
if (tableLookup(L, "show_footer", tmp1))
paramBoolDeprecated(L, tmp1.c_str());
show_footer = (tmp1 == "true" || tmp1 == "1" || tmp1 == "yes");
}
CLuaCWindow **udata = (CLuaCWindow **) lua_newuserdata(L, sizeof(CLuaCWindow *));
*udata = new CLuaCWindow();
(*udata)->w = new CComponentsWindow(x, y, dx, dy, name.c_str(), icon.c_str(), 0, has_shadow, (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow);
if (!show_header)
(*udata)->w->showHeader(false);
if (!show_footer)
(*udata)->w->showFooter(false);
else {
CComponentsFooter* footer = (*udata)->w->getFooterObject();
if (footer) {
vector<button_label_s> buttons;
if (!btnRed.empty()){
button_label_s btnSred;
btnSred.button = NEUTRINO_ICON_BUTTON_RED;
btnSred.text = btnRed;
buttons.push_back(btnSred);
}
if (!btnGreen.empty()){
button_label_s btnSgreen;
btnSgreen.button = NEUTRINO_ICON_BUTTON_GREEN;
btnSgreen.text = btnGreen;
buttons.push_back(btnSgreen);
}
if (!btnYellow.empty()){
button_label_s btnSyellow;
btnSyellow.button = NEUTRINO_ICON_BUTTON_YELLOW;
btnSyellow.text = btnYellow;
buttons.push_back(btnSyellow);
}
if (!btnBlue.empty()){
button_label_s btnSblue;
btnSblue.button = NEUTRINO_ICON_BUTTON_BLUE;
btnSblue.text = btnBlue;
buttons.push_back(btnSblue);
}
if(!buttons.empty())
footer->setButtonLabels(buttons, dx-20, (dx-20) / (buttons.size()+1));
}
}
luaL_getmetatable(L, "cwindow");
lua_setmetatable(L, -2);
return 1;
}
CLuaCWindow *CLuaInstance::CWindowCheck(lua_State *L, int n)
{
return *(CLuaCWindow **) luaL_checkudata(L, n, "cwindow");
}
int CLuaInstance::CWindowPaint(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m) return 0;
bool do_save_bg = true;
if (!tableLookup(L, "do_save_bg", do_save_bg))
{
std::string tmp = "true";
if (tableLookup(L, "do_save_bg", tmp))
paramBoolDeprecated(L, tmp.c_str());
do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes");
}
m->w->paint(do_save_bg);
return 0;
}
int CLuaInstance::CWindowHide(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m) return 0;
bool no_restore = false;
if (!tableLookup(L, "no_restore", no_restore))
{
std::string tmp = "false";
if (tableLookup(L, "no_restore", tmp))
paramBoolDeprecated(L, tmp.c_str());
no_restore = (tmp == "true" || tmp == "1" || tmp == "yes");
}
m->w->hide(no_restore);
return 0;
}
int CLuaInstance::CWindowSetCaption(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m) return 0;
std::string name = "";
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
m->w->setWindowCaption(name);
return 0;
}
int CLuaInstance::CWindowSetWindowColor(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m) return 0;
lua_Unsigned color;
if (tableLookup(L, "color_frame" , color)) {
checkMagicMask(color);
m->w->setColorFrame(color);
}
if (tableLookup(L, "color_body" , color)) {
checkMagicMask(color);
m->w->setColorBody(color);
}
if (tableLookup(L, "color_shadow" , color)) {
checkMagicMask(color);
m->w->setColorShadow(color);
}
return 0;
}
int CLuaInstance::CWindowPaintHeader(lua_State *L)
{
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m) return 0;
CComponentsHeader* header = m->w->getHeaderObject();
if (header)
m->w->showHeader();
header->paint();
return 0;
}
// function 'header_height' is deprecated
int CLuaInstance::CWindowGetHeaderHeight_dep(lua_State *L)
{
functionDeprecated(L, "header_height", "headerHeight");
return CWindowGetHeaderHeight(L);
}
// function 'footer_height' is deprecated
int CLuaInstance::CWindowGetFooterHeight_dep(lua_State *L)
{
functionDeprecated(L, "footer_height", "footerHeight");
return CWindowGetFooterHeight(L);
}
int CLuaInstance::CWindowGetHeaderHeight(lua_State *L)
{
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m)
return 0;
CComponentsHeader* header = m->w->getHeaderObject();
int hh = 0;
if (header)
hh = header->getHeight();
lua_pushinteger(L, hh);
return 1;
}
int CLuaInstance::CWindowGetFooterHeight(lua_State *L)
{
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m)
return 0;
CComponentsFooter* footer = m->w->getFooterObject();
int fh = 0;
if (footer)
fh = footer->getHeight();
lua_pushinteger(L, fh);
return 1;
}
int CLuaInstance::CWindowSetCenterPos(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m) return 0;
lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y;
tableLookup(L, "along_mode", tmp_along_mode);
if(tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y)
along_mode=tmp_along_mode;
m->w->setCenterPos(along_mode);
return 0;
}
int CLuaInstance::CWindowDelete(lua_State *L)
{
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaCWindow *m = CWindowCheck(L, 1);
if (!m)
return 0;
delete m;
return 0;
}
// --------------------------------------------------------------------------------
CLuaSignalBox *CLuaInstance::SignalBoxCheck(lua_State *L, int n)
{
return *(CLuaSignalBox **) luaL_checkudata(L, n, "signalbox");
}
void CLuaInstance::SignalBoxRegister(lua_State *L)
{
luaL_Reg meth[] = {
{ "new", CLuaInstance::SignalBoxNew },
{ "paint", CLuaInstance::SignalBoxPaint },
{ "setCenterPos", CLuaInstance::SignalBoxSetCenterPos },
{ "__gc", CLuaInstance::SignalBoxDelete },
{ NULL, NULL }
};
luaL_newmetatable(L, "signalbox");
luaL_setfuncs(L, meth, 0);
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
lua_setglobal(L, "signalbox");
}
int CLuaInstance::SignalBoxNew(lua_State *L)
{
lua_assert(lua_istable(L,1));
std::string name, icon = std::string(NEUTRINO_ICON_INFO);
lua_Integer x = 110, y = 150, dx = 430, dy = 150;
lua_Integer vertical = true;
CLuaCWindow* parent = NULL;
tableLookup(L, "x", x);
tableLookup(L, "y", y);
tableLookup(L, "dx", dx);
tableLookup(L, "dy", dy);
tableLookup(L, "vertical", vertical);
tableLookup(L, "parent", (void**)&parent);
CComponentsForm* pw = (parent && parent->w) ? parent->w->getBodyObject() : NULL;
CLuaSignalBox **udata = (CLuaSignalBox **) lua_newuserdata(L, sizeof(CLuaSignalBox *));
*udata = new CLuaSignalBox();
(*udata)->s = new CSignalBox(x, y, dx, dy, NULL, (vertical!=0)?true:false, pw);
(*udata)->parent = pw;
luaL_getmetatable(L, "signalbox");
lua_setmetatable(L, -2);
return 1;
}
int CLuaInstance::SignalBoxPaint(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaSignalBox *m = SignalBoxCheck(L, 1);
if (!m) return 0;
bool do_save_bg = true;
if (!tableLookup(L, "do_save_bg", do_save_bg))
{
std::string tmp = "true";
if (tableLookup(L, "do_save_bg", tmp))
paramBoolDeprecated(L, tmp.c_str());
do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes");
}
m->s->paint(do_save_bg);
return 0;
}
int CLuaInstance::SignalBoxSetCenterPos(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaSignalBox *m = SignalBoxCheck(L, 1);
if (!m) return 0;
lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y;
tableLookup(L, "along_mode", tmp_along_mode);
if(tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y)
along_mode=tmp_along_mode;
m->s->setCenterPos(along_mode);
return 0;
}
int CLuaInstance::SignalBoxDelete(lua_State *L)
{
CLuaSignalBox *m = SignalBoxCheck(L, 1);
if (!m)
return 0;
delete m;
return 0;
}
// --------------------------------------------------------------------------------
CLuaComponentsText *CLuaInstance::ComponentsTextCheck(lua_State *L, int n)
{
return *(CLuaComponentsText **) luaL_checkudata(L, n, "ctext");
}
void CLuaInstance::ComponentsTextRegister(lua_State *L)
{
luaL_Reg meth[] = {
{ "new", CLuaInstance::ComponentsTextNew },
{ "paint", CLuaInstance::ComponentsTextPaint },
{ "hide", CLuaInstance::ComponentsTextHide },
{ "setText", CLuaInstance::ComponentsTextSetText },
{ "scroll", CLuaInstance::ComponentsTextScroll },
{ "setCenterPos", CLuaInstance::ComponentsTextSetCenterPos },
{ "enableUTF8", CLuaInstance::ComponentsTextEnableUTF8 },
{ "__gc", CLuaInstance::ComponentsTextDelete },
{ NULL, NULL }
};
luaL_newmetatable(L, "ctext");
luaL_setfuncs(L, meth, 0);
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
lua_setglobal(L, "ctext");
}
int CLuaInstance::ComponentsTextNew(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow* parent = NULL;
lua_Integer x=10, y=10, dx=100, dy=100;
std::string text = "";
std::string tmpMode = "";
lua_Integer mode = CTextBox::AUTO_WIDTH;
lua_Integer font_text = SNeutrinoSettings::FONT_TYPE_MENU;
lua_Unsigned color_text = (lua_Unsigned)COL_MENUCONTENT_TEXT;
lua_Unsigned color_frame = (lua_Unsigned)COL_MENUCONTENT_PLUS_6;
lua_Unsigned color_body = (lua_Unsigned)COL_MENUCONTENT_PLUS_0;
lua_Unsigned color_shadow = (lua_Unsigned)COL_MENUCONTENTDARK_PLUS_0;
tableLookup(L, "parent" , (void**)&parent);
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;
bool has_shadow = false;
if (!tableLookup(L, "has_shadow", has_shadow))
{
std::string tmp1 = "false";
if (tableLookup(L, "has_shadow", tmp1))
paramBoolDeprecated(L, tmp1.c_str());
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);
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 },
{ "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 },
{ "DECODE_HTML", 0 },
{ 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;
}
if (tmpMode.find("DECODE_HTML") != std::string::npos)
htmlEntityDecode(text);
}
CComponentsForm* pw = (parent && parent->w) ? parent->w->getBodyObject() : NULL;
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], 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;
}
int CLuaInstance::ComponentsTextPaint(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m) return 0;
bool do_save_bg = true;
if (!tableLookup(L, "do_save_bg", do_save_bg))
{
std::string tmp = "true";
if (tableLookup(L, "do_save_bg", tmp))
paramBoolDeprecated(L, tmp.c_str());
do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes");
}
m->ct->paint(do_save_bg);
return 0;
}
int CLuaInstance::ComponentsTextHide(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m) return 0;
bool no_restore = false;
if (!tableLookup(L, "no_restore", no_restore))
{
std::string tmp = "false";
if (tableLookup(L, "no_restore", tmp))
paramBoolDeprecated(L, tmp.c_str());
no_restore = (tmp == "true" || tmp == "1" || tmp == "yes");
}
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 = "";
lua_Integer mode = m->mode;
lua_Integer 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;
}
int CLuaInstance::ComponentsTextScroll(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m) return 0;
std::string tmp = "true";
tableLookup(L, "dir", tmp);
bool scrollDown = (tmp == "down" || tmp == "1");
//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::ComponentsTextSetCenterPos(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m) return 0;
lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y;
tableLookup(L, "along_mode", tmp_along_mode);
if(tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y)
along_mode=tmp_along_mode;
m->ct->setCenterPos(along_mode);
return 0;
}
int CLuaInstance::ComponentsTextEnableUTF8(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m) return 0;
bool utf8_encoded = true;
if (!tableLookup(L, "utf8_encoded", utf8_encoded))
{
std::string tmp = "true";
if (tableLookup(L, "utf8_encoded", tmp))
paramBoolDeprecated(L, tmp.c_str());
utf8_encoded = (tmp == "true" || tmp == "1" || tmp == "yes");
}
m->ct->enableUTF8(utf8_encoded);
return 0;
}
int CLuaInstance::ComponentsTextDelete(lua_State *L)
{
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaComponentsText *m = ComponentsTextCheck(L, 1);
if (!m)
return 0;
delete m;
return 0;
}
// --------------------------------------------------------------------------------
CLuaPicture *CLuaInstance::CPictureCheck(lua_State *L, int n)
{
return *(CLuaPicture **) luaL_checkudata(L, n, "cpicture");
}
void CLuaInstance::CPictureRegister(lua_State *L)
{
luaL_Reg meth[] = {
{ "new", CLuaInstance::CPictureNew },
{ "paint", CLuaInstance::CPicturePaint },
{ "hide", CLuaInstance::CPictureHide },
{ "setPicture", CLuaInstance::CPictureSetPicture },
{ "setCenterPos", CLuaInstance::CPictureSetCenterPos },
{ "__gc", CLuaInstance::CPictureDelete },
{ NULL, NULL }
};
luaL_newmetatable(L, "cpicture");
luaL_setfuncs(L, meth, 0);
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
lua_setglobal(L, "cpicture");
}
int CLuaInstance::CPictureNew(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaCWindow* parent = NULL;
lua_Integer x=10, y=10, dx=100, dy=100;
std::string image_name = "";
lua_Integer alignment = 0;
lua_Unsigned color_frame = (lua_Unsigned)COL_MENUCONTENT_PLUS_6;
lua_Unsigned color_background = (lua_Unsigned)COL_MENUCONTENT_PLUS_0;
lua_Unsigned color_shadow = (lua_Unsigned)COL_MENUCONTENTDARK_PLUS_0;
/*
transparency = CFrameBuffer::TM_BLACK (2): Transparency when black content ('pseudo' transparency)
transparency = CFrameBuffer::TM_NONE (1): No 'pseudo' transparency
*/
lua_Integer transparency = CFrameBuffer::TM_NONE;
tableLookup(L, "parent" , (void**)&parent);
tableLookup(L, "x" , x);
tableLookup(L, "y" , y);
tableLookup(L, "dx" , dx);
tableLookup(L, "dy" , dy);
tableLookup(L, "image" , image_name);
tableLookup(L, "alignment" , alignment); //invalid argumet, for compatibility
if (alignment)
dprintf(DEBUG_NORMAL, "[CLuaInstance][%s - %d] invalid argument: 'alignment' has no effect!\n", __func__, __LINE__);
bool has_shadow = false;
if (!tableLookup(L, "has_shadow", has_shadow))
{
std::string tmp1 = "false";
if (tableLookup(L, "has_shadow", tmp1))
paramBoolDeprecated(L, tmp1.c_str());
has_shadow = (tmp1 == "true" || tmp1 == "1" || tmp1 == "yes");
}
tableLookup(L, "color_frame" , color_frame);
tableLookup(L, "color_background" , color_background);
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 *));
*udata = new CLuaPicture();
if (dx == 0 && dy == 0) /* NO_SCALE */
(*udata)->cp = new CComponentsPicture(x, y, image_name, pw, has_shadow, (fb_pixel_t)color_frame, (fb_pixel_t)color_background, (fb_pixel_t)color_shadow, transparency);
else
(*udata)->cp = new CComponentsPicture(x, y, dx, dy, image_name, pw, has_shadow, (fb_pixel_t)color_frame, (fb_pixel_t)color_background, (fb_pixel_t)color_shadow, transparency);
(*udata)->parent = pw;
luaL_getmetatable(L, "cpicture");
lua_setmetatable(L, -2);
return 1;
}
int CLuaInstance::CPicturePaint(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaPicture *m = CPictureCheck(L, 1);
if (!m) return 0;
bool do_save_bg = true;
if (!tableLookup(L, "do_save_bg", do_save_bg))
{
std::string tmp = "true";
if (tableLookup(L, "do_save_bg", tmp))
paramBoolDeprecated(L, tmp.c_str());
do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes");
}
m->cp->paint(do_save_bg);
return 0;
}
int CLuaInstance::CPictureHide(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaPicture *m = CPictureCheck(L, 1);
if (!m) return 0;
bool no_restore = false;
if (!tableLookup(L, "no_restore", no_restore))
{
std::string tmp = "false";
if (tableLookup(L, "no_restore", tmp))
paramBoolDeprecated(L, tmp.c_str());
no_restore = (tmp == "true" || tmp == "1" || tmp == "yes");
}
if (m->parent) {
m->cp->setPicture("");
m->cp->paint();
} else
m->cp->hide(no_restore);
return 0;
}
int CLuaInstance::CPictureSetPicture(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaPicture *m = CPictureCheck(L, 1);
if (!m) return 0;
std::string image_name = "";
tableLookup(L, "image", image_name);
m->cp->setPicture(image_name);
return 0;
}
int CLuaInstance::CPictureSetCenterPos(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaPicture *m = CPictureCheck(L, 1);
if (!m) return 0;
lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y;
tableLookup(L, "along_mode", tmp_along_mode);
if(tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y)
along_mode=tmp_along_mode;
m->cp->setCenterPos(along_mode);
return 0;
}
int CLuaInstance::CPictureDelete(lua_State *L)
{
LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L));
CLuaPicture *m = CPictureCheck(L, 1);
if (!m) return 0;
delete m;
return 0;
}
// --------------------------------------------------------------------------------
int CLuaInstance::checkVersion(lua_State *L)
{
int numargs = lua_gettop(L);