1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 06:15:10 +03:00

[Horus] background function added to widgets

This commit is contained in:
Bertrand Songis 2016-05-18 18:49:06 +02:00
parent 1da69e4066
commit 633af68fa9
4 changed files with 46 additions and 6 deletions

View file

@ -182,8 +182,13 @@ bool menuMainView(evt_t event)
break; break;
} }
if (customScreens[g_eeGeneral.view]) { for (uint8_t i=0; i<MAX_CUSTOM_SCREENS; i++) {
customScreens[g_eeGeneral.view]->refresh(); if (customScreens[i]) {
if (i == g_eeGeneral.view)
customScreens[i]->refresh();
else
customScreens[i]->background();
}
} }
return true; return true;

View file

@ -108,6 +108,10 @@ class Widget
virtual void refresh() = 0; virtual void refresh() = 0;
virtual void background()
{
}
protected: protected:
const WidgetFactory * factory; const WidgetFactory * factory;
Zone zone; Zone zone;

View file

@ -131,6 +131,17 @@ class WidgetsContainer: public WidgetsContainerInterface
} }
} }
virtual void background()
{
if (widgets) {
for (int i=0; i<N; i++) {
if (widgets[i]) {
widgets[i]->background();
}
}
}
}
protected: protected:
PersistentData * persistentData; PersistentData * persistentData;
}; };

View file

@ -911,6 +911,8 @@ class LuaWidget: public Widget
virtual void refresh(); virtual void refresh();
virtual void background();
protected: protected:
int widgetData; int widgetData;
}; };
@ -931,7 +933,8 @@ class LuaWidgetFactory: public WidgetFactory
LuaWidgetFactory(const char * name, int widgetOptions, int createFunction): LuaWidgetFactory(const char * name, int widgetOptions, int createFunction):
WidgetFactory(name, createOptionsArray(widgetOptions)), WidgetFactory(name, createOptionsArray(widgetOptions)),
createFunction(createFunction), createFunction(createFunction),
refreshFunction(0) refreshFunction(0),
backgroundFunction(0)
{ {
} }
@ -967,6 +970,7 @@ class LuaWidgetFactory: public WidgetFactory
protected: protected:
int createFunction; int createFunction;
int refreshFunction; int refreshFunction;
int backgroundFunction;
}; };
void LuaWidget::refresh() void LuaWidget::refresh()
@ -980,10 +984,21 @@ void LuaWidget::refresh()
} }
} }
void LuaWidget::background()
{
SET_LUA_INSTRUCTIONS_COUNT(PERMANENT_SCRIPTS_MAX_INSTRUCTIONS);
LuaWidgetFactory * factory = (LuaWidgetFactory *)this->factory;
lua_rawgeti(L, LUA_REGISTRYINDEX, factory->backgroundFunction);
lua_rawgeti(L, LUA_REGISTRYINDEX, widgetData);
if (lua_pcall(L, 1, 0, 0) != 0) {
TRACE("Error in widget %s: %s", factory->getName(), lua_tostring(L, -1));
}
}
void luaLoadWidgetCallback() void luaLoadWidgetCallback()
{ {
const char * name=NULL; const char * name=NULL;
int widgetOptions=0, createFunction=0, refreshFunction=0; int widgetOptions=0, createFunction=0, refreshFunction=0, backgroundFunction=0;
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
@ -1004,11 +1019,16 @@ void luaLoadWidgetCallback()
refreshFunction = luaL_ref(L, LUA_REGISTRYINDEX); refreshFunction = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushnil(L); lua_pushnil(L);
} }
else if (!strcmp(key, "background")) {
backgroundFunction = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushnil(L);
}
} }
if (name && createFunction) { if (name && createFunction) {
LuaWidgetFactory * factory = new LuaWidgetFactory(name, widgetOptions, createFunction); LuaWidgetFactory * factory = new LuaWidgetFactory(name, widgetOptions, createFunction);
factory->refreshFunction = refreshFunction; factory->refreshFunction = refreshFunction;
factory->backgroundFunction = backgroundFunction;
} }
} }