Merge pull request #8424 from opentx/raphaelcoeffic/fix-decorations

2.4: fixed decorations
This commit is contained in:
Bertrand Songis
2021-04-05 17:22:49 +02:00
committed by GitHub
6 changed files with 96 additions and 64 deletions
+88 -33
View File
@@ -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)
);
}
}
+2
View File
@@ -53,6 +53,8 @@ class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
protected:
const LayoutFactory * factory;
TopBar * topBar = nullptr;
uint8_t decorationSettings = 0;
std::list<Window*> decorations;
};
void registerLayout(const LayoutFactory * factory);
+1 -8
View File
@@ -106,14 +106,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;
+2 -7
View File
@@ -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;
+1 -8
View File
@@ -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;
+2 -8
View File
@@ -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;
};