lua: add simple hint method

Origin commit data
------------------
Branch: ni/coolstream
Commit: d836ccebaf
Author: Thilo Graf <dbt@novatux.de>
Date: 2021-11-01 (Mon, 01 Nov 2021)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
2021-11-01 21:12:01 +01:00
committed by vanhofen
parent 2332d97adc
commit 0c7749b56b
4 changed files with 179 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ libneutrino_gui_lua_a_SOURCES = \
lua_configfile.cpp \
lua_curl.cpp \
lua_filehelpers.cpp \
lua_hint.cpp \
lua_hintbox.cpp \
lua_hourglass.cpp \
lua_menue.cpp \

128
src/gui/lua/lua_hint.cpp Normal file
View File

@@ -0,0 +1,128 @@
/*
* lua simple hint window
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <global.h>
#include <system/debug.h>
#include <neutrino.h>
#include "luainstance.h"
#include "lua_hint.h"
CLuaInstHint* CLuaInstHint::getInstance()
{
static CLuaInstHint* LuaInstHint = NULL;
if(!LuaInstHint)
LuaInstHint = new CLuaInstHint();
return LuaInstHint;
}
void CLuaInstHint::HintRegister(lua_State *L)
{
luaL_Reg meth[] = {
{ "new", CLuaInstHint::HintNew },
{ "paint", CLuaInstHint::HintPaint },
{ "hide", CLuaInstHint::HintHide },
{ "__gc", CLuaInstHint::HintDelete },
{ NULL, NULL }
};
luaL_newmetatable(L, "hint");
luaL_setfuncs(L, meth, 0);
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
lua_setglobal(L, "hint");
}
int CLuaInstHint::HintNew(lua_State *L)
{
lua_assert(lua_istable(L,1));
std::string text = "";
tableLookup(L, "text", text);
bool show_background = true;
if (!tableLookup(L, "show_background", show_background))
{
std::string tmp = "true";
if (tableLookup(L, "show_background", tmp))
paramBoolDeprecated(L, tmp.c_str());
show_background = (tmp == "true" || tmp == "1" || tmp == "yes");
}
CLuaHint **udata = (CLuaHint **) lua_newuserdata(L, sizeof(CLuaHint *));
*udata = new CLuaHint();
(*udata)->h = new CHint(text.c_str(), show_background);
luaL_getmetatable(L, "hint");
lua_setmetatable(L, -2);
return 1;
}
CLuaHint *CLuaInstHint::HintCheck(lua_State *L, int n)
{
return *(CLuaHint **) luaL_checkudata(L, n, "hint");
}
int CLuaInstHint::HintPaint(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaHint *D = HintCheck(L, 1);
if (!D) 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");
}
D->h->paint(do_save_bg);
return 0;
}
int CLuaInstHint::HintHide(lua_State *L)
{
lua_assert(lua_istable(L,1));
CLuaHint *D = HintCheck(L, 1);
if (!D) return 0;
bool tmp1 = false;
std::string tmp2 = "false";
if ((tableLookup(L, "no_restore", tmp1)) || (tableLookup(L, "no_restore", tmp2)))
obsoleteHideParameter(L);
D->h->hide();
return 0;
}
int CLuaInstHint::HintDelete(lua_State *L)
{
LUA_DEBUG("CLuaInstHint::%s %d\n", __func__, lua_gettop(L));
CLuaHint *D = HintCheck(L, 1);
if (!D) return 0;
delete D;
return 0;
}

48
src/gui/lua/lua_hint.h Normal file
View File

@@ -0,0 +1,48 @@
/*
* lua simple hint window
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LUAHINT_H_
#define _LUAHINT_H_
#include <gui/widget/hintbox.h>
class CLuaHint
{
public:
CHint *h;
CLuaHint() { h = NULL; }
~CLuaHint() { delete h; }
};
class CLuaInstHint
{
public:
CLuaInstHint() {};
~CLuaInstHint() {};
static CLuaInstHint* getInstance();
static void HintRegister(lua_State *L);
private:
static CLuaHint *HintCheck(lua_State *L, int n);
static int HintNew(lua_State *L);
static int HintPaint(lua_State *L);
static int HintHide(lua_State *L);
static int HintDelete(lua_State *L);
};
#endif //_LUAHINT_H_

View File

@@ -48,6 +48,7 @@
#include "lua_configfile.h"
#include "lua_curl.h"
#include "lua_filehelpers.h"
#include "lua_hint.h"
#include "lua_hintbox.h"
#include "lua_hourglass.h"
#include "lua_menue.h"
@@ -769,6 +770,7 @@ void LuaInstRegisterFunctions(lua_State *L, bool fromThreads/*=false*/)
CLuaInstConfigFile::getInstance()->LuaConfigFileRegister(L);
CLuaInstCurl::getInstance()->LuaCurlRegister(L);
CLuaInstFileHelpers::getInstance()->LuaFileHelpersRegister(L);
CLuaInstHint::getInstance()->HintRegister(L);
CLuaInstHintbox::getInstance()->HintboxRegister(L);
CLuaInstHourGlass::getInstance()->HourGlassRegister(L);
CLuaInstMenu::getInstance()->MenuRegister(L);