Re-use ViewMain decoration in Radio calibration

This commit is contained in:
Raphael Coeffic
2021-04-18 07:57:41 +02:00
parent 3ed1de1619
commit a1cd234c14
7 changed files with 398 additions and 314 deletions
+1
View File
@@ -53,6 +53,7 @@ set(GUI_SRC
radio_diaganas.cpp
radio_calibration.cpp
view_main.cpp
view_main_decoration.cpp
view_channels.cpp
view_logical_switches.cpp
view_statistics.cpp
+1
View File
@@ -29,6 +29,7 @@
#define MAX_LAYOUT_OPTIONS 10
constexpr coord_t TRIM_LINE_WIDTH = 8;
constexpr coord_t TRIM_SQUARE_SIZE = 17;
constexpr coord_t MAIN_ZONE_BORDER = 10;
class LayoutFactory;
+8 -44
View File
@@ -21,6 +21,7 @@
#include "opentx.h"
#include "radio_calibration.h"
#include "sliders.h"
#include "view_main_decoration.h"
#define XPOT_DELTA 10
#define XPOT_DELAY 5 /* cycles */
@@ -81,51 +82,14 @@ void RadioCalibrationPage::buildBody(FormWindow * window)
new StickCalibrationWindow(window, {40, 20, 90, 90}, STICK1, STICK2);
new StickCalibrationWindow(window, {LCD_W - 130, 20, 90, 90}, STICK4, STICK3);
#if defined(PCBHORUS)
new MainViewHorizontalSlider(this, {HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, 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}, 1);
}
new MainViewHorizontalSlider(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, CALIBRATED_POT3);
#if defined(HARDWARE_EXT1)
coord_t yOffset = TOPBAR_HEIGHT / 2;
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT / 2},
CALIBRATED_SLIDER_REAR_LEFT);
new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT / 2},
CALIBRATED_POT_EXT1);
}
else {
new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT},
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 / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT / 2},
CALIBRATED_SLIDER_REAR_RIGHT);
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT / 2},
CALIBRATED_POT_EXT2);
}
else {
new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT / 2 + yOffset, TRIM_SQUARE_SIZE,
VERTICAL_SLIDERS_HEIGHT},
CALIBRATED_SLIDER_REAR_RIGHT);
}
#endif
#elif defined(PCBNV14)
new MainViewHorizontalSlider(this, {HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, CALIBRATED_POT1);
new MainViewHorizontalSlider(this, {LCD_W - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, LCD_H - TRIM_SQUARE_SIZE, HORIZONTAL_SLIDERS_WIDTH, TRIM_SQUARE_SIZE}, CALIBRATED_POT2);
rect_t r = { 0, 0, window->width(), window->height() };
auto deco = new ViewMainDecoration(window, r);
deco->setTrimsVisible(false);
deco->setSlidersVisible(true);
deco->setFlightModeVisible(false);
deco->adjustDecoration();
#if defined(PCBNV14)
new TextButton(window, {LCD_W - 120, LCD_H - 140, 90, 40}, "Next",
[=]() -> uint8_t {
nextStep();
+14 -243
View File
@@ -28,17 +28,16 @@
#include "topbar.h"
#include "layouts/sliders.h"
#include "layouts/trims.h"
#include "view_main_decoration.h"
#include "opentx.h"
constexpr coord_t MAIN_ZONE_BORDER = 10;
Layout * customScreens[MAX_CUSTOM_SCREENS] = {};
int getMainViewsCount()
{
for (int index=1; index<MAX_CUSTOM_SCREENS; index++) {
if (!customScreens[index]) {
return index;
return index + 1;
}
}
return MAX_CUSTOM_SCREENS;
@@ -87,171 +86,35 @@ void ViewMain::setTopbarVisible(bool visible)
topbar->setVisible(visible);
}
void ViewMain::setSlidersVisible(bool visible)
{
//
// Horizontal Sliders
//
sliders[SLIDERS_POT1]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
//TODO: might change depending on hardware settings
if (IS_POT_MULTIPOS(POT2)) {
sliders[SLIDERS_POT2]->setHeight(visible ? MULTIPOS_H : 0);
}
else if (IS_POT(POT2)) {
sliders[SLIDERS_POT2]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
}
#if defined(HARDWARE_POT3)
sliders[SLIDERS_POT3]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
#endif
//
// Vertical sliders
//
sliders[SLIDERS_REAR_LEFT]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
#if defined(HARDWARE_EXT1)
//TODO: might change depending on hardware settings
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
sliders[SLIDERS_EXT1]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
}
#endif
sliders[SLIDERS_REAR_RIGHT]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
#if defined(HARDWARE_EXT2)
//TODO: might change depending on hardware settings
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
sliders[SLIDERS_EXT2]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
}
#endif
}
void ViewMain::setTrimsVisible(bool visible)
{
trims[TRIMS_LH]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
trims[TRIMS_RH]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
decoration->setTrimsVisible(visible);
}
trims[TRIMS_LV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
trims[TRIMS_RV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
void ViewMain::setSlidersVisible(bool visible)
{
decoration->setSlidersVisible(visible);
}
void ViewMain::setFlightModeVisible(bool visible)
{
flightMode->setHeight(visible ? 20 : 0);
decoration->setFlightModeVisible(visible);
}
void ViewMain::adjustDecoration()
{
// Topbar does not need any computation
// (height() has been set in setTopbarVisible())
// Sliders are closer to the edge and must be computed first
// (vertical sliders depends on topbar)
// These are located on the bottom
auto pos = height() - sliders[SLIDERS_POT1]->height();
sliders[SLIDERS_POT1]->setTop(pos);
if (sliders[SLIDERS_POT2]) {
auto sl = sliders[SLIDERS_POT2];
sl->setTop(pos);
if (IS_POT_MULTIPOS(POT2)) {
sl->setWidth(MULTIPOS_W);
}
else { // if !IS_POT(POT2) -> sliders[SLIDERS_POT2] == nullptr
sl->setWidth(HORIZONTAL_SLIDERS_WIDTH);
}
sl->setLeft((width() - sl->width()) / 2);
}
#if defined(HARDWARE_POT3)
sliders[SLIDERS_POT3]->setTop(pos);
#endif
// Horizontal trims are on top of horizontal sliders
pos -= trims[TRIMS_LH]->height();
trims[TRIMS_LH]->setTop(pos);
trims[TRIMS_RH]->setTop(pos);
// Vertical trims/slider are on top of horizontal sliders with a small margin
auto vertTop = pos - HMARGIN - VERTICAL_SLIDERS_HEIGHT;
// Left side (vertical)
pos = left();
sliders[SLIDERS_REAR_LEFT]->setLeft(pos);
sliders[SLIDERS_REAR_LEFT]->setTop(vertTop);
#if defined(HARDWARE_EXT1)
sliders[SLIDERS_EXT1]->setLeft(pos);
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
auto rl = sliders[SLIDERS_REAR_LEFT];
auto e1 = sliders[SLIDERS_EXT1];
// If EXT1 is configured as a slider,
// place it bellow rear-left slider (and make them smaller)
rl->setHeight(VERTICAL_SLIDERS_HEIGHT / 2);
e1->setTop(vertTop + rl->height() + HMARGIN/2);
e1->setHeight(rl->height());
}
else {
auto rl = sliders[SLIDERS_REAR_LEFT];
auto e1 = sliders[SLIDERS_EXT1];
// Otherwise hide the extra slider and make rear-left fullsize
rl->setHeight(VERTICAL_SLIDERS_HEIGHT);
e1->setHeight(0);
}
#endif
// Right side (vertical)
pos = right() - sliders[SLIDERS_REAR_RIGHT]->width();
sliders[SLIDERS_REAR_RIGHT]->setLeft(pos);
sliders[SLIDERS_REAR_RIGHT]->setTop(vertTop);
#if defined(HARDWARE_EXT2)
sliders[SLIDERS_EXT2]->setLeft(pos);
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
auto rr = sliders[SLIDERS_REAR_RIGHT];
auto e2 = sliders[SLIDERS_EXT2];
// If EXT2 is configured as a slider,
// place it bellow rear-left slider (and make them smaller)
rr->setHeight(VERTICAL_SLIDERS_HEIGHT / 2);
e2->setTop(vertTop + rr->height() + HMARGIN/2);
e2->setHeight(rr->height());
}
else {
auto rr = sliders[SLIDERS_REAR_RIGHT];
auto e2 = sliders[SLIDERS_EXT2];
// Otherwise hide the extra slider and make rear-left fullsize
rr->setHeight(VERTICAL_SLIDERS_HEIGHT);
e2->setHeight(0);
}
#endif
// Finally place the vertical trims further from the edge
trims[TRIMS_LV]->setLeft(sliders[SLIDERS_REAR_LEFT]->right());
trims[TRIMS_LV]->setTop(vertTop);
trims[TRIMS_RV]->setLeft(sliders[SLIDERS_REAR_RIGHT]->left() - trims[TRIMS_RV]->width());
trims[TRIMS_RV]->setTop(vertTop);
//TODO: find a proper place for the flight-mode text box
decoration->adjustDecoration();
}
rect_t ViewMain::getMainZone() const
{
rect_t zone = {
trims[TRIMS_LV]->right() + MAIN_ZONE_BORDER,
topbar->bottom() + MAIN_ZONE_BORDER,
0, 0 // let's compute them!
};
zone.w = trims[TRIMS_RV]->left() - MAIN_ZONE_BORDER - zone.x;
zone.h = trims[TRIMS_LH]->top() - MAIN_ZONE_BORDER - zone.y;
rect_t zone = decoration->getMainZone();
zone.y += topbar->bottom();
zone.h -= topbar->height();
return zone;
}
@@ -334,9 +197,7 @@ void ViewMain::paint(BitmapBuffer * dc)
void ViewMain::createDecoration()
{
createTopbar();
createSliders();
createTrims();
createFlightMode();
decoration = new ViewMainDecoration(this, getRect());
}
void ViewMain::createTopbar()
@@ -345,93 +206,3 @@ void ViewMain::createTopbar()
topbar->load();
}
void ViewMain::createSliders()
{
// TODO:
// - layout must become really dynamic (see adjustDecoration())
// - components should be created in "folded" state
// - it should not be required to call hasXXXX() at all
// fixed size array, so that works
memset(sliders, 0, sizeof(sliders));
rect_t r = {
// left
HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
sliders[SLIDERS_POT1] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT1);
r = rect_t { 0, 0, 0, 0 };
if (IS_POT_MULTIPOS(POT2)) {
sliders[SLIDERS_POT2] = new MainView6POS(this, r, 1);
}
else if (IS_POT(POT2)) {
sliders[SLIDERS_POT2] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT2);
}
#if defined(HARDWARE_POT3)
r = rect_t {
// right
width() - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
sliders[SLIDERS_POT3] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT3);
#endif
r = rect_t { 0, 0, 0, 0 };
sliders[SLIDERS_REAR_LEFT] = new MainViewVerticalSlider(this, r, CALIBRATED_SLIDER_REAR_LEFT);
sliders[SLIDERS_REAR_RIGHT] = new MainViewVerticalSlider(this, r, CALIBRATED_SLIDER_REAR_RIGHT);
#if defined(HARDWARE_EXT1)
sliders[SLIDERS_EXT1] = new MainViewVerticalSlider(this, r, CALIBRATED_POT_EXT1);
#endif
#if defined(HARDWARE_EXT2)
sliders[SLIDERS_EXT2] = new MainViewVerticalSlider(this, r, CALIBRATED_POT_EXT2);
#endif
}
void ViewMain::createTrims()
{
// Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH
rect_t r = {
left() + HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
trims[TRIMS_LH] = new MainViewHorizontalTrim(this, r, 0);
r = rect_t {
right() - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
trims[TRIMS_RH] = new MainViewHorizontalTrim(this, r, 3);
r = rect_t {
0, 0, 0,
VERTICAL_SLIDERS_HEIGHT
};
trims[TRIMS_LV] = new MainViewVerticalTrim(this, r, 1);
trims[TRIMS_RV] = new MainViewVerticalTrim(this, r, 2);
}
void ViewMain::createFlightMode()
{
rect_t r = {
// centered text box (50 pixels from either edge)
// -> re-size once the other components are set
50, 0, width() - 100, 0
};
std::function<std::string()> getFM = []() -> std::string {
return g_model.flightModeData[mixerCurrentFlightMode].name;
};
flightMode = new DynamicText(this, r, getFM, CENTERED);
}
+4 -27
View File
@@ -25,6 +25,7 @@
#include <memory>
class TopBar;
class ViewMainDecoration;
class SetupWidgetsPage;
class ViewMain: public FormWindow
@@ -50,7 +51,7 @@ class ViewMain: public FormWindow
}
#endif
// Set decoration visibility
// Set topbar & decoration visibility
void setTopbarVisible(bool visible);
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
@@ -66,29 +67,8 @@ class ViewMain: public FormWindow
protected:
static ViewMain * _instance;
enum {
SLIDERS_POT1 = 0,
SLIDERS_POT2,
SLIDERS_POT3,
SLIDERS_REAR_LEFT,
SLIDERS_EXT1,
SLIDERS_REAR_RIGHT,
SLIDERS_EXT2,
SLIDERS_MAX
};
enum {
TRIMS_LH = 0,
TRIMS_LV,
TRIMS_RV,
TRIMS_RH,
TRIMS_MAX
};
TopBar* topbar;
Window* sliders[SLIDERS_MAX];
Window* trims[TRIMS_MAX];
Window* flightMode;
TopBar* topbar;
ViewMainDecoration* decoration;
friend class SetupWidgetsPage;
@@ -101,9 +81,6 @@ class ViewMain: public FormWindow
void createDecoration();
void createTopbar();
void createSliders();
void createTrims();
void createFlightMode();
};
#endif // _VIEW_MAIN_H_
@@ -0,0 +1,287 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "view_main_decoration.h"
#include "layout.h"
// because of IS_POT_MULTIPOS() and pal
#include "opentx.h"
// these 2 need things from opentx.h
#include "layouts/sliders.h"
#include "layouts/trims.h"
#include "board.h"
void ViewMainDecoration::setSlidersVisible(bool visible)
{
//
// Horizontal Sliders
//
sliders[SLIDERS_POT1]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
//TODO: might change depending on hardware settings
if (IS_POT_MULTIPOS(POT2)) {
sliders[SLIDERS_POT2]->setHeight(visible ? MULTIPOS_H : 0);
}
else if (IS_POT(POT2)) {
sliders[SLIDERS_POT2]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
}
#if defined(HARDWARE_POT3)
sliders[SLIDERS_POT3]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
#endif
//
// Vertical sliders
//
sliders[SLIDERS_REAR_LEFT]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
#if defined(HARDWARE_EXT1)
//TODO: might change depending on hardware settings
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
sliders[SLIDERS_EXT1]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
}
#endif
sliders[SLIDERS_REAR_RIGHT]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
#if defined(HARDWARE_EXT2)
//TODO: might change depending on hardware settings
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
sliders[SLIDERS_EXT2]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
}
#endif
}
void ViewMainDecoration::setTrimsVisible(bool visible)
{
trims[TRIMS_LH]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
trims[TRIMS_RH]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
trims[TRIMS_LV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
trims[TRIMS_RV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
}
void ViewMainDecoration::setFlightModeVisible(bool visible)
{
flightMode->setHeight(visible ? 20 : 0);
}
void ViewMainDecoration::adjustDecoration()
{
// Sliders are closer to the edge and must be computed first
// These are located on the bottom
auto pos = bottom() - sliders[SLIDERS_POT1]->height();
sliders[SLIDERS_POT1]->setTop(pos);
if (sliders[SLIDERS_POT2]) {
auto sl = sliders[SLIDERS_POT2];
sl->setTop(pos);
if (IS_POT_MULTIPOS(POT2)) {
sl->setWidth(MULTIPOS_W);
}
else { // if !IS_POT(POT2) -> sliders[SLIDERS_POT2] == nullptr
sl->setWidth(HORIZONTAL_SLIDERS_WIDTH);
}
sl->setLeft((width() - sl->width()) / 2);
}
#if defined(HARDWARE_POT3)
sliders[SLIDERS_POT3]->setTop(pos);
#endif
// Horizontal trims are on top of horizontal sliders
pos -= trims[TRIMS_LH]->height();
trims[TRIMS_LH]->setTop(pos);
trims[TRIMS_RH]->setTop(pos);
// Vertical trims/slider are on top of horizontal sliders with a small margin
auto vertTop = pos - HMARGIN - VERTICAL_SLIDERS_HEIGHT;
// Left side (vertical)
pos = left();
sliders[SLIDERS_REAR_LEFT]->setLeft(pos);
sliders[SLIDERS_REAR_LEFT]->setTop(vertTop);
#if defined(HARDWARE_EXT1)
sliders[SLIDERS_EXT1]->setLeft(pos);
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
auto rl = sliders[SLIDERS_REAR_LEFT];
auto e1 = sliders[SLIDERS_EXT1];
// If EXT1 is configured as a slider,
// place it bellow rear-left slider (and make them smaller)
rl->setHeight(VERTICAL_SLIDERS_HEIGHT / 2);
e1->setTop(vertTop + rl->height() + HMARGIN/2);
e1->setHeight(rl->height());
}
else {
auto rl = sliders[SLIDERS_REAR_LEFT];
auto e1 = sliders[SLIDERS_EXT1];
// Otherwise hide the extra slider and make rear-left fullsize
rl->setHeight(VERTICAL_SLIDERS_HEIGHT);
e1->setHeight(0);
}
#endif
// Right side (vertical)
pos = right() - sliders[SLIDERS_REAR_RIGHT]->width();
sliders[SLIDERS_REAR_RIGHT]->setLeft(pos);
sliders[SLIDERS_REAR_RIGHT]->setTop(vertTop);
#if defined(HARDWARE_EXT2)
sliders[SLIDERS_EXT2]->setLeft(pos);
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
auto rr = sliders[SLIDERS_REAR_RIGHT];
auto e2 = sliders[SLIDERS_EXT2];
// If EXT2 is configured as a slider,
// place it bellow rear-left slider (and make them smaller)
rr->setHeight(VERTICAL_SLIDERS_HEIGHT / 2);
e2->setTop(vertTop + rr->height() + HMARGIN/2);
e2->setHeight(rr->height());
}
else {
auto rr = sliders[SLIDERS_REAR_RIGHT];
auto e2 = sliders[SLIDERS_EXT2];
// Otherwise hide the extra slider and make rear-left fullsize
rr->setHeight(VERTICAL_SLIDERS_HEIGHT);
e2->setHeight(0);
}
#endif
// Finally place the vertical trims further from the edge
trims[TRIMS_LV]->setLeft(sliders[SLIDERS_REAR_LEFT]->right());
trims[TRIMS_LV]->setTop(vertTop);
trims[TRIMS_RV]->setLeft(sliders[SLIDERS_REAR_RIGHT]->left() - trims[TRIMS_RV]->width());
trims[TRIMS_RV]->setTop(vertTop);
//TODO: find a proper place for the flight-mode text box
}
rect_t ViewMainDecoration::getMainZone() const
{
rect_t zone = {
trims[TRIMS_LV]->right() + MAIN_ZONE_BORDER,
/*topbar->bottom() +*/ MAIN_ZONE_BORDER,
0, 0 // let's compute them!
};
zone.w = trims[TRIMS_RV]->left() - MAIN_ZONE_BORDER - zone.x;
zone.h = trims[TRIMS_LH]->top() - MAIN_ZONE_BORDER - zone.y;
return zone;
}
void ViewMainDecoration::createSliders()
{
// TODO:
// - layout must become really dynamic (see adjustDecoration())
// - components should be created in "folded" state
// - it should not be required to call hasXXXX() at all
// fixed size array, so that works
memset(sliders, 0, sizeof(sliders));
rect_t r = {
// left
HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
sliders[SLIDERS_POT1] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT1);
r = rect_t { 0, 0, 0, 0 };
if (IS_POT_MULTIPOS(POT2)) {
sliders[SLIDERS_POT2] = new MainView6POS(this, r, 1);
}
else if (IS_POT(POT2)) {
sliders[SLIDERS_POT2] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT2);
}
#if defined(HARDWARE_POT3)
r = rect_t {
// right
width() - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
sliders[SLIDERS_POT3] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT3);
#endif
r = rect_t { 0, 0, 0, 0 };
sliders[SLIDERS_REAR_LEFT] = new MainViewVerticalSlider(this, r, CALIBRATED_SLIDER_REAR_LEFT);
sliders[SLIDERS_REAR_RIGHT] = new MainViewVerticalSlider(this, r, CALIBRATED_SLIDER_REAR_RIGHT);
#if defined(HARDWARE_EXT1)
sliders[SLIDERS_EXT1] = new MainViewVerticalSlider(this, r, CALIBRATED_POT_EXT1);
#endif
#if defined(HARDWARE_EXT2)
sliders[SLIDERS_EXT2] = new MainViewVerticalSlider(this, r, CALIBRATED_POT_EXT2);
#endif
}
void ViewMainDecoration::createTrims()
{
// Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH
rect_t r = {
left() + HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
trims[TRIMS_LH] = new MainViewHorizontalTrim(this, r, 0);
r = rect_t {
right() - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, 0,
HORIZONTAL_SLIDERS_WIDTH, 0
};
trims[TRIMS_RH] = new MainViewHorizontalTrim(this, r, 3);
r = rect_t {
0, 0, 0,
VERTICAL_SLIDERS_HEIGHT
};
trims[TRIMS_LV] = new MainViewVerticalTrim(this, r, 1);
trims[TRIMS_RV] = new MainViewVerticalTrim(this, r, 2);
}
void ViewMainDecoration::createFlightMode()
{
rect_t r = {
// centered text box (50 pixels from either edge)
// -> re-size once the other components are set
50, 0, width() - 100, 0
};
std::function<std::string()> getFM = []() -> std::string {
return g_model.flightModeData[mixerCurrentFlightMode].name;
};
flightMode = new DynamicText(this, r, getFM, CENTERED);
}
@@ -0,0 +1,83 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "window.h"
class ViewMainDecoration: public Window
{
public:
ViewMainDecoration(Window * parent, const rect_t & rect):
Window(parent, rect)
{
createSliders();
createTrims();
createFlightMode();
}
// Set decoration visibility
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);
// Re-calculate positions
void adjustDecoration();
// Get the available space in the middle of the screen
// (without decoration)
rect_t getMainZone() const;
protected:
#if defined(DEBUG_WINDOWS)
virtual std::string getName() const
{
return "ViewMainDecoration";
}
#endif
enum {
SLIDERS_POT1 = 0,
SLIDERS_POT2,
SLIDERS_POT3,
SLIDERS_REAR_LEFT,
SLIDERS_EXT1,
SLIDERS_REAR_RIGHT,
SLIDERS_EXT2,
SLIDERS_MAX
};
enum {
TRIMS_LH = 0,
TRIMS_LV,
TRIMS_RV,
TRIMS_RH,
TRIMS_MAX
};
Window* sliders[SLIDERS_MAX];
Window* trims[TRIMS_MAX];
Window* flightMode;
void createSliders();
void createTrims();
void createFlightMode();
};