CLuaInstance: Add script function saveScreen()/restoreScreen()

Example:
 local memID = n:saveScreen(x, y, w, h);
 ...
 ...
 n:restoreScreen(x, y, w, h, memID, delete);
 -- delete = true => delete screen buffer
 -- delete = false => don't delete screen buffer

 - Set Lua api version to 1.14


Origin commit data
------------------
Branch: ni/coolstream
Commit: 550cfc853d
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2015-11-27 (Fri, 27 Nov 2015)

Origin message was:
------------------
CLuaInstance: Add script function saveScreen()/restoreScreen()

 Example:
  local memID = n:saveScreen(x, y, w, h);
   ...
   ...
  n:restoreScreen(x, y, w, h, memID, delete);
   -- delete = true => delete screen buffer
   -- delete = false => don't delete screen buffer

 - Set Lua api version to 1.14


------------------
This commit was generated by Migit
This commit is contained in:
Michael Liebmann
2015-11-27 12:11:57 +01:00
parent 427d7ccc9c
commit be655e8b24
2 changed files with 86 additions and 1 deletions

View File

@@ -558,6 +558,9 @@ const luaL_Reg CLuaInstance::methods[] =
{ {
{ "GetRevision", CLuaInstance::GetRevision }, { "GetRevision", CLuaInstance::GetRevision },
{ "PaintBox", CLuaInstance::PaintBox }, { "PaintBox", CLuaInstance::PaintBox },
{ "saveScreen", CLuaInstance::saveScreen },
{ "restoreScreen", CLuaInstance::restoreScreen },
{ "deleteSavedScreen", CLuaInstance::deleteSavedScreen },
{ "RenderString", CLuaInstance::RenderString }, { "RenderString", CLuaInstance::RenderString },
{ "PaintIcon", CLuaInstance::PaintIcon }, { "PaintIcon", CLuaInstance::PaintIcon },
{ "GetInput", CLuaInstance::GetInput }, { "GetInput", CLuaInstance::GetInput },
@@ -662,6 +665,74 @@ int CLuaInstance::NewWindow(lua_State *L)
return 1; 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) int CLuaInstance::GetRevision(lua_State *L)
{ {
unsigned int ret = 0; unsigned int ret = 0;
@@ -1083,6 +1154,12 @@ int CLuaInstance::GCWindow(lua_State *L)
CLuaData *w = (CLuaData *)lua_unboxpointer(L, 1); CLuaData *w = (CLuaData *)lua_unboxpointer(L, 1);
if (w && w->fbwin) { 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(); w->fontmap.clear();
} }
CNeutrinoFonts::getInstance()->deleteDynFontExtAll(); CNeutrinoFonts::getInstance()->deleteDynFontExtAll();

View File

@@ -34,18 +34,23 @@ extern "C" {
#include <vector> #include <vector>
#define LUA_API_VERSION_MAJOR 1 #define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 13 #define LUA_API_VERSION_MINOR 14
typedef std::pair<lua_Integer, Font*> fontmap_pair_t; typedef std::pair<lua_Integer, Font*> fontmap_pair_t;
typedef std::map<lua_Integer, Font*> fontmap_t; typedef std::map<lua_Integer, Font*> fontmap_t;
typedef fontmap_t::iterator fontmap_iterator_t; typedef fontmap_t::iterator fontmap_iterator_t;
typedef std::pair<lua_Integer, fb_pixel_t*> screenmap_pair_t;
typedef std::map<lua_Integer, fb_pixel_t*> screenmap_t;
typedef screenmap_t::iterator screenmap_iterator_t;
/* this is stored as userdata in the lua_State */ /* this is stored as userdata in the lua_State */
struct CLuaData struct CLuaData
{ {
CFBWindow *fbwin; CFBWindow *fbwin;
CRCInput *rcinput; CRCInput *rcinput;
fontmap_t fontmap; fontmap_t fontmap;
screenmap_t screenmap;
}; };
struct CLuaMenuItem struct CLuaMenuItem
@@ -229,6 +234,9 @@ private:
static int GetRevision(lua_State *L); static int GetRevision(lua_State *L);
static int NewWindow(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 PaintBox(lua_State *L);
static int PaintIcon(lua_State *L); static int PaintIcon(lua_State *L);
static int RenderString(lua_State *L); static int RenderString(lua_State *L);