From 49b91431fede4b648a589ef0f47cd4bb51a65823 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Wed, 1 Sep 2021 20:44:50 +1000 Subject: [PATCH 1/3] Set more sensible default colors for output widget And also allow colors to be customised! Fixes #663 --- radio/src/gui/colorlcd/widgets/outputs.cpp | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/radio/src/gui/colorlcd/widgets/outputs.cpp b/radio/src/gui/colorlcd/widgets/outputs.cpp index 27a8ac497..bfdd0c777 100644 --- a/radio/src/gui/colorlcd/widgets/outputs.cpp +++ b/radio/src/gui/colorlcd/widgets/outputs.cpp @@ -45,7 +45,7 @@ class OutputsWidget: public Widget oneColumn(dc); } - uint8_t drawChannels(BitmapBuffer * dc, const uint16_t & x, const uint16_t & y, const uint16_t & w, const uint16_t & h, const uint8_t & firstChan, const bool & bg_shown, const uint16_t & bg_color) + uint8_t drawChannels(BitmapBuffer * dc, const uint16_t & x, const uint16_t & y, const uint16_t & w, const uint16_t & h, const uint8_t & firstChan, const bool & bg_shown, const uint16_t & bg_color, const uint16_t & txt_color, const uint16_t & bar_color) { const uint8_t numChan = h / ROW_HEIGHT; const uint8_t lastChan = firstChan + numChan; @@ -55,6 +55,9 @@ class OutputsWidget: public Widget const uint16_t barLft = x + RECT_BORDER; const uint16_t barMid = barLft + barW / 2; + LcdFlags barColor = COLOR2FLAGS(bar_color); + LcdFlags txtColor = COLOR2FLAGS(txt_color); + for (uint8_t curChan = firstChan; curChan < lastChan && curChan <= MAX_OUTPUT_CHANNELS; curChan++) { const int16_t chanVal = calcRESXto100(channelOutputs[curChan-1]); const uint16_t rowTop = y + (curChan - firstChan) * rowH; @@ -66,16 +69,16 @@ class OutputsWidget: public Widget dc->drawSolidFilledRect(barLft, barTop, barW , barH, CUSTOM_COLOR); } if (fillW) - dc->drawSolidFilledRect((chanVal > 0 ? barMid : barMid - fillW), barTop, fillW, barH, COLOR_THEME_SECONDARY1); + dc->drawSolidFilledRect((chanVal > 0 ? barMid : barMid - fillW), barTop, fillW, barH, barColor); lcd->drawSolidVerticalLine(barMid, barTop, barH, COLOR_THEME_SECONDARY1); dc->drawRect(x, rowTop, w, rowH + 1); - dc->drawNumber(x + barW - 10, barTop, chanVal, FONT(XS) | COLOR_THEME_SECONDARY1 | RIGHT, 0, nullptr, "%"); + dc->drawNumber(x + barW - 10, barTop, chanVal, FONT(XS) | txtColor | RIGHT, 0, nullptr, "%"); if (g_model.limitData[curChan - 1].name[0] != 0) { - dc->drawNumber(barLft + 1, barTop, curChan, FONT(XS) | COLOR_THEME_SECONDARY1 | LEFT | LEADING0, 2); - dc->drawSizedText(barLft + 23, barTop, g_model.limitData[curChan - 1].name, sizeof(g_model.limitData[curChan - 1].name), FONT(XS) | COLOR_THEME_SECONDARY1 | LEFT); + dc->drawNumber(barLft + 1, barTop, curChan, FONT(XS) | txtColor | LEFT | LEADING0, 2); + dc->drawSizedText(barLft + 23, barTop, g_model.limitData[curChan - 1].name, sizeof(g_model.limitData[curChan - 1].name), FONT(XS) | txtColor | LEFT); } else { - drawSource(dc, barLft + 1, barTop, MIXSRC_FIRST_CH+curChan-1, FONT(XS) | COLOR_THEME_SECONDARY1 | LEFT); + drawSource(dc, barLft + 1, barTop, MIXSRC_FIRST_CH+curChan-1, FONT(XS) | txtColor | LEFT); } } return lastChan - 1; @@ -86,11 +89,15 @@ class OutputsWidget: public Widget uint8_t endColumn = drawChannels(dc, 0, 0, (width() / 2) - 1, height(), persistentData->options[0].value.unsignedValue, persistentData->options[1].value.boolValue, - persistentData->options[2].value.unsignedValue); + persistentData->options[2].value.unsignedValue, + persistentData->options[3].value.unsignedValue, + persistentData->options[4].value.unsignedValue); drawChannels(dc, width() / 2, 0, (width() / 2) - 1, height(), endColumn + 1, persistentData->options[1].value.boolValue, - persistentData->options[2].value.unsignedValue); + persistentData->options[2].value.unsignedValue, + persistentData->options[3].value.unsignedValue, + persistentData->options[4].value.unsignedValue); } void oneColumn(BitmapBuffer * dc) @@ -98,7 +105,9 @@ class OutputsWidget: public Widget drawChannels(dc, 0, 0, width(), height(), persistentData->options[0].value.unsignedValue, persistentData->options[1].value.boolValue, - persistentData->options[2].value.unsignedValue); + persistentData->options[2].value.unsignedValue, + persistentData->options[3].value.unsignedValue, + persistentData->options[4].value.unsignedValue); } void checkEvents() override @@ -127,6 +136,8 @@ const ZoneOption OutputsWidget::options[] = { { STR_FIRST_CHANNEL, ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32) }, { STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false) }, { STR_BG_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(LIGHTGREY) }, + { STR_TEXT_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY1>>16) }, + { STR_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1>>16) }, { nullptr, ZoneOption::Bool } }; From d4628ca78d3775108d54bd6adb4508d76287c1c7 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Wed, 8 Sep 2021 21:37:01 +1000 Subject: [PATCH 2/3] Update copyright header --- radio/src/gui/colorlcd/widgets/outputs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/widgets/outputs.cpp b/radio/src/gui/colorlcd/widgets/outputs.cpp index bfdd0c777..53417c992 100644 --- a/radio/src/gui/colorlcd/widgets/outputs.cpp +++ b/radio/src/gui/colorlcd/widgets/outputs.cpp @@ -1,7 +1,8 @@ /* - * Copyright (C) OpenTX + * Copyright (C) EdgeTX * * Based on code named + * opentx - https://github.com/opentx/opentx * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x From 0420d2519e07ab2bc157ed9c7d2d815d0fd96b69 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Wed, 8 Sep 2021 21:50:11 +1000 Subject: [PATCH 3/3] Apply code formatter --- radio/src/gui/colorlcd/widgets/outputs.cpp | 216 +++++++++++---------- 1 file changed, 117 insertions(+), 99 deletions(-) diff --git a/radio/src/gui/colorlcd/widgets/outputs.cpp b/radio/src/gui/colorlcd/widgets/outputs.cpp index 53417c992..683200e7b 100644 --- a/radio/src/gui/colorlcd/widgets/outputs.cpp +++ b/radio/src/gui/colorlcd/widgets/outputs.cpp @@ -22,124 +22,142 @@ #include "opentx.h" #include "widgets_container_impl.h" -#define RECT_BORDER 1 -#define ROW_HEIGHT 17 +#define RECT_BORDER 1 +#define ROW_HEIGHT 17 -#define VIEW_CHANNELS_LIMIT_PCT (g_model.extendedLimits ? LIMIT_EXT_PERCENT : 100) +#define VIEW_CHANNELS_LIMIT_PCT \ + (g_model.extendedLimits ? LIMIT_EXT_PERCENT : 100) -constexpr uint32_t OUTPUTS_REFRESH = 1000 / 5; // 5 Hz +constexpr uint32_t OUTPUTS_REFRESH = 1000 / 5; // 5 Hz - -class OutputsWidget: public Widget +class OutputsWidget : public Widget { - public: - OutputsWidget(const WidgetFactory * factory, FormGroup * parent, const rect_t & rect, Widget::PersistentData * persistentData): + public: + OutputsWidget(const WidgetFactory* factory, FormGroup* parent, + const rect_t& rect, Widget::PersistentData* persistentData) : Widget(factory, parent, rect, persistentData) - { - } + { + } - void refresh(BitmapBuffer * dc) override - { - if (width() > 300 && height() > 20) - twoColumns(dc); - else if (width() > 150 && height() > 20) - oneColumn(dc); - } + void refresh(BitmapBuffer* dc) override + { + if (width() > 300 && height() > 20) + twoColumns(dc); + else if (width() > 150 && height() > 20) + oneColumn(dc); + } - uint8_t drawChannels(BitmapBuffer * dc, const uint16_t & x, const uint16_t & y, const uint16_t & w, const uint16_t & h, const uint8_t & firstChan, const bool & bg_shown, const uint16_t & bg_color, const uint16_t & txt_color, const uint16_t & bar_color) - { - const uint8_t numChan = h / ROW_HEIGHT; - const uint8_t lastChan = firstChan + numChan; - const uint8_t rowH = (h - numChan * ROW_HEIGHT >= numChan ? ROW_HEIGHT + 1 : ROW_HEIGHT); - const uint16_t barW = w - RECT_BORDER * 2; - const uint8_t barH = rowH - RECT_BORDER; - const uint16_t barLft = x + RECT_BORDER; - const uint16_t barMid = barLft + barW / 2; + uint8_t drawChannels(BitmapBuffer* dc, const uint16_t& x, const uint16_t& y, + const uint16_t& w, const uint16_t& h, + const uint8_t& firstChan, const bool& bg_shown, + const uint16_t& bg_color, const uint16_t& txt_color, + const uint16_t& bar_color) + { + const uint8_t numChan = h / ROW_HEIGHT; + const uint8_t lastChan = firstChan + numChan; + const uint8_t rowH = + (h - numChan * ROW_HEIGHT >= numChan ? ROW_HEIGHT + 1 : ROW_HEIGHT); + const uint16_t barW = w - RECT_BORDER * 2; + const uint8_t barH = rowH - RECT_BORDER; + const uint16_t barLft = x + RECT_BORDER; + const uint16_t barMid = barLft + barW / 2; - LcdFlags barColor = COLOR2FLAGS(bar_color); - LcdFlags txtColor = COLOR2FLAGS(txt_color); + LcdFlags barColor = COLOR2FLAGS(bar_color); + LcdFlags txtColor = COLOR2FLAGS(txt_color); - for (uint8_t curChan = firstChan; curChan < lastChan && curChan <= MAX_OUTPUT_CHANNELS; curChan++) { - const int16_t chanVal = calcRESXto100(channelOutputs[curChan-1]); - const uint16_t rowTop = y + (curChan - firstChan) * rowH; - const uint16_t barTop = rowTop + RECT_BORDER; - const uint16_t fillW = divRoundClosest(barW * limit(0, abs(chanVal), VIEW_CHANNELS_LIMIT_PCT), VIEW_CHANNELS_LIMIT_PCT * 2); + for (uint8_t curChan = firstChan; + curChan < lastChan && curChan <= MAX_OUTPUT_CHANNELS; curChan++) { + const int16_t chanVal = calcRESXto100(channelOutputs[curChan - 1]); + const uint16_t rowTop = y + (curChan - firstChan) * rowH; + const uint16_t barTop = rowTop + RECT_BORDER; + const uint16_t fillW = divRoundClosest( + barW * limit(0, abs(chanVal), VIEW_CHANNELS_LIMIT_PCT), + VIEW_CHANNELS_LIMIT_PCT * 2); - if (bg_shown) { - lcdSetColor(bg_color); - dc->drawSolidFilledRect(barLft, barTop, barW , barH, CUSTOM_COLOR); - } - if (fillW) - dc->drawSolidFilledRect((chanVal > 0 ? barMid : barMid - fillW), barTop, fillW, barH, barColor); - lcd->drawSolidVerticalLine(barMid, barTop, barH, COLOR_THEME_SECONDARY1); - dc->drawRect(x, rowTop, w, rowH + 1); - dc->drawNumber(x + barW - 10, barTop, chanVal, FONT(XS) | txtColor | RIGHT, 0, nullptr, "%"); - if (g_model.limitData[curChan - 1].name[0] != 0) { - dc->drawNumber(barLft + 1, barTop, curChan, FONT(XS) | txtColor | LEFT | LEADING0, 2); - dc->drawSizedText(barLft + 23, barTop, g_model.limitData[curChan - 1].name, sizeof(g_model.limitData[curChan - 1].name), FONT(XS) | txtColor | LEFT); - } - else { - drawSource(dc, barLft + 1, barTop, MIXSRC_FIRST_CH+curChan-1, FONT(XS) | txtColor | LEFT); - } + if (bg_shown) { + lcdSetColor(bg_color); + dc->drawSolidFilledRect(barLft, barTop, barW, barH, CUSTOM_COLOR); } - return lastChan - 1; - } - - void twoColumns(BitmapBuffer * dc) - { - uint8_t endColumn = drawChannels(dc, 0, 0, (width() / 2) - 1, height(), - persistentData->options[0].value.unsignedValue, - persistentData->options[1].value.boolValue, - persistentData->options[2].value.unsignedValue, - persistentData->options[3].value.unsignedValue, - persistentData->options[4].value.unsignedValue); - - drawChannels(dc, width() / 2, 0, (width() / 2) - 1, height(), endColumn + 1, - persistentData->options[1].value.boolValue, - persistentData->options[2].value.unsignedValue, - persistentData->options[3].value.unsignedValue, - persistentData->options[4].value.unsignedValue); - } - - void oneColumn(BitmapBuffer * dc) - { - drawChannels(dc, 0, 0, width(), height(), - persistentData->options[0].value.unsignedValue, - persistentData->options[1].value.boolValue, - persistentData->options[2].value.unsignedValue, - persistentData->options[3].value.unsignedValue, - persistentData->options[4].value.unsignedValue); - } - - void checkEvents() override - { - Widget::checkEvents(); - - // Last time we refreshed the window - uint32_t now = RTOS_GET_MS(); - if (now - lastRefresh >= OUTPUTS_REFRESH) { - lastRefresh = now; - invalidate(); + if (fillW) + dc->drawSolidFilledRect((chanVal > 0 ? barMid : barMid - fillW), barTop, + fillW, barH, barColor); + lcd->drawSolidVerticalLine(barMid, barTop, barH, COLOR_THEME_SECONDARY1); + dc->drawRect(x, rowTop, w, rowH + 1); + dc->drawNumber(x + barW - 10, barTop, chanVal, + FONT(XS) | txtColor | RIGHT, 0, nullptr, "%"); + if (g_model.limitData[curChan - 1].name[0] != 0) { + dc->drawNumber(barLft + 1, barTop, curChan, + FONT(XS) | txtColor | LEFT | LEADING0, 2); + dc->drawSizedText(barLft + 23, barTop, + g_model.limitData[curChan - 1].name, + sizeof(g_model.limitData[curChan - 1].name), + FONT(XS) | txtColor | LEFT); + } else { + drawSource(dc, barLft + 1, barTop, MIXSRC_FIRST_CH + curChan - 1, + FONT(XS) | txtColor | LEFT); } + } + return lastChan - 1; + } + void twoColumns(BitmapBuffer* dc) + { + uint8_t endColumn = + drawChannels(dc, 0, 0, (width() / 2) - 1, height(), + persistentData->options[0].value.unsignedValue, + persistentData->options[1].value.boolValue, + persistentData->options[2].value.unsignedValue, + persistentData->options[3].value.unsignedValue, + persistentData->options[4].value.unsignedValue); + + drawChannels(dc, width() / 2, 0, (width() / 2) - 1, height(), endColumn + 1, + persistentData->options[1].value.boolValue, + persistentData->options[2].value.unsignedValue, + persistentData->options[3].value.unsignedValue, + persistentData->options[4].value.unsignedValue); + } + + void oneColumn(BitmapBuffer* dc) + { + drawChannels(dc, 0, 0, width(), height(), + persistentData->options[0].value.unsignedValue, + persistentData->options[1].value.boolValue, + persistentData->options[2].value.unsignedValue, + persistentData->options[3].value.unsignedValue, + persistentData->options[4].value.unsignedValue); + } + + void checkEvents() override + { + Widget::checkEvents(); + + // Last time we refreshed the window + uint32_t now = RTOS_GET_MS(); + if (now - lastRefresh >= OUTPUTS_REFRESH) { + lastRefresh = now; invalidate(); } + invalidate(); + } - static const ZoneOption options[]; + static const ZoneOption options[]; - protected: - // Last time we refreshed the window - uint32_t lastRefresh = 0; + protected: + // Last time we refreshed the window + uint32_t lastRefresh = 0; }; const ZoneOption OutputsWidget::options[] = { - { STR_FIRST_CHANNEL, ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32) }, - { STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false) }, - { STR_BG_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(LIGHTGREY) }, - { STR_TEXT_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY1>>16) }, - { STR_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1>>16) }, - { nullptr, ZoneOption::Bool } -}; + {STR_FIRST_CHANNEL, ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1), + OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32)}, + {STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false)}, + {STR_BG_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(LIGHTGREY)}, + {STR_TEXT_COLOR, ZoneOption::Color, + OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY1 >> 16)}, + {STR_COLOR, ZoneOption::Color, + OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1 >> 16)}, + {nullptr, ZoneOption::Bool}}; -BaseWidgetFactory outputsWidget("Outputs", OutputsWidget::options); +BaseWidgetFactory outputsWidget("Outputs", + OutputsWidget::options);