diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index a6d0ef62c..61a378d15 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -558,6 +558,9 @@ const luaL_Reg CLuaInstance::methods[] = { { "GetRevision", CLuaInstance::GetRevision }, { "PaintBox", CLuaInstance::PaintBox }, + { "saveScreen", CLuaInstance::saveScreen }, + { "restoreScreen", CLuaInstance::restoreScreen }, + { "deleteSavedScreen", CLuaInstance::deleteSavedScreen }, { "RenderString", CLuaInstance::RenderString }, { "PaintIcon", CLuaInstance::PaintIcon }, { "GetInput", CLuaInstance::GetInput }, @@ -662,6 +665,74 @@ int CLuaInstance::NewWindow(lua_State *L) return 1; } +int CLuaInstance::saveScreen(lua_State *L) +{ + int x, y, w, h; + fb_pixel_t* buf; + CLuaData *W = CheckData(L, 1); + if (!W || !W->fbwin) + return 0; + x = luaL_checkint(L, 2); + y = luaL_checkint(L, 3); + w = luaL_checkint(L, 4); + h = luaL_checkint(L, 5); + + buf = W->fbwin->saveScreen(x, y, w, h); + + lua_Integer id = W->screenmap.size() + 1; + W->screenmap.insert(screenmap_pair_t(id, buf)); + lua_pushinteger(L, id); + return 1; +} + +int CLuaInstance::restoreScreen(lua_State *L) +{ + int x, y, w, h, id; + fb_pixel_t* buf = NULL; + bool del; + CLuaData *W = CheckData(L, 1); + if (!W || !W->fbwin) + return 0; + x = luaL_checkint(L, 2); + y = luaL_checkint(L, 3); + w = luaL_checkint(L, 4); + h = luaL_checkint(L, 5); + id = luaL_checkint(L, 6); + del = _luaL_checkbool(L, 7); + + for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it) { + if (it->first == id) { + buf = it->second; + if (del) + it->second = NULL; + break; + } + } + if (buf != NULL) + W->fbwin->restoreScreen(x, y, w, h, buf, del); + return 0; +} + +int CLuaInstance::deleteSavedScreen(lua_State *L) +{ + int id; + CLuaData *W = CheckData(L, 1); + if (!W || !W->fbwin) + return 0; + id = luaL_checkint(L, 2); + + for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it) { + if (it->first == id) { + if (it->second != NULL) { + delete[] it->second; + it->second = NULL; + } + break; + } + } + return 0; +} + int CLuaInstance::GetRevision(lua_State *L) { unsigned int ret = 0; @@ -1083,6 +1154,12 @@ int CLuaInstance::GCWindow(lua_State *L) CLuaData *w = (CLuaData *)lua_unboxpointer(L, 1); if (w && w->fbwin) { + for (screenmap_iterator_t it = w->screenmap.begin(); it != w->screenmap.end(); ++it) { + if (it->second != NULL) + delete[] it->second; + } + DBG1("CLuaInstance::%s delete screenmap\n", __func__); + w->screenmap.clear(); w->fontmap.clear(); } CNeutrinoFonts::getInstance()->deleteDynFontExtAll(); diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index c0f3b3780..f30fd285d 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -34,18 +34,23 @@ extern "C" { #include #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 13 +#define LUA_API_VERSION_MINOR 14 typedef std::pair fontmap_pair_t; typedef std::map fontmap_t; typedef fontmap_t::iterator fontmap_iterator_t; +typedef std::pair screenmap_pair_t; +typedef std::map screenmap_t; +typedef screenmap_t::iterator screenmap_iterator_t; + /* this is stored as userdata in the lua_State */ struct CLuaData { CFBWindow *fbwin; CRCInput *rcinput; fontmap_t fontmap; + screenmap_t screenmap; }; struct CLuaMenuItem @@ -229,6 +234,9 @@ private: static int GetRevision(lua_State *L); static int NewWindow(lua_State *L); + static int saveScreen(lua_State *L); + static int restoreScreen(lua_State *L); + static int deleteSavedScreen(lua_State *L); static int PaintBox(lua_State *L); static int PaintIcon(lua_State *L); static int RenderString(lua_State *L);