From 4eb4177d8c76a7b993a8a3a2d40b310f152c9920 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 5 Apr 2021 16:34:12 +0200 Subject: [PATCH] fixed decorations --- radio/src/gui/colorlcd/layout.cpp | 121 ++++++++++++++----- radio/src/gui/colorlcd/layout.h | 2 + radio/src/gui/colorlcd/layouts/layout1x1.cpp | 9 +- radio/src/gui/colorlcd/layouts/layout2+1.cpp | 9 +- radio/src/gui/colorlcd/layouts/layout2x1.cpp | 9 +- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 10 +- 6 files changed, 96 insertions(+), 64 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index f0dcf237b..1480db327 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -95,15 +95,39 @@ void loadCustomScreens() screen->attach(ViewMain::instance); } } - - //customScreens[g_model.view]->attach(ViewMain::instance); } void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) { + // check if deco setting are still up-to-date + uint8_t checkSettings = + (topbar ? 1 << 0 : 0) | + (sliders ? 1 << 1 : 0) | + (trims ? 1 << 2 : 0) | + (flightMode ? 1 << 3 : 0); + + if (checkSettings == decorationSettings) { + // everything ok, exit! + return; + } + + // kill all decorations & re-decorate + for (auto deco: decorations) { + deco->deleteLater(); + } + decorations.clear(); + topBar = nullptr; + + // effect a full redraw + invalidate(); + + // save settings + decorationSettings = checkSettings; + if (topbar) { topBar = new TopBar(this); topBar->load(); + decorations.push_back(topBar); } if (sliders) { @@ -111,49 +135,69 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0) + (topbar ? TOPBAR_HEIGHT / 2 : 0); #endif - new MainViewHorizontalSlider(this, {HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, - [=] { return calibratedAnalogs[CALIBRATED_POT1]; }); + decorations.push_back( + new MainViewHorizontalSlider(this, {HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, + [=] { return calibratedAnalogs[CALIBRATED_POT1]; }) + ); if (IS_POT_MULTIPOS(POT2)) { - new MainView6POS(this, {LCD_W / 2 - MULTIPOS_W / 2, LCD_H - TRIM_SQUARE_SIZE, MULTIPOS_W + 1, MULTIPOS_H}, - [=] { return (1 + (potsPos[1] & 0x0f)); }); + decorations.push_back( + new MainView6POS(this, {LCD_W / 2 - MULTIPOS_W / 2, LCD_H - TRIM_SQUARE_SIZE, MULTIPOS_W + 1, MULTIPOS_H}, + [=] { return (1 + (potsPos[1] & 0x0f)); }) + ); } else if (IS_POT(POT2)) { - new MainViewHorizontalSlider(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, - [=] { return calibratedAnalogs[CALIBRATED_POT2]; }); + decorations.push_back( + new MainViewHorizontalSlider(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, + [=] { return calibratedAnalogs[CALIBRATED_POT2]; }) + ); } #if defined(HARDWARE_POT3) - new MainViewHorizontalSlider(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, - [=] { return calibratedAnalogs[CALIBRATED_POT3]; }); + decorations.push_back( + new MainViewHorizontalSlider(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, + [=] { return calibratedAnalogs[CALIBRATED_POT3]; }) + ); #endif #if defined(HARDWARE_EXT1) if (IS_POT_SLIDER_AVAILABLE(EXT1)) { - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, - [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }); - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, - [=] { return calibratedAnalogs[CALIBRATED_POT_EXT1]; }); + decorations.push_back( + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) + ); + decorations.push_back( + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + [=] { return calibratedAnalogs[CALIBRATED_POT_EXT1]; }) + ); } else { - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, - [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }); + decorations.push_back( + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) + ); } #endif #if defined(HARDWARE_EXT2) if (IS_POT_SLIDER_AVAILABLE(EXT2)) { - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, + decorations.push_back( + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, - [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }); - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, + [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) + ); + decorations.push_back( + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, - [=] { return calibratedAnalogs[CALIBRATED_POT_EXT2]; }); + [=] { return calibratedAnalogs[CALIBRATED_POT_EXT2]; }) + ); } else { - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, + decorations.push_back( + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, - [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }); + [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) + ); } #endif } @@ -169,24 +213,35 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) // Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH // Left - new MainViewHorizontalTrim(this, {HMARGIN, LCD_H - TRIM_SQUARE_SIZE + yOffset, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, - [=] { return getTrimValue(mixerCurrentFlightMode, 0); }); - // Right - new MainViewHorizontalTrim(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE + yOffset, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, - [=] { return getTrimValue(mixerCurrentFlightMode, 3); }); + decorations.push_back( + new MainViewHorizontalTrim(this, {HMARGIN, LCD_H - TRIM_SQUARE_SIZE + yOffset, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, + [=] { return getTrimValue(mixerCurrentFlightMode, 0); }) + ); + // Right + decorations.push_back( + new MainViewHorizontalTrim(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE + yOffset, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, + [=] { return getTrimValue(mixerCurrentFlightMode, 3); }) + ); // Left - new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, - [=] { return getTrimValue(mixerCurrentFlightMode, 1); }); + decorations.push_back( + new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + [=] { return getTrimValue(mixerCurrentFlightMode, 1); }) + ); + // Right - new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, - [=] { return getTrimValue(mixerCurrentFlightMode, 2); }); + decorations.push_back( + new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + [=] { return getTrimValue(mixerCurrentFlightMode, 2); }) + ); } if (flightMode) { - new DynamicText(this, {50, LCD_H - 4 - (sliders? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { + decorations.push_back( + new DynamicText(this, {50, LCD_H - 4 - (sliders? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { return g_model.flightModeData[mixerCurrentFlightMode].name; - }, CENTERED); + }, CENTERED) + ); } } diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index 2d93297f2..1be0b623a 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -53,6 +53,8 @@ class Layout: public WidgetsContainer protected: const LayoutFactory * factory; TopBar * topBar = nullptr; + uint8_t decorationSettings = 0; + std::list decorations; }; void registerLayout(const LayoutFactory * factory); diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index 9912c8590..8345b4318 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -90,14 +90,7 @@ class Layout1x1: public Layout void checkEvents() override { Layout::checkEvents(); - uint8_t newValue = persistentData->options[4].value.boolValue << 4 | persistentData->options[3].value.boolValue << 3 | persistentData->options[2].value.boolValue << 2 - | persistentData->options[1].value.boolValue << 1 | persistentData->options[0].value.boolValue; - if (value != newValue) { - value = newValue; - // TODO call this from the Layout config window - this->clear(); - decorate(); - } + decorate(); } protected: uint8_t value = 0; diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index 9320ae624..ed40c6a7f 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -86,13 +86,8 @@ class Layout2P1: public Layout void checkEvents() override { Layout::checkEvents(); - uint8_t newValue = persistentData->options[4].value.boolValue << 4 | persistentData->options[3].value.boolValue << 3 | persistentData->options[2].value.boolValue << 2 - | persistentData->options[1].value.boolValue << 1 | persistentData->options[0].value.boolValue; - if (value != newValue) { - value = newValue; - // TODO call this from the Layout config window - decorate(); - } + // TODO call this from the Layout config window + decorate(); } protected: uint8_t value = 0; diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index ae0afb5a6..67610c614 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -92,14 +92,7 @@ class Layout2x1: public Layout void checkEvents() override { Layout::checkEvents(); - uint8_t newValue = persistentData->options[4].value.boolValue << 4 | persistentData->options[3].value.boolValue << 3 | persistentData->options[2].value.boolValue << 2 - | persistentData->options[1].value.boolValue << 1 | persistentData->options[0].value.boolValue; - if (value != newValue) { - value = newValue; - // TODO call this from the Layout config window - this->clear(); - decorate(); - } + decorate(); } protected: uint8_t value = 0; diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index 9706ffc6f..37bf4515b 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -94,15 +94,9 @@ class Layout2x2: public Layout void checkEvents() override { Layout::checkEvents(); - uint8_t newValue = persistentData->options[4].value.boolValue << 4 | persistentData->options[3].value.boolValue << 3 | persistentData->options[2].value.boolValue << 2 - | persistentData->options[1].value.boolValue << 1 | persistentData->options[0].value.boolValue; - if (value != newValue) { - value = newValue; - // TODO call this from the Layout config window - this->clear(); - decorate(); - } + decorate(); } + protected: uint8_t value = 0; };