Color options for Lua widget get translated to Lua color flags

To support new color encoding in Lua widgets
This commit is contained in:
jfrickmann
2021-08-27 22:21:37 -04:00
parent 8becbfcb49
commit 1af65969ed
3 changed files with 14 additions and 4 deletions
+11 -3
View File
@@ -177,12 +177,16 @@ ZoneOption * createOptionsArray(int reference, uint8_t maxOptions)
// TRACE("default signed = %d", option->deflt.signedValue);
}
else if (option->type == ZoneOption::Source ||
option->type == ZoneOption::TextSize ||
option->type == ZoneOption::Color) {
option->type == ZoneOption::TextSize) {
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
option->deflt.unsignedValue = lua_tounsigned(lsWidgets, -1);
// TRACE("default unsigned = %u", option->deflt.unsignedValue);
}
else if (option->type == ZoneOption::Color) {
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
option->deflt.unsignedValue = COLOR_VAL(flagsRGB(lua_tounsigned(lsWidgets, -1)));
// TRACE("default unsigned = %u", option->deflt.unsignedValue);
}
else if (option->type == ZoneOption::Bool) {
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
option->deflt.boolValue = (lua_tounsigned(lsWidgets, -1) != 0);
@@ -418,7 +422,11 @@ void LuaWidget::update()
lua_newtable(lsWidgets);
int i = 0;
for (const ZoneOption * option = getOptions(); option->name; option++, i++) {
l_pushtableint(option->name, persistentData->options[i].value.signedValue);
int32_t value = persistentData->options[i].value.signedValue;
if (option->type == ZoneOption::Color)
l_pushtableint(option->name, COLOR2FLAGS(value) | RGB_FLAG);
else
l_pushtableint(option->name, value);
}
if (lua_pcall(lsWidgets, 2, 0, 0) != 0) {