From 633af68fa9c1b4bd5f929dc22e2bc7c927a590ff Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 18 May 2016 18:49:06 +0200 Subject: [PATCH] [Horus] background function added to widgets --- radio/src/gui/horus/view_main.cpp | 9 +++++++-- radio/src/gui/horus/widget.h | 6 +++++- radio/src/gui/horus/widgets_container.h | 11 +++++++++++ radio/src/lua/interface.cpp | 26 ++++++++++++++++++++++--- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/radio/src/gui/horus/view_main.cpp b/radio/src/gui/horus/view_main.cpp index 96305b9cf..ddf7a61ab 100644 --- a/radio/src/gui/horus/view_main.cpp +++ b/radio/src/gui/horus/view_main.cpp @@ -182,8 +182,13 @@ bool menuMainView(evt_t event) break; } - if (customScreens[g_eeGeneral.view]) { - customScreens[g_eeGeneral.view]->refresh(); + for (uint8_t i=0; irefresh(); + else + customScreens[i]->background(); + } } return true; diff --git a/radio/src/gui/horus/widget.h b/radio/src/gui/horus/widget.h index e08c72a24..bc02c233a 100644 --- a/radio/src/gui/horus/widget.h +++ b/radio/src/gui/horus/widget.h @@ -90,7 +90,7 @@ class Widget { } - virtual void update() const + virtual void update() const { } @@ -108,6 +108,10 @@ class Widget virtual void refresh() = 0; + virtual void background() + { + } + protected: const WidgetFactory * factory; Zone zone; diff --git a/radio/src/gui/horus/widgets_container.h b/radio/src/gui/horus/widgets_container.h index ca274df94..ea7648fd0 100644 --- a/radio/src/gui/horus/widgets_container.h +++ b/radio/src/gui/horus/widgets_container.h @@ -131,6 +131,17 @@ class WidgetsContainer: public WidgetsContainerInterface } } + virtual void background() + { + if (widgets) { + for (int i=0; ibackground(); + } + } + } + } + protected: PersistentData * persistentData; }; diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index 4ef3485a7..5ca93650e 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -911,6 +911,8 @@ class LuaWidget: public Widget virtual void refresh(); + virtual void background(); + protected: int widgetData; }; @@ -931,7 +933,8 @@ class LuaWidgetFactory: public WidgetFactory LuaWidgetFactory(const char * name, int widgetOptions, int createFunction): WidgetFactory(name, createOptionsArray(widgetOptions)), createFunction(createFunction), - refreshFunction(0) + refreshFunction(0), + backgroundFunction(0) { } @@ -967,6 +970,7 @@ class LuaWidgetFactory: public WidgetFactory protected: int createFunction; int refreshFunction; + int backgroundFunction; }; 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() { 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); @@ -1004,11 +1019,16 @@ void luaLoadWidgetCallback() refreshFunction = luaL_ref(L, LUA_REGISTRYINDEX); lua_pushnil(L); } + else if (!strcmp(key, "background")) { + backgroundFunction = luaL_ref(L, LUA_REGISTRYINDEX); + lua_pushnil(L); + } } if (name && createFunction) { LuaWidgetFactory * factory = new LuaWidgetFactory(name, widgetOptions, createFunction); factory->refreshFunction = refreshFunction; + factory->backgroundFunction = backgroundFunction; } }