1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-25 09:15:21 +03:00

Make Horus widgets 'shadow' effect an option (#5203)

* Add shadows to c++ widgets

* Add BOOL zone option to Horus LUA

* LUA widgets too
This commit is contained in:
3djc 2017-09-11 07:34:49 +02:00 committed by Bertrand Songis
parent 093034f9e7
commit da71f4cbbc
5 changed files with 47 additions and 27 deletions

View file

@ -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)

View file

@ -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
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 }

View file

@ -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);
}

View file

@ -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 }
};
@ -111,9 +112,11 @@ void ValueWidget::refresh()
}
}
if(persistentData->options[2].boolValue) {
drawSource(xLabel + 1, yLabel + 1, field, attrLabel|BLACK);
drawSource(xLabel, yLabel, field, attrLabel|CUSTOM_COLOR);
drawSourceValue(xValue + 1, yValue + 1, field, attrValue|BLACK);
}
drawSource(xLabel, yLabel, field, attrLabel|CUSTOM_COLOR);
drawSourceValue(xValue, yValue, field, attrValue|CUSTOM_COLOR);
}

View file

@ -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 },