From da71f4cbbc3af79a4b6d822ad2543677e044d9a0 Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 11 Sep 2017 07:34:49 +0200 Subject: [PATCH] Make Horus widgets 'shadow' effect an option (#5203) * Add shadows to c++ widgets * Add BOOL zone option to Horus LUA * LUA widgets too --- radio/sdcard/horus/WIDGETS/BattCheck/main.lua | 45 +++++++++++-------- radio/sdcard/horus/WIDGETS/Counter/main.lua | 9 +++- radio/src/gui/480x272/widgets/text.cpp | 4 ++ radio/src/gui/480x272/widgets/value.cpp | 15 ++++--- radio/src/lua/api_general.cpp | 1 + 5 files changed, 47 insertions(+), 27 deletions(-) diff --git a/radio/sdcard/horus/WIDGETS/BattCheck/main.lua b/radio/sdcard/horus/WIDGETS/BattCheck/main.lua index bae83ac51..35605ccf8 100755 --- a/radio/sdcard/horus/WIDGETS/BattCheck/main.lua +++ b/radio/sdcard/horus/WIDGETS/BattCheck/main.lua @@ -16,10 +16,12 @@ ---- # # ---- ######################################################################### +local shadowed = 0 local options = { { "Sensor", SOURCE, 1 }, - { "Color", COLOR, WHITE } + { "Color", COLOR, WHITE }, + { "Shadow", BOOL, 0 } } -- This function is runned once at the creation of the widget @@ -182,8 +184,8 @@ local function zoneSmall(zone) if type(mySensor) == "table" then local myString = string.format("%2.1fV", getCellSum(mySensor)).." ("..getCellCount(mySensor).."S)" local percent = getCellPercent(getCellAvg(mySensor)) - lcd.drawText(zone.zone.x + zone.zone.w, zone.zone.y + 22, myString, RIGHT + SMLSIZE + CUSTOM_COLOR + SHADOWED) - lcd.drawText(zone.zone.x + zone.zone.w, zone.zone.y, percent.."%", RIGHT + MIDSIZE + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + zone.zone.w, zone.zone.y + 22, myString, RIGHT + SMLSIZE + CUSTOM_COLOR + shadowed) + lcd.drawText(zone.zone.x + zone.zone.w, zone.zone.y, percent.."%", RIGHT + MIDSIZE + CUSTOM_COLOR + shadowed) -- fils batt lcd.setColor(CUSTOM_COLOR, getPercentColor(percent)) lcd.drawGauge(zone.zone.x+2, zone.zone.y+2, 75, zone.zone.h - 4, percent, 100, CUSTOM_COLOR) @@ -195,7 +197,7 @@ local function zoneSmall(zone) lcd.drawRectangle(zone.zone.x + myBatt.x + i, zone.zone.y + myBatt.y, myBatt.segments_w, myBatt.h, CUSTOM_COLOR, 1) end else - lcd.drawText(zone.zone.x, zone.zone.y+10, "No FLVSS sensor data", LEFT + SMLSIZE + INVERS + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x, zone.zone.y+10, "No FLVSS sensor data", LEFT + SMLSIZE + INVERS + CUSTOM_COLOR + shadowed) end return end @@ -208,7 +210,7 @@ local function zoneMedium(zone) lcd.setColor(CUSTOM_COLOR, zone.options.Color) if type(mySensor) == "table" then local percent = getCellPercent(getCellAvg(mySensor)) - lcd.drawText(zone.zone.x + zone.zone.w, zone.zone.y+5, percent.."% ", RIGHT + MIDSIZE + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + zone.zone.w, zone.zone.y+5, percent.."% ", RIGHT + MIDSIZE + CUSTOM_COLOR + shadowed) -- fils batt lcd.setColor(CUSTOM_COLOR, getPercentColor(percent)) @@ -219,7 +221,7 @@ local function zoneMedium(zone) lcd.setColor(CUSTOM_COLOR, getRangeColor(mySensor[i], getCellMax(mySensor), getCellMax(mySensor) - 0.2)) lcd.drawFilledRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 58, 20, CUSTOM_COLOR) lcd.setColor(CUSTOM_COLOR, WHITE) - lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", mySensor[i]), CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", mySensor[i]), CUSTOM_COLOR + shadowed) lcd.drawRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 59, 20, CUSTOM_COLOR,1) end else @@ -229,7 +231,7 @@ local function zoneMedium(zone) lcd.setColor(CUSTOM_COLOR, WHITE) lcd.drawRectangle(zone.zone.x + myBatt.x , zone.zone.y + myBatt.y, myBatt.w, myBatt.h, CUSTOM_COLOR, 2) lcd.drawFilledRectangle(zone.zone.x + myBatt.x + myBatt.w, zone.zone.y + myBatt.h/2 - myBatt.cath_h/2, myBatt.cath_w, myBatt.cath_h, CUSTOM_COLOR) - lcd.drawText(zone.zone.x + myBatt.x + 5 , zone.zone.y + myBatt.y + 5, string.format("%2.1fV", getCellSum(mySensor)), LEFT + MIDSIZE + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + myBatt.x + 5 , zone.zone.y + myBatt.y + 5, string.format("%2.1fV", getCellSum(mySensor)), LEFT + MIDSIZE + CUSTOM_COLOR + shadowed) --for i=1, myBatt.w - myBatt.segments_w, myBatt.segments_w do -- lcd.drawRectangle(zone.zone.x + myBatt.x + i, zone.zone.y + myBatt.y, myBatt.segments_w, myBatt.h, CUSTOM_COLOR, 1) --end @@ -244,9 +246,9 @@ local function zoneLarge(zone) lcd.setColor(CUSTOM_COLOR, zone.options.Color) if type(mySensor) == "table" then local percent = getCellPercent(getCellAvg(mySensor)) - lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y+15, percent.."%", RIGHT + DBLSIZE + CUSTOM_COLOR + SHADOWED) - lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y+44, string.format("%2.1fV", getCellSum(mySensor)), RIGHT + MIDSIZE + CUSTOM_COLOR + SHADOWED) - lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y+65, getCellCount(mySensor).."S", RIGHT + MIDSIZE + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y+15, percent.."%", RIGHT + DBLSIZE + CUSTOM_COLOR + shadowed) + lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y+44, string.format("%2.1fV", getCellSum(mySensor)), RIGHT + MIDSIZE + CUSTOM_COLOR + shadowed) + lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y+65, getCellCount(mySensor).."S", RIGHT + MIDSIZE + CUSTOM_COLOR + shadowed) -- fils batt lcd.setColor(CUSTOM_COLOR, getPercentColor(percent)) lcd.drawFilledRectangle(zone.zone.x + myBatt.x, zone.zone.y + myBatt.y + myBatt.h + myBatt.cath_h - math.floor(percent/100 * myBatt.h), myBatt.w, math.floor(percent/100 * myBatt.h), CUSTOM_COLOR) @@ -256,11 +258,11 @@ local function zoneLarge(zone) lcd.setColor(CUSTOM_COLOR, getRangeColor(mySensor[i], getCellMax(mySensor), getCellMax(mySensor) - 0.2)) lcd.drawFilledRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 58, 20, CUSTOM_COLOR) lcd.setColor(CUSTOM_COLOR, WHITE) - lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", mySensor[i]), CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", mySensor[i]), CUSTOM_COLOR + shadowed) lcd.drawRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 59, 20, CUSTOM_COLOR, 1) end else - lcd.drawText(zone.zone.x+5, zone.zone.y, "No FLVSS sensor data", LEFT + SMLSIZE + INVERS + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x+5, zone.zone.y, "No FLVSS sensor data", LEFT + SMLSIZE + INVERS + CUSTOM_COLOR + shadowed) end -- draws bat lcd.setColor(CUSTOM_COLOR, WHITE) @@ -285,16 +287,16 @@ local function zoneXLarge(zone) lcd.drawFilledRectangle(zone.zone.x + myBatt.x, zone.zone.y + myBatt.y + myBatt.h + myBatt.cath_h - math.floor(percent/100 * myBatt.h), myBatt.w, math.floor(percent/100 * myBatt.h), CUSTOM_COLOR) -- draw right text section lcd.setColor(CUSTOM_COLOR, zone.options.Color) - lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y + myBatt.y, percent.."%", RIGHT + DBLSIZE + CUSTOM_COLOR + SHADOWED) - lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y + myBatt.y + 63, string.format("%2.1fV", getCellSum(mySensor)), RIGHT + MIDSIZE + CUSTOM_COLOR + SHADOWED) - lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y + myBatt.y + 105, getCellCount(mySensor).."S", RIGHT + MIDSIZE + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y + myBatt.y, percent.."%", RIGHT + DBLSIZE + CUSTOM_COLOR + shadowed) + lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y + myBatt.y + 63, string.format("%2.1fV", getCellSum(mySensor)), RIGHT + MIDSIZE + CUSTOM_COLOR + shadowed) + lcd.drawText(zone.zone.x+zone.zone.w, zone.zone.y + myBatt.y + 105, getCellCount(mySensor).."S", RIGHT + MIDSIZE + CUSTOM_COLOR + shadowed) -- draw cells local pos = {{x=111, y=38}, {x=164, y=38}, {x=217, y=38}, {x=111, y=57}, {x=164, y=57}, {x=217, y=57}} for i=1, getCellCount(mySensor), 1 do lcd.setColor(CUSTOM_COLOR, getRangeColor(mySensor[i], getCellMax(mySensor), getCellMax(mySensor) - 0.2)) lcd.drawFilledRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 53, 20, CUSTOM_COLOR) lcd.setColor(CUSTOM_COLOR, WHITE) - lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", mySensor[i]), CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", mySensor[i]), CUSTOM_COLOR + shadowed) lcd.drawRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 54, 20, CUSTOM_COLOR, 1) end -- draw cells for lowest cells @@ -304,7 +306,7 @@ local function zoneXLarge(zone) lcd.drawFilledRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 53, 20, CUSTOM_COLOR) lcd.setColor(CUSTOM_COLOR, WHITE) lcd.drawRectangle(zone.zone.x + pos[i].x, zone.zone.y + pos[i].y, 54, 20, CUSTOM_COLOR, 1) - lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", histCellData[i]), CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + pos[i].x+10, zone.zone.y + pos[i].y, string.format("%.2f", histCellData[i]), CUSTOM_COLOR + shadowed) end else lcd.drawText(zone.zone.x+5, zone.zone.y, "No FLVSS sensor data", LEFT + SMLSIZE + INVERS + CUSTOM_COLOR) @@ -318,9 +320,9 @@ local function zoneXLarge(zone) end -- draw middle rectangles lcd.drawRectangle(zone.zone.x + 110, zone.zone.y + 38, 161, 40, CUSTOM_COLOR, 1) - lcd.drawText(zone.zone.x + 270, zone.zone.y + 21, "Live data", RIGHT + SMLSIZE + INVERS + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + 270, zone.zone.y + 21, "Live data", RIGHT + SMLSIZE + INVERS + CUSTOM_COLOR + shadowed) lcd.drawRectangle(zone.zone.x + 110, zone.zone.y + 110, 161, 40, CUSTOM_COLOR, 1) - lcd.drawText(zone.zone.x + 270, zone.zone.y + 93, "Lowest data", RIGHT + SMLSIZE + INVERS + CUSTOM_COLOR + SHADOWED) + lcd.drawText(zone.zone.x + 270, zone.zone.y + 93, "Lowest data", RIGHT + SMLSIZE + INVERS + CUSTOM_COLOR + shadowed) return end @@ -331,6 +333,11 @@ local function background(myZone) end function refresh(myZone) + if myZone.options.Shadow == 1 then + shadowed = SHADOWED + else + shadowed = 0 + end if myZone.options.Sensor == 1 then lcd.drawText(myZone.zone.x+2, myZone.zone.y+2, "Not configured", LEFT + SMLSIZE + CUSTOM_COLOR) lcd.drawText(myZone.zone.x+2, myZone.zone.y+20, "Requires FLVSS sensor", LEFT + SMLSIZE + INVERS + CUSTOM_COLOR) diff --git a/radio/sdcard/horus/WIDGETS/Counter/main.lua b/radio/sdcard/horus/WIDGETS/Counter/main.lua index 1a68badcf..49c89962e 100644 --- a/radio/sdcard/horus/WIDGETS/Counter/main.lua +++ b/radio/sdcard/horus/WIDGETS/Counter/main.lua @@ -17,7 +17,8 @@ local options = { { "Option1", SOURCE, 1 }, { "Option2", VALUE, 1000 }, - { "Option3", COLOR, RED } + { "Option3", COLOR, RED }, + { "Shadow", BOOL, 0 } } local function create(zone, options) @@ -36,7 +37,11 @@ end function refresh(pie) pie.counter = pie.counter + 1 - lcd.drawNumber(pie.zone.x, pie.zone.y, pie.counter, LEFT + DBLSIZE + TEXT_COLOR); + if pie.options.Shadow == 1 then + lcd.drawNumber(pie.zone.x, pie.zone.y, pie.counter, LEFT + DBLSIZE + TEXT_COLOR); + else + lcd.drawNumber(pie.zone.x, pie.zone.y, pie.counter, LEFT + DBLSIZE + TEXT_COLOR + SHADOWED); + end end return { name="Counter", options=options, create=create, update=update, refresh=refresh, background=background } diff --git a/radio/src/gui/480x272/widgets/text.cpp b/radio/src/gui/480x272/widgets/text.cpp index 19d6ef039..30d593be6 100644 --- a/radio/src/gui/480x272/widgets/text.cpp +++ b/radio/src/gui/480x272/widgets/text.cpp @@ -39,6 +39,7 @@ const ZoneOption TextWidget::options[] = { { "Text", ZoneOption::String, OPTION_VALUE_STRING(TEXT_WIDGET_DEFAULT_LABEL) }, { "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) }, { "Size", ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(0) }, + { "Shadow", ZoneOption::Bool, OPTION_VALUE_BOOL(false) }, { NULL, ZoneOption::Bool } }; @@ -46,6 +47,9 @@ void TextWidget::refresh() { lcdSetColor(persistentData->options[1].unsignedValue); LcdFlags fontsize = FONTSIZE(persistentData->options[2].unsignedValue << 8); + if(persistentData->options[3].boolValue) { + lcdDrawSizedText(zone.x+1, zone.y+1, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|BLACK); + } lcdDrawSizedText(zone.x, zone.y, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|CUSTOM_COLOR); } diff --git a/radio/src/gui/480x272/widgets/value.cpp b/radio/src/gui/480x272/widgets/value.cpp index ca0beb555..2a36ba7f3 100644 --- a/radio/src/gui/480x272/widgets/value.cpp +++ b/radio/src/gui/480x272/widgets/value.cpp @@ -36,6 +36,7 @@ class ValueWidget: public Widget const ZoneOption ValueWidget::options[] = { { "Source", ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_Rud) }, { "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(WHITE) }, + { "Shadow", ZoneOption::Bool, OPTION_VALUE_BOOL(false) }, { NULL, ZoneOption::Bool } }; @@ -45,12 +46,12 @@ void ValueWidget::refresh() mixsrc_t field = persistentData->options[0].unsignedValue; lcdSetColor(persistentData->options[1].unsignedValue); - + int x = zone.x; int y = zone.y; - + // TRACE("w=%d, h=%d", zone.w, zone.h); - + // lcdDrawFilledRect(zone.x, zone.y, zone.w, zone.h, SOLID, MAINVIEW_PANES_COLOR | OPACITY(5)); int xValue, yValue, xLabel, yLabel; @@ -111,11 +112,13 @@ void ValueWidget::refresh() } } - drawSource(xLabel + 1, yLabel + 1, field, attrLabel|BLACK); + if(persistentData->options[2].boolValue) { + drawSource(xLabel + 1, yLabel + 1, field, attrLabel|BLACK); + drawSourceValue(xValue + 1, yValue + 1, field, attrValue|BLACK); + } drawSource(xLabel, yLabel, field, attrLabel|CUSTOM_COLOR); - drawSourceValue(xValue + 1, yValue + 1, field, attrValue|BLACK); drawSourceValue(xValue, yValue, field, attrValue|CUSTOM_COLOR); - + } BaseWidgetFactory ValueWidget("Value", ValueWidget::options); diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 265112ca0..9c1ebd650 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -1240,6 +1240,7 @@ const luaR_value_entry opentxConstants[] = { #if defined(COLORLCD) { "SHADOWED", SHADOWED }, { "COLOR", ZoneOption::Color }, + { "BOOL", ZoneOption::Bool }, { "CUSTOM_COLOR", CUSTOM_COLOR }, { "TEXT_COLOR", TEXT_COLOR }, { "TEXT_BGCOLOR", TEXT_BGCOLOR },