From a3d9bff44e39c2336e83d0aeb4c0d8d7cab2f6c5 Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Fri, 21 Feb 2014 00:01:04 +0100 Subject: [PATCH] CLuaInstance: Add various CComponentsWindow fuctions - Added: color buttons for footer, header_height --- src/gui/luainstance.cpp | 50 ++++++++++++++++++++++++++++++++++++++--- src/gui/luainstance.h | 1 + 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index e6037f135..699b2ba21 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -1291,12 +1291,10 @@ void CLuaInstance::CWindowRegister(lua_State *L) { "new", CLuaInstance::CWindowNew }, { "paint", CLuaInstance::CWindowPaint }, { "hide", CLuaInstance::CWindowHide }, + { "header_height", CLuaInstance::CWindowGetHeaderHeight }, { "__gc", CLuaInstance::CWindowDelete }, { NULL, NULL } }; -#if 0 - { "exec", CLuaInstance::CWindowExec }, -#endif luaL_newmetatable(L, "cwindow"); luaL_setfuncs(L, meth, 0); @@ -1310,6 +1308,10 @@ int CLuaInstance::CWindowNew(lua_State *L) lua_assert(lua_istable(L,1)); std::string name, icon = std::string(NEUTRINO_ICON_INFO); + std::string btnRed = ""; + std::string btnGreen = ""; + std::string btnYellow = ""; + std::string btnBlue = ""; int x = 100, y = 100, dx = 450, dy = 250; tableLookup(L, "x", x); tableLookup(L, "y", y); @@ -1317,10 +1319,38 @@ int CLuaInstance::CWindowNew(lua_State *L) tableLookup(L, "dy", dy); tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name); tableLookup(L, "icon", icon); + tableLookup(L, "btnRed", btnRed); + tableLookup(L, "btnGreen", btnGreen); + tableLookup(L, "btnYellow", btnYellow); + tableLookup(L, "btnBlue", btnBlue); 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()); + + CComponentsFooter* footer = (*udata)->w->getFooterObject(); + if (footer) { + int btnCount = 0; + if (btnRed != "") btnCount++; + if (btnGreen != "") btnCount++; + if (btnYellow != "") btnCount++; + if (btnBlue != "") btnCount++; + if (btnCount) { + fb_pixel_t col = footer->getColorBody(); + int btnw = (dx-20) / btnCount; + int btnh = footer->getHeight(); + int start = 10; + if (btnRed != "") + footer->addCCItem(new CComponentsButtonRed(start, CC_CENTERED, btnw, btnh, btnRed, false , true, false, col, col)); + if (btnGreen != "") + footer->addCCItem(new CComponentsButtonGreen(start+=btnw, CC_CENTERED, btnw, btnh, btnGreen, false , true, false, col, col)); + if (btnYellow != "") + footer->addCCItem(new CComponentsButtonYellow(start+=btnw, CC_CENTERED, btnw, btnh, btnYellow, false , true, false, col, col)); + if (btnBlue != "") + footer->addCCItem(new CComponentsButtonBlue(start+=btnw, CC_CENTERED, btnw, btnh, btnBlue, false , true, false, col, col)); + } + } + luaL_getmetatable(L, "cwindow"); lua_setmetatable(L, -2); return 1; @@ -1361,6 +1391,20 @@ int CLuaInstance::CWindowHide(lua_State *L) return 0; } +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::CWindowDelete(lua_State *L) { CLuaCWindow *m = CWindowCheck(L, 1); diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 48c0afcfd..093fda100 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -198,6 +198,7 @@ private: static CLuaCWindow *CWindowCheck(lua_State *L, int n); static int CWindowPaint(lua_State *L); static int CWindowHide(lua_State *L); + static int CWindowGetHeaderHeight(lua_State *L); static int CWindowDelete(lua_State *L); static CLuaSignalBox *SignalBoxCheck(lua_State *L, int n);