diff --git a/src/gui/lua/Makefile.am b/src/gui/lua/Makefile.am index e28802597..741ab33cb 100644 --- a/src/gui/lua/Makefile.am +++ b/src/gui/lua/Makefile.am @@ -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 \ diff --git a/src/gui/lua/lua_hint.cpp b/src/gui/lua/lua_hint.cpp new file mode 100644 index 000000000..185efedb1 --- /dev/null +++ b/src/gui/lua/lua_hint.cpp @@ -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 . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#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; +} diff --git a/src/gui/lua/lua_hint.h b/src/gui/lua/lua_hint.h new file mode 100644 index 000000000..7c5cd14e8 --- /dev/null +++ b/src/gui/lua/lua_hint.h @@ -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 . + */ + +#ifndef _LUAHINT_H_ +#define _LUAHINT_H_ + +#include + +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_ diff --git a/src/gui/lua/luainstance.cpp b/src/gui/lua/luainstance.cpp index ff1f658f1..894940d4c 100644 --- a/src/gui/lua/luainstance.cpp +++ b/src/gui/lua/luainstance.cpp @@ -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);