Facelift round 4

This commit is contained in:
Raphael Coeffic
2021-06-14 06:34:57 +02:00
parent cf1d83351c
commit 490cf003a3
11 changed files with 992 additions and 799 deletions
+15 -2
View File
@@ -309,10 +309,9 @@ void ModelCurvesPage::build(FormWindow * window, int8_t focusIndex)
if (isCurveUsed(index)) { if (isCurveUsed(index)) {
// Curve label // Curve label
auto text = auto txt =
new StaticText(window, grid.getLabelSlot(), getCurveString(1 + index), new StaticText(window, grid.getLabelSlot(), getCurveString(1 + index),
BUTTON_BACKGROUND, CENTERED); BUTTON_BACKGROUND, CENTERED);
text->setBackgroundColor(FOCUS_COLOR);
// Curve drawing // Curve drawing
Button * button = new CurveButton(window, grid.getFieldSlot(), index); Button * button = new CurveButton(window, grid.getFieldSlot(), index);
@@ -334,11 +333,25 @@ void ModelCurvesPage::build(FormWindow * window, int8_t focusIndex)
}); });
return 0; return 0;
}); });
button->setFocusHandler([=](bool focus) {
if (focus) {
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
} else {
txt->setBackgroundColor(FIELD_FRAME_COLOR);
txt->setTextFlags(CENTERED);
}
txt->invalidate();
});
if (focusIndex == index) { if (focusIndex == index) {
button->setFocus(SET_FOCUS_DEFAULT); button->setFocus(SET_FOCUS_DEFAULT);
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
txt->invalidate();
} }
txt->setHeight(button->height());
grid.spacer(button->height() + 5); grid.spacer(button->height() + 5);
} else { } else {
auto button = new TextButton(window, grid.getLabelSlot(), auto button = new TextButton(window, grid.getLabelSlot(),
+1 -1
View File
@@ -30,7 +30,7 @@ class ModelCurvesPage: public PageTab {
virtual void build(FormWindow * window) override virtual void build(FormWindow * window) override
{ {
build(window, -1); build(window, 0);
} }
protected: protected:
+12 -3
View File
@@ -64,9 +64,18 @@ void GVarButton::paint(BitmapBuffer * dc)
currentFlightMode = getFlightMode(); currentFlightMode = getFlightMode();
gvarSum = 0; gvarSum = 0;
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, FIELD_BGCOLOR); LcdFlags bgColor = FIELD_BGCOLOR;
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, getGVarString(gvarIdx), 0); LcdFlags textColor = 0;
dc->drawSizedText(x, y, gvar->name, LEN_GVAR_NAME, 0); if (hasFocus()) {
bgColor = FOCUS_BGCOLOR;
textColor = FOCUS_COLOR;
}
dc->drawSolidFilledRect(0, 0, nameRectW, rect.h, bgColor);
dc->drawSolidFilledRect(nameRectW, 0, rect.w - nameRectW, rect.h, FIELD_BGCOLOR);
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, getGVarString(gvarIdx), textColor);
dc->drawSizedText(x, y, gvar->name, LEN_GVAR_NAME, textColor);
// values are right aligned // values are right aligned
x += GVAR_NAME_SIZE; x += GVAR_NAME_SIZE;
+46 -27
View File
@@ -327,13 +327,17 @@ void CommonInputOrMixButton::drawFlightModes(BitmapBuffer *dc,
void CommonInputOrMixButton::paint(BitmapBuffer * dc) void CommonInputOrMixButton::paint(BitmapBuffer * dc)
{ {
dc->drawSolidFilledRect(0, 0, width(), height(), dc->drawSolidFilledRect(0, 0, width(), height(),
hasFocus() ? FOCUS_BGCOLOR : FIELD_BGCOLOR); /*hasFocus() ? FOCUS_BGCOLOR :*/ FIELD_BGCOLOR);
paintBody(dc); paintBody(dc);
if (!hasFocus()) if (!hasFocus())
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FIELD_FRAME_COLOR); dc->drawSolidRect(0, 0, rect.w, rect.h, 1, FIELD_FRAME_COLOR);
else
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
} }
class InputLineButton : public CommonInputOrMixButton { class InputLineButton : public CommonInputOrMixButton
{
public: public:
InputLineButton(FormGroup *parent, const rect_t &rect, uint8_t index) : InputLineButton(FormGroup *parent, const rect_t &rect, uint8_t index) :
CommonInputOrMixButton(parent, rect, index) CommonInputOrMixButton(parent, rect, index)
@@ -344,18 +348,15 @@ class InputLineButton : public CommonInputOrMixButton {
} }
} }
bool isActive() const override bool isActive() const override { return isExpoActive(index); }
{
return isExpoActive(index);
}
void paintBody(BitmapBuffer *dc) override void paintBody(BitmapBuffer *dc) override
{ {
const ExpoData &line = g_model.expoData[index]; const ExpoData &line = g_model.expoData[index];
LcdFlags textColor = DEFAULT_COLOR; LcdFlags textColor = DEFAULT_COLOR;
if (hasFocus()) // if (hasFocus())
textColor = FOCUS_COLOR; // textColor = FOCUS_COLOR;
// first line ... // first line ...
drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, line.weight, drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, line.weight,
@@ -421,21 +422,19 @@ void ModelInputsPage::build(FormWindow * window, int8_t focusIndex)
ExpoData *line = g_model.expoData; ExpoData *line = g_model.expoData;
for (uint8_t input = 0; input < MAX_INPUTS; input++) { for (uint8_t input = 0; input < MAX_INPUTS; input++) {
if (inputIndex < MAX_EXPOS && line->chn == input && EXPO_VALID(line)) { if (inputIndex < MAX_EXPOS && line->chn == input && EXPO_VALID(line)) {
coord_t h = grid.getWindowHeight();
auto txt = new StaticText(window, grid.getLabelSlot(), auto txt = new StaticText(window, grid.getLabelSlot(),
getSourceString(MIXSRC_FIRST_INPUT + input), getSourceString(MIXSRC_FIRST_INPUT + input),
0, CENTERED); BUTTON_BACKGROUND, CENTERED);
txt->setBackgroundColor(FIELD_BGCOLOR);
while (inputIndex < MAX_EXPOS && line->chn == input && EXPO_VALID(line)) { while (inputIndex < MAX_EXPOS && line->chn == input && EXPO_VALID(line)) {
Button * button = new InputLineButton(window, grid.getFieldSlot(), inputIndex); Button *button =
if (focusIndex == inputIndex) new InputLineButton(window, grid.getFieldSlot(), inputIndex);
button->setFocus(SET_FOCUS_DEFAULT);
button->setPressHandler([=]() -> uint8_t { button->setPressHandler([=]() -> uint8_t {
button->bringToTop(); button->bringToTop();
Menu *menu = new Menu(window); Menu *menu = new Menu(window);
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT,
editInput(window, input, inputIndex); [=]() { editInput(window, input, inputIndex); });
});
if (!reachExposLimit()) { if (!reachExposLimit()) {
menu->addLine(STR_INSERT_BEFORE, [=]() { menu->addLine(STR_INSERT_BEFORE, [=]() {
insertExpo(inputIndex, input); insertExpo(inputIndex, input);
@@ -453,7 +452,8 @@ void ModelInputsPage::build(FormWindow * window, int8_t focusIndex)
menu->addLine(STR_PASTE_BEFORE, [=]() { menu->addLine(STR_PASTE_BEFORE, [=]() {
copyExpo(s_copySrcIdx, inputIndex, PASTE_BEFORE); copyExpo(s_copySrcIdx, inputIndex, PASTE_BEFORE);
if (s_copyMode == MOVE_MODE) { if (s_copyMode == MOVE_MODE) {
deleteExpo((s_copySrcIdx > inputIndex) ? s_copySrcIdx+1 : s_copySrcIdx); deleteExpo((s_copySrcIdx > inputIndex) ? s_copySrcIdx + 1
: s_copySrcIdx);
s_copyMode = 0; s_copyMode = 0;
} }
rebuild(window, inputIndex); rebuild(window, inputIndex);
@@ -461,7 +461,8 @@ void ModelInputsPage::build(FormWindow * window, int8_t focusIndex)
menu->addLine(STR_PASTE_AFTER, [=]() { menu->addLine(STR_PASTE_AFTER, [=]() {
copyExpo(s_copySrcIdx, inputIndex, PASTE_AFTER); copyExpo(s_copySrcIdx, inputIndex, PASTE_AFTER);
if (s_copyMode == MOVE_MODE) { if (s_copyMode == MOVE_MODE) {
deleteExpo((s_copySrcIdx > inputIndex) ? s_copySrcIdx+1 : s_copySrcIdx); deleteExpo((s_copySrcIdx > inputIndex) ? s_copySrcIdx + 1
: s_copySrcIdx);
s_copyMode = 0; s_copyMode = 0;
} }
rebuild(window, inputIndex + 1); rebuild(window, inputIndex + 1);
@@ -478,19 +479,36 @@ void ModelInputsPage::build(FormWindow * window, int8_t focusIndex)
}); });
return 0; return 0;
}); });
button->setFocusHandler([=](bool focus) {
if (focus) {
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
} else {
txt->setBackgroundColor(FIELD_FRAME_COLOR);
txt->setTextFlags(CENTERED);
}
txt->invalidate();
});
grid.spacer(button->height() - 2); if (focusIndex == inputIndex) {
button->setFocus(SET_FOCUS_DEFAULT);
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
txt->invalidate();
}
grid.spacer(button->height() - 1);
++inputIndex; ++inputIndex;
++line; ++line;
} }
h = grid.getWindowHeight() - h + 1;
txt->setHeight(h);
grid.spacer(7); grid.spacer(7);
} } else {
else { auto button = new TextButton(window, grid.getLabelSlot(),
auto button = new TextButton(window, grid.getLabelSlot(), getSourceString(MIXSRC_FIRST_INPUT + input)); getSourceString(MIXSRC_FIRST_INPUT + input));
if (focusIndex == inputIndex) if (focusIndex == inputIndex) button->setFocus(SET_FOCUS_DEFAULT);
button->setFocus(SET_FOCUS_DEFAULT);
button->setPressHandler([=]() -> uint8_t { button->setPressHandler([=]() -> uint8_t {
button->bringToTop(); button->bringToTop();
Menu *menu = new Menu(window); Menu *menu = new Menu(window);
@@ -504,7 +522,8 @@ void ModelInputsPage::build(FormWindow * window, int8_t focusIndex)
menu->addLine(STR_PASTE, [=]() { menu->addLine(STR_PASTE, [=]() {
copyExpo(s_copySrcIdx, inputIndex, input); copyExpo(s_copySrcIdx, inputIndex, input);
if (s_copyMode == MOVE_MODE) { if (s_copyMode == MOVE_MODE) {
deleteExpo((s_copySrcIdx >= inputIndex) ? s_copySrcIdx+1 : s_copySrcIdx); deleteExpo((s_copySrcIdx >= inputIndex) ? s_copySrcIdx + 1
: s_copySrcIdx);
s_copyMode = 0; s_copyMode = 0;
} }
rebuild(window, -1); rebuild(window, -1);
@@ -241,18 +241,16 @@ static constexpr coord_t col1 = 20;
static constexpr coord_t col2 = (LCD_W - 100) / 3 + col1; static constexpr coord_t col2 = (LCD_W - 100) / 3 + col1;
static constexpr coord_t col3 = ((LCD_W - 100) / 3) * 2 + col1; static constexpr coord_t col3 = ((LCD_W - 100) / 3) * 2 + col1;
class LogicalSwitchButton : public Button { class LogicalSwitchButton : public Button
{
public: public:
LogicalSwitchButton(FormGroup* parent, const rect_t& rect, int lsIndex) : LogicalSwitchButton(FormGroup* parent, const rect_t& rect, int lsIndex) :
Button(parent, rect), Button(parent, rect), lsIndex(lsIndex), active(isActive())
lsIndex(lsIndex),
active(isActive())
{ {
LogicalSwitchData* ls = lswAddress(lsIndex); LogicalSwitchData* ls = lswAddress(lsIndex);
if (ls->andsw != SWSRC_NONE || ls->duration != 0 || ls->delay != 0) if (ls->andsw != SWSRC_NONE || ls->duration != 0 || ls->delay != 0)
setHeight(height() + 20); setHeight(height() + 20);
if (lswFamily(ls->func) == LS_FAMILY_EDGE) if (lswFamily(ls->func) == LS_FAMILY_EDGE) setHeight(height() + 20);
setHeight(height() + 20);
} }
bool isActive() const bool isActive() const
@@ -282,49 +280,53 @@ class LogicalSwitchButton : public Button {
if (lsFamily == LS_FAMILY_BOOL || lsFamily == LS_FAMILY_STICKY) { if (lsFamily == LS_FAMILY_BOOL || lsFamily == LS_FAMILY_STICKY) {
drawSwitch(dc, col2, line1, ls->v1); drawSwitch(dc, col2, line1, ls->v1);
drawSwitch(dc, col3, line1, ls->v2); drawSwitch(dc, col3, line1, ls->v2);
} } else if (lsFamily == LS_FAMILY_EDGE) {
else if (lsFamily == LS_FAMILY_EDGE) {
drawSwitch(dc, col1, line2, ls->v1); drawSwitch(dc, col1, line2, ls->v1);
putsEdgeDelayParam(dc, col2, line2, ls); putsEdgeDelayParam(dc, col2, line2, ls);
} } else if (lsFamily == LS_FAMILY_COMP) {
else if (lsFamily == LS_FAMILY_COMP) {
drawSource(dc, col2, line1, ls->v1, 0); drawSource(dc, col2, line1, ls->v1, 0);
drawSource(dc, col3, line1, ls->v2, 0); drawSource(dc, col3, line1, ls->v2, 0);
} } else if (lsFamily == LS_FAMILY_TIMER) {
else if (lsFamily == LS_FAMILY_TIMER) {
dc->drawNumber(col2, line1, lswTimerValue(ls->v1), LEFT | PREC1); dc->drawNumber(col2, line1, lswTimerValue(ls->v1), LEFT | PREC1);
dc->drawNumber(col3, line1, lswTimerValue(ls->v2), LEFT | PREC1); dc->drawNumber(col3, line1, lswTimerValue(ls->v2), LEFT | PREC1);
} } else {
else {
drawSource(dc, col2, line1, ls->v1, 0); drawSource(dc, col2, line1, ls->v1, 0);
drawSourceCustomValue(dc, col3, line1, ls->v1, (ls->v1 <= MIXSRC_LAST_CH ? calc100toRESX(ls->v2) : ls->v2), 0); drawSourceCustomValue(
dc, col3, line1, ls->v1,
(ls->v1 <= MIXSRC_LAST_CH ? calc100toRESX(ls->v2) : ls->v2), 0);
} }
// AND switch // AND switch
drawSwitch(dc, col1, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->andsw, 0); drawSwitch(dc, col1, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2,
ls->andsw, 0);
// CSW duration // CSW duration
if (ls->duration > 0) { if (ls->duration > 0) {
dc->drawNumber(col2, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->duration, PREC1 | LEFT); dc->drawNumber(col2, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2,
ls->duration, PREC1 | LEFT);
} }
// CSW delay // CSW delay
if (lsFamily != LS_FAMILY_EDGE && ls->delay > 0) { if (lsFamily != LS_FAMILY_EDGE && ls->delay > 0) {
dc->drawNumber(col3, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->delay, PREC1 | LEFT); dc->drawNumber(col3, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2,
ls->delay, PREC1 | LEFT);
} }
} }
void paint(BitmapBuffer* dc) override void paint(BitmapBuffer* dc) override
{ {
if (active) if (active)
dc->drawSolidFilledRect(2, 2, rect.w-4, rect.h-4, HIGHLIGHT_COLOR); dc->drawSolidFilledRect(0, 0, rect.w, rect.h, HIGHLIGHT_COLOR);
else else
dc->drawSolidFilledRect(2, 2, rect.w-4, rect.h-4, FIELD_BGCOLOR); dc->drawSolidFilledRect(0, 0, rect.w, rect.h, FIELD_BGCOLOR);
paintLogicalSwitchLine(dc); paintLogicalSwitchLine(dc);
// The bounding rect // The bounding rect
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? CHECKBOX_COLOR : DISABLE_COLOR); if (hasFocus())
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
else
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, FIELD_FRAME_COLOR);
} }
protected: protected:
@@ -363,7 +365,8 @@ void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex)
LogicalSwitchData* ls = lswAddress(i); LogicalSwitchData* ls = lswAddress(i);
if (ls->func == LS_FUNC_NONE) { if (ls->func == LS_FUNC_NONE) {
auto button = new TextButton(window, grid.getLabelSlot(), getSwitchPositionName(SWSRC_SW1+i)); auto button = new TextButton(window, grid.getLabelSlot(),
getSwitchPositionName(SWSRC_SW1 + i));
button->setPressHandler([=]() { button->setPressHandler([=]() {
if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) { if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) {
Menu* menu = new Menu(window); Menu* menu = new Menu(window);
@@ -379,16 +382,15 @@ void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex)
return 0; return 0;
}); });
grid.spacer(button->height() + 5); grid.spacer(button->height() + 5);
} } else {
else { auto txt = new StaticText(window, grid.getLabelSlot(),
new StaticText(window, grid.getLabelSlot(), getSwitchPositionName(SWSRC_SW1 + i), BUTTON_BACKGROUND, CENTERED); getSwitchPositionName(SWSRC_SW1 + i),
BUTTON_BACKGROUND, CENTERED);
auto button = new LogicalSwitchButton(window, grid.getFieldSlot(), i); auto button = new LogicalSwitchButton(window, grid.getFieldSlot(), i);
button->setPressHandler([=]() { button->setPressHandler([=]() {
Menu* menu = new Menu(window); Menu* menu = new Menu(window);
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() { editLogicalSwitch(window, i); });
editLogicalSwitch(window, i);
});
if (ls->func) if (ls->func)
menu->addLine(STR_COPY, [=]() { menu->addLine(STR_COPY, [=]() {
clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH; clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH;
@@ -400,7 +402,8 @@ void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex)
storageDirty(EE_MODEL); storageDirty(EE_MODEL);
rebuild(window, i); rebuild(window, i);
}); });
if (ls->func || ls->v1 || ls->v2 || ls->delay || ls->duration || ls->andsw) if (ls->func || ls->v1 || ls->v2 || ls->delay || ls->duration ||
ls->andsw)
menu->addLine(STR_CLEAR, [=]() { menu->addLine(STR_CLEAR, [=]() {
memset(ls, 0, sizeof(LogicalSwitchData)); memset(ls, 0, sizeof(LogicalSwitchData));
storageDirty(EE_MODEL); storageDirty(EE_MODEL);
@@ -408,11 +411,25 @@ void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex)
}); });
return 0; return 0;
}); });
button->setFocusHandler([=](bool focus) {
if (focus) {
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
} else {
txt->setBackgroundColor(FIELD_FRAME_COLOR);
txt->setTextFlags(CENTERED);
}
txt->invalidate();
});
if (focusIndex == i) { if (focusIndex == i) {
button->setFocus(SET_FOCUS_DEFAULT); button->setFocus(SET_FOCUS_DEFAULT);
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
txt->invalidate();
} }
txt->setHeight(button->height());
grid.spacer(button->height() + 5); grid.spacer(button->height() + 5);
} }
} }
@@ -29,7 +29,7 @@ public:
virtual void build(FormWindow * window) override virtual void build(FormWindow * window) override
{ {
build(window, -1); build(window, 0);
} }
protected: protected:
+84 -54
View File
@@ -53,12 +53,11 @@ bool reachMixesLimit()
return false; return false;
} }
class MixEditWindow : public Page { class MixEditWindow : public Page
{
public: public:
MixEditWindow(int8_t channel, uint8_t mixIndex) : MixEditWindow(int8_t channel, uint8_t mixIndex) :
Page(ICON_MODEL_MIXER), Page(ICON_MODEL_MIXER), channel(channel), mixIndex(mixIndex)
channel(channel),
mixIndex(mixIndex)
{ {
buildBody(&body); buildBody(&body);
buildHeader(&header); buildHeader(&header);
@@ -71,8 +70,14 @@ class MixEditWindow : public Page {
void buildHeader(Window *window) void buildHeader(Window *window)
{ {
new StaticText(window, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT}, STR_MIXES, 0, MENU_COLOR); new StaticText(window,
new StaticText(window, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT, LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT}, getSourceString(MIXSRC_CH1 + channel), 0, MENU_COLOR); {PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT,
PAGE_LINE_HEIGHT},
STR_MIXES, 0, MENU_COLOR);
new StaticText(window,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT,
LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT},
getSourceString(MIXSRC_CH1 + channel), 0, MENU_COLOR);
} }
void buildBody(FormWindow *window) void buildBody(FormWindow *window)
@@ -84,23 +89,28 @@ class MixEditWindow : public Page {
// Mix name // Mix name
new StaticText(window, grid.getLabelSlot(), STR_MIXNAME); new StaticText(window, grid.getLabelSlot(), STR_MIXNAME);
new RadioTextEdit(window, grid.getFieldSlot(), mix->name, sizeof(mix->name)); new RadioTextEdit(window, grid.getFieldSlot(), mix->name,
sizeof(mix->name));
grid.nextLine(); grid.nextLine();
// Source // Source
new StaticText(window, grid.getLabelSlot(), STR_SOURCE); new StaticText(window, grid.getLabelSlot(), STR_SOURCE);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST, GET_SET_DEFAULT(mix->srcRaw)); new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST,
GET_SET_DEFAULT(mix->srcRaw));
grid.nextLine(); grid.nextLine();
// Weight // Weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT); new StaticText(window, grid.getLabelSlot(), STR_WEIGHT);
auto gvar = new GVarNumberEdit(window, grid.getFieldSlot(), MIX_WEIGHT_MIN, MIX_WEIGHT_MAX, GET_SET_DEFAULT(mix->weight)); auto gvar =
new GVarNumberEdit(window, grid.getFieldSlot(), MIX_WEIGHT_MIN,
MIX_WEIGHT_MAX, GET_SET_DEFAULT(mix->weight));
gvar->setSuffix("%"); gvar->setSuffix("%");
grid.nextLine(); grid.nextLine();
// Offset // Offset
new StaticText(window, grid.getLabelSlot(), STR_OFFSET); new StaticText(window, grid.getLabelSlot(), STR_OFFSET);
gvar = new GVarNumberEdit(window, grid.getFieldSlot(), MIX_OFFSET_MIN, MIX_OFFSET_MAX, GET_SET_DEFAULT(mix->offset)); gvar = new GVarNumberEdit(window, grid.getFieldSlot(), MIX_OFFSET_MIN,
MIX_OFFSET_MAX, GET_SET_DEFAULT(mix->offset));
gvar->setSuffix("%"); gvar->setSuffix("%");
grid.nextLine(); grid.nextLine();
@@ -111,15 +121,16 @@ class MixEditWindow : public Page {
// Curve // Curve
new StaticText(&body, grid.getLabelSlot(), STR_CURVE); new StaticText(&body, grid.getLabelSlot(), STR_CURVE);
new Choice(&body, grid.getFieldSlot(2, 0), "\004DiffExpoFuncCstm", 0, CURVE_REF_CUSTOM, new Choice(&body, grid.getFieldSlot(2, 0), "\004DiffExpoFuncCstm", 0,
GET_DEFAULT(mix->curve.type), CURVE_REF_CUSTOM, GET_DEFAULT(mix->curve.type),
[=](int32_t newValue) { [=](int32_t newValue) {
mix->curve.type = newValue; mix->curve.type = newValue;
mix->curve.value = 0; mix->curve.value = 0;
SET_DIRTY(); SET_DIRTY();
updateCurveParamField(mix); updateCurveParamField(mix);
}); });
curveParamField = new FormGroup(&body, grid.getFieldSlot(2, 1), FORM_FORWARD_FOCUS); curveParamField =
new FormGroup(&body, grid.getFieldSlot(2, 1), FORM_FORWARD_FOCUS);
updateCurveParamField(mix); updateCurveParamField(mix);
grid.nextLine(); grid.nextLine();
@@ -127,9 +138,9 @@ class MixEditWindow : public Page {
new StaticText(window, grid.getLabelSlot(), STR_FLMODE); new StaticText(window, grid.getLabelSlot(), STR_FLMODE);
for (uint8_t i = 0; i < MAX_FLIGHT_MODES; i++) { for (uint8_t i = 0; i < MAX_FLIGHT_MODES; i++) {
char fm[2] = {char('0' + i), '\0'}; char fm[2] = {char('0' + i), '\0'};
if (i > 0 && (i % 4) == 0) if (i > 0 && (i % 4) == 0) grid.nextLine();
grid.nextLine(); new TextButton(
new TextButton(window, grid.getFieldSlot(4, i % 4), fm, window, grid.getFieldSlot(4, i % 4), fm,
[=]() -> uint8_t { [=]() -> uint8_t {
BFBIT_FLIP(mix->flightModes, bfBit<uint8_t>(i)); BFBIT_FLIP(mix->flightModes, bfBit<uint8_t>(i));
SET_DIRTY(); SET_DIRTY();
@@ -141,26 +152,28 @@ class MixEditWindow : public Page {
// Switch // Switch
new StaticText(window, grid.getLabelSlot(), STR_SWITCH); new StaticText(window, grid.getLabelSlot(), STR_SWITCH);
new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, GET_SET_DEFAULT(mix->swtch)); new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST_IN_MIXES,
SWSRC_LAST_IN_MIXES, GET_SET_DEFAULT(mix->swtch));
grid.nextLine(); grid.nextLine();
// Warning // Warning
new StaticText(window, grid.getLabelSlot(), STR_MIXWARNING); new StaticText(window, grid.getLabelSlot(), STR_MIXWARNING);
auto edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, 3, GET_SET_DEFAULT(mix->mixWarn)); auto edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, 3,
GET_SET_DEFAULT(mix->mixWarn));
edit->setZeroText(STR_OFF); edit->setZeroText(STR_OFF);
grid.nextLine(); grid.nextLine();
// Multiplex // Multiplex
new StaticText(window, grid.getLabelSlot(), STR_MULTPX); new StaticText(window, grid.getLabelSlot(), STR_MULTPX);
new Choice(window, grid.getFieldSlot(), STR_VMLTPX, 0, 2, GET_SET_DEFAULT(mix->mltpx)); new Choice(window, grid.getFieldSlot(), STR_VMLTPX, 0, 2,
GET_SET_DEFAULT(mix->mltpx));
grid.nextLine(); grid.nextLine();
// Delay up // Delay up
new StaticText(window, grid.getLabelSlot(), STR_DELAYUP); new StaticText(window, grid.getLabelSlot(), STR_DELAYUP);
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX, edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
GET_DEFAULT(mix->delayUp), GET_DEFAULT(mix->delayUp),
SET_VALUE(mix->delayUp, newValue), SET_VALUE(mix->delayUp, newValue), 0, PREC1);
0, PREC1);
edit->setSuffix("s"); edit->setSuffix("s");
grid.nextLine(); grid.nextLine();
@@ -168,8 +181,7 @@ class MixEditWindow : public Page {
new StaticText(window, grid.getLabelSlot(), STR_DELAYDOWN); new StaticText(window, grid.getLabelSlot(), STR_DELAYDOWN);
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX, edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
GET_DEFAULT(mix->delayDown), GET_DEFAULT(mix->delayDown),
SET_VALUE(mix->delayDown, newValue), SET_VALUE(mix->delayDown, newValue), 0, PREC1);
0, PREC1);
edit->setSuffix("s"); edit->setSuffix("s");
grid.nextLine(); grid.nextLine();
@@ -177,8 +189,7 @@ class MixEditWindow : public Page {
new StaticText(window, grid.getLabelSlot(), STR_SLOWUP); new StaticText(window, grid.getLabelSlot(), STR_SLOWUP);
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX, edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
GET_DEFAULT(mix->speedUp), GET_DEFAULT(mix->speedUp),
SET_VALUE(mix->speedUp, newValue), SET_VALUE(mix->speedUp, newValue), 0, PREC1);
0, PREC1);
edit->setSuffix("s"); edit->setSuffix("s");
grid.nextLine(); grid.nextLine();
@@ -186,8 +197,7 @@ class MixEditWindow : public Page {
new StaticText(window, grid.getLabelSlot(), STR_SLOWDOWN); new StaticText(window, grid.getLabelSlot(), STR_SLOWDOWN);
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX, edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
GET_DEFAULT(mix->speedDown), GET_DEFAULT(mix->speedDown),
SET_VALUE(mix->speedDown, newValue), SET_VALUE(mix->speedDown, newValue), 0, PREC1);
0, PREC1);
edit->setSuffix("s"); edit->setSuffix("s");
grid.nextLine(); grid.nextLine();
@@ -199,34 +209,36 @@ class MixEditWindow : public Page {
{ {
curveParamField->clear(); curveParamField->clear();
const rect_t rect = {0, 0, curveParamField->width(), curveParamField->height()}; const rect_t rect = {0, 0, curveParamField->width(),
curveParamField->height()};
switch (line->curve.type) { switch (line->curve.type) {
case CURVE_REF_DIFF: case CURVE_REF_DIFF:
case CURVE_REF_EXPO: case CURVE_REF_EXPO: {
{ GVarNumberEdit *edit =
GVarNumberEdit * edit = new GVarNumberEdit(curveParamField, rect, -100, 100, GET_SET_DEFAULT(line->curve.value)); new GVarNumberEdit(curveParamField, rect, -100, 100,
GET_SET_DEFAULT(line->curve.value));
edit->setSuffix("%"); edit->setSuffix("%");
break; break;
} }
case CURVE_REF_FUNC: case CURVE_REF_FUNC:
new Choice(curveParamField, rect, STR_VCURVEFUNC, 0, CURVE_BASE - 1, GET_SET_DEFAULT(line->curve.value)); new Choice(curveParamField, rect, STR_VCURVEFUNC, 0, CURVE_BASE - 1,
GET_SET_DEFAULT(line->curve.value));
break; break;
case CURVE_REF_CUSTOM: case CURVE_REF_CUSTOM: {
{ auto choice = new Choice(curveParamField, rect, -MAX_CURVES, MAX_CURVES,
auto choice = new Choice(curveParamField, rect, -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value)); GET_SET_DEFAULT(line->curve.value));
choice->setTextHandler([](int value) { choice->setTextHandler([](int value) { return getCurveString(value); });
return getCurveString(value);
});
break; break;
} }
} }
} }
}; };
class MixLineButton : public CommonInputOrMixButton { class MixLineButton : public CommonInputOrMixButton
{
public: public:
MixLineButton(FormGroup *parent, const rect_t &rect, uint8_t index) : MixLineButton(FormGroup *parent, const rect_t &rect, uint8_t index) :
CommonInputOrMixButton(parent, rect, index) CommonInputOrMixButton(parent, rect, index)
@@ -237,18 +249,13 @@ class MixLineButton : public CommonInputOrMixButton {
} }
} }
bool isActive() const override bool isActive() const override { return isMixActive(index); }
{
return isMixActive(index);
}
void paintBody(BitmapBuffer *dc) override void paintBody(BitmapBuffer *dc) override
{ {
const MixData &line = g_model.mixData[index]; const MixData &line = g_model.mixData[index];
LcdFlags textColor = DEFAULT_COLOR; LcdFlags textColor = DEFAULT_COLOR;
if (hasFocus())
textColor = FOCUS_COLOR;
// first line ... // first line ...
drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, line.weight, drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, line.weight,
@@ -291,7 +298,8 @@ void insertMix(uint8_t idx, uint8_t channel)
mix->destCh = channel; mix->destCh = channel;
mix->srcRaw = channel + 1; mix->srcRaw = channel + 1;
if (!isSourceAvailable(mix->srcRaw)) { if (!isSourceAvailable(mix->srcRaw)) {
mix->srcRaw = (channel > 3 ? MIXSRC_Rud - 1 + channel : MIXSRC_Rud - 1 + channelOrder(channel)); mix->srcRaw = (channel > 3 ? MIXSRC_Rud - 1 + channel
: MIXSRC_Rud - 1 + channelOrder(channel));
while (!isSourceAvailable(mix->srcRaw)) { while (!isSourceAvailable(mix->srcRaw)) {
mix->srcRaw += 1; mix->srcRaw += 1;
} }
@@ -339,15 +347,15 @@ void ModelMixesPage::build(FormWindow * window, int8_t focusMixIndex)
MixData * mix = g_model.mixData; MixData * mix = g_model.mixData;
for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) { for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) {
if (mixIndex < MAX_MIXERS && mix->srcRaw > 0 && mix->destCh == ch) { if (mixIndex < MAX_MIXERS && mix->srcRaw > 0 && mix->destCh == ch) {
coord_t h = grid.getWindowHeight();
auto txt = new StaticText(window, grid.getLabelSlot(), auto txt = new StaticText(window, grid.getLabelSlot(),
getSourceString(MIXSRC_CH1 + ch), 0, getSourceString(MIXSRC_CH1 + ch),
CENTERED); BUTTON_BACKGROUND, CENTERED);
txt->setBackgroundColor(FIELD_BGCOLOR);
uint8_t count = 0; uint8_t count = 0;
while (mixIndex < MAX_MIXERS && mix->srcRaw > 0 && mix->destCh == ch) { while (mixIndex < MAX_MIXERS && mix->srcRaw > 0 && mix->destCh == ch) {
Button * button = new MixLineButton(window, grid.getFieldSlot(), mixIndex); Button * button = new MixLineButton(window, grid.getFieldSlot(), mixIndex);
if (focusMixIndex == mixIndex)
button->setFocus(SET_FOCUS_DEFAULT);
button->setPressHandler([=]() -> uint8_t { button->setPressHandler([=]() -> uint8_t {
button->bringToTop(); button->bringToTop();
Menu * menu = new Menu(window); Menu * menu = new Menu(window);
@@ -396,16 +404,38 @@ void ModelMixesPage::build(FormWindow * window, int8_t focusMixIndex)
}); });
return 0; return 0;
}); });
button->setFocusHandler([=](bool focus) {
if (focus) {
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
} else {
txt->setBackgroundColor(FIELD_FRAME_COLOR);
txt->setTextFlags(CENTERED);
}
txt->invalidate();
});
if (count++ > 0) { if (focusMixIndex == mixIndex) {
new StaticBitmap(window, {35, button->top() + (button->height() - 18) / 2, 25, 17}, mixerMultiplexBitmap[mix->mltpx]); button->setFocus(SET_FOCUS_DEFAULT);
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
txt->invalidate();
} }
grid.spacer(button->height() - 2); if (count++ > 0) {
new StaticBitmap(
window, {35, button->top() + (button->height() - 18) / 2, 25, 17},
mixerMultiplexBitmap[mix->mltpx]);
}
grid.spacer(button->height() - 1);
++mixIndex; ++mixIndex;
++mix; ++mix;
} }
h = grid.getWindowHeight() - h + 1;
txt->setHeight(h);
grid.spacer(7); grid.spacer(7);
} }
else { else {
+20 -10
View File
@@ -129,11 +129,6 @@ class OutputLineButton : public Button {
LcdFlags textColor = DEFAULT_COLOR; LcdFlags textColor = DEFAULT_COLOR;
LcdFlags bgColor = FIELD_BGCOLOR; LcdFlags bgColor = FIELD_BGCOLOR;
if (hasFocus()) {
textColor = FOCUS_COLOR;
bgColor = FOCUS_BGCOLOR;
}
dc->drawSolidFilledRect(0, 0, width(), height(), bgColor); dc->drawSolidFilledRect(0, 0, width(), height(), bgColor);
// first line // first line
@@ -165,8 +160,10 @@ class OutputLineButton : public Button {
} }
// bounding rect // bounding rect
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, if (hasFocus())
hasFocus() ? FOCUS_BGCOLOR : FIELD_FRAME_COLOR); dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
else
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, FIELD_FRAME_COLOR);
} }
protected: protected:
@@ -197,9 +194,8 @@ void ModelOutputsPage::build(FormWindow * window, int8_t focusChannel)
// Channel label // Channel label
auto txt = new StaticText(window, grid.getLabelSlot(), auto txt = new StaticText(window, grid.getLabelSlot(),
getSourceString(MIXSRC_CH1 + ch), 0, getSourceString(MIXSRC_CH1 + ch),
CENTERED); BUTTON_BACKGROUND, CENTERED);
txt->setBackgroundColor(FIELD_BGCOLOR);
// Channel settings // Channel settings
Button * button = new OutputLineButton(window, grid.getFieldSlot(), output); Button * button = new OutputLineButton(window, grid.getFieldSlot(), output);
@@ -231,11 +227,25 @@ void ModelOutputsPage::build(FormWindow * window, int8_t focusChannel)
}); });
return 0; return 0;
}); });
button->setFocusHandler([=](bool focus) {
if (focus) {
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
} else {
txt->setBackgroundColor(FIELD_FRAME_COLOR);
txt->setTextFlags(CENTERED);
}
txt->invalidate();
});
if (focusChannel == ch) { if (focusChannel == ch) {
button->setFocus(SET_FOCUS_DEFAULT); button->setFocus(SET_FOCUS_DEFAULT);
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
txt->invalidate();
} }
txt->setHeight(button->height());
grid.spacer(button->height() + 5); grid.spacer(button->height() + 5);
} }
+1 -1
View File
@@ -29,7 +29,7 @@ class ModelOutputsPage: public PageTab {
virtual void build(FormWindow * window) override virtual void build(FormWindow * window) override
{ {
build(window, -1); build(window, 0);
} }
protected: protected:
+203 -104
View File
@@ -24,10 +24,12 @@
#define SET_DIRTY() storageDirty(functions == g_model.customFn ? EE_MODEL : EE_GENERAL) #define SET_DIRTY() storageDirty(functions == g_model.customFn ? EE_MODEL : EE_GENERAL)
class SpecialFunctionEditPage : public Page { class SpecialFunctionEditPage : public Page
{
public: public:
SpecialFunctionEditPage(CustomFunctionData *functions, uint8_t index) : SpecialFunctionEditPage(CustomFunctionData *functions, uint8_t index) :
Page(functions == g_model.customFn ? ICON_MODEL_SPECIAL_FUNCTIONS : ICON_RADIO_GLOBAL_FUNCTIONS), Page(functions == g_model.customFn ? ICON_MODEL_SPECIAL_FUNCTIONS
: ICON_RADIO_GLOBAL_FUNCTIONS),
functions(functions), functions(functions),
index(index) index(index)
{ {
@@ -44,7 +46,12 @@ class SpecialFunctionEditPage : public Page {
bool isActive() const bool isActive() const
{ {
return ((functions == g_model.customFn ? modelFunctionsContext.activeSwitches : globalFunctionsContext.activeSwitches) & ((MASK_CFN_TYPE)1 << index) ? 1 : 0); return ((functions == g_model.customFn
? modelFunctionsContext.activeSwitches
: globalFunctionsContext.activeSwitches) &
((MASK_CFN_TYPE)1 << index)
? 1
: 0);
} }
void checkEvents() override void checkEvents() override
@@ -52,15 +59,25 @@ class SpecialFunctionEditPage : public Page {
Page::checkEvents(); Page::checkEvents();
if (active != isActive()) { if (active != isActive()) {
invalidate(); invalidate();
headerSF->setTextFlags(isActive() ? FONT(BOLD) |HIGHLIGHT_COLOR : MENU_COLOR); headerSF->setTextFlags(isActive() ? FONT(BOLD) | HIGHLIGHT_COLOR
: MENU_COLOR);
active = !active; active = !active;
} }
} }
void buildHeader(Window *window) void buildHeader(Window *window)
{ {
new StaticText(window, { PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT, 20 }, functions == g_model.customFn ? STR_MENUCUSTOMFUNC : STR_MENUSPECIALFUNCS, 0, MENU_COLOR); new StaticText(
headerSF = new StaticText(window, { PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT, LCD_W - PAGE_TITLE_LEFT, 20 }, (functions == g_model.customFn ? "SF" : "GF" ) + std::to_string(index), 0, MENU_COLOR); window, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT, 20},
functions == g_model.customFn ? STR_MENUCUSTOMFUNC
: STR_MENUSPECIALFUNCS,
0, MENU_COLOR);
headerSF = new StaticText(
window,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT,
LCD_W - PAGE_TITLE_LEFT, 20},
(functions == g_model.customFn ? "SF" : "GF") + std::to_string(index),
0, MENU_COLOR);
} }
void updateSpecialFunctionOneWindow() void updateSpecialFunctionOneWindow()
@@ -75,24 +92,32 @@ class SpecialFunctionEditPage : public Page {
switch (func) { switch (func) {
case FUNC_OVERRIDE_CHANNEL: case FUNC_OVERRIDE_CHANNEL:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_CH); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_CH);
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 1, MAX_OUTPUT_CHANNELS, GET_SET_VALUE_WITH_OFFSET(CFN_CH_INDEX(cfn), 1)); new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 1,
MAX_OUTPUT_CHANNELS,
GET_SET_VALUE_WITH_OFFSET(CFN_CH_INDEX(cfn), 1));
grid.nextLine(); grid.nextLine();
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), -100, 100,
GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_TRAINER: { case FUNC_TRAINER: {
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
auto choice = new Choice(specialFunctionOneWindow, grid.getFieldSlot(), 0,NUM_STICKS + 1,GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
auto choice =
new Choice(specialFunctionOneWindow, grid.getFieldSlot(), 0,
NUM_STICKS + 1, GET_SET_DEFAULT(CFN_PARAM(cfn)));
choice->setTextHandler([=](int32_t value) { choice->setTextHandler([=](int32_t value) {
if (value == 0) if (value == 0)
return std::string(STR_STICKS); return std::string(STR_STICKS);
else if (value == NUM_STICKS + 1) else if (value == NUM_STICKS + 1)
return std::string(STR_CHANS); return std::string(STR_CHANS);
else else
return TEXT_AT_INDEX(STR_VSRCRAW, value);; return TEXT_AT_INDEX(STR_VSRCRAW, value);
;
}); });
grid.nextLine(); grid.nextLine();
break; break;
@@ -100,8 +125,10 @@ class SpecialFunctionEditPage : public Page {
case FUNC_RESET: case FUNC_RESET:
if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) { if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) {
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_RESET); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
auto choice = new Choice(specialFunctionOneWindow, grid.getFieldSlot(), 0, STR_RESET);
auto choice = new Choice(
specialFunctionOneWindow, grid.getFieldSlot(), 0,
FUNC_RESET_PARAM_FIRST_TELEM + lastUsedTelemetryIndex(), FUNC_RESET_PARAM_FIRST_TELEM + lastUsedTelemetryIndex(),
GET_SET_DEFAULT(CFN_PARAM(cfn))); GET_SET_DEFAULT(CFN_PARAM(cfn)));
choice->setAvailableHandler(isSourceAvailableInResetSpecialFunction); choice->setAvailableHandler(isSourceAvailableInResetSpecialFunction);
@@ -109,87 +136,117 @@ class SpecialFunctionEditPage : public Page {
if (value < FUNC_RESET_PARAM_FIRST_TELEM) if (value < FUNC_RESET_PARAM_FIRST_TELEM)
return TEXT_AT_INDEX(STR_VFSWRESET, value); return TEXT_AT_INDEX(STR_VFSWRESET, value);
else else
return std::string(g_model.telemetrySensors[value - FUNC_RESET_PARAM_FIRST_TELEM].label, TELEM_LABEL_LEN); return std::string(
g_model.telemetrySensors[value - FUNC_RESET_PARAM_FIRST_TELEM]
.label,
TELEM_LABEL_LEN);
}); });
grid.nextLine(); grid.nextLine();
} }
break; break;
case FUNC_VOLUME: case FUNC_VOLUME:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VOLUME); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VOLUME);
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0,
MIXSRC_LAST_CH, GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_BACKLIGHT: case FUNC_BACKLIGHT:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0,
MIXSRC_LAST_CH, GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_PLAY_SOUND: case FUNC_PLAY_SOUND:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new Choice(specialFunctionOneWindow, grid.getFieldSlot(), STR_FUNCSOUNDS, 0, STR_VALUE);
AU_SPECIAL_SOUND_LAST - AU_SPECIAL_SOUND_FIRST - 1, GET_SET_DEFAULT(CFN_PARAM(cfn))); new Choice(specialFunctionOneWindow, grid.getFieldSlot(),
STR_FUNCSOUNDS, 0,
AU_SPECIAL_SOUND_LAST - AU_SPECIAL_SOUND_FIRST - 1,
GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_PLAY_TRACK: case FUNC_PLAY_TRACK:
case FUNC_BACKGND_MUSIC: case FUNC_BACKGND_MUSIC:
case FUNC_PLAY_SCRIPT: case FUNC_PLAY_SCRIPT:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new FileChoice(specialFunctionOneWindow, grid.getFieldSlot(), STR_VALUE);
func == FUNC_PLAY_SCRIPT ? SCRIPTS_FUNCS_PATH : std::string(SOUNDS_PATH, SOUNDS_PATH_LNG_OFS) + new FileChoice(
specialFunctionOneWindow, grid.getFieldSlot(),
func == FUNC_PLAY_SCRIPT
? SCRIPTS_FUNCS_PATH
: std::string(SOUNDS_PATH, SOUNDS_PATH_LNG_OFS) +
std::string(currentLanguagePack->id, 2), std::string(currentLanguagePack->id, 2),
func == FUNC_PLAY_SCRIPT ? SCRIPTS_EXT : SOUNDS_EXT, func == FUNC_PLAY_SCRIPT ? SCRIPTS_EXT : SOUNDS_EXT,
sizeof(cfn->play.name), sizeof(cfn->play.name),
[=]() { [=]() { return std::string(cfn->play.name, ZLEN(cfn->play.name)); },
return std::string(cfn->play.name, ZLEN(cfn->play.name));
},
[=](std::string newValue) { [=](std::string newValue) {
strncpy(cfn->play.name, newValue.c_str(), sizeof(cfn->play.name)); strncpy(cfn->play.name, newValue.c_str(), sizeof(cfn->play.name));
SET_DIRTY(); SET_DIRTY();
}, true); // strip extension },
true); // strip extension
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_SET_TIMER: { case FUNC_SET_TIMER: {
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_TIMER); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
auto timerchoice = new Choice(specialFunctionOneWindow, grid.getFieldSlot(), 0, TIMERS - 1, GET_SET_DEFAULT(CFN_TIMER_INDEX(cfn))); STR_TIMER);
auto timerchoice =
new Choice(specialFunctionOneWindow, grid.getFieldSlot(), 0,
TIMERS - 1, GET_SET_DEFAULT(CFN_TIMER_INDEX(cfn)));
timerchoice->setTextHandler([](int32_t value) { timerchoice->setTextHandler([](int32_t value) {
return std::string(STR_TIMER) + std::to_string(value + 1); return std::string(STR_TIMER) + std::to_string(value + 1);
}); });
grid.nextLine(); grid.nextLine();
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new TimeEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 9 * 60 * 60 - 1, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
new TimeEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0,
9 * 60 * 60 - 1, GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
} }
case FUNC_SET_FAILSAFE: case FUNC_SET_FAILSAFE:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_MODULE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new Choice(specialFunctionOneWindow, grid.getFieldSlot(), "\004Int.Ext.", 0, NUM_MODULES - 1, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_MODULE);
new Choice(specialFunctionOneWindow, grid.getFieldSlot(),
"\004Int.Ext.", 0, NUM_MODULES - 1,
GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_PLAY_VALUE: case FUNC_PLAY_VALUE:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0,
MIXSRC_LAST_TELEM, GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_HAPTIC: case FUNC_HAPTIC:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 3, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 3,
GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine(); grid.nextLine();
break; break;
case FUNC_LOGS: { case FUNC_LOGS: {
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(),
auto edit = new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 255, GET_SET_DEFAULT(CFN_PARAM(cfn))); STR_VALUE);
edit->setDisplayHandler([=](BitmapBuffer * dc, LcdFlags flags, int32_t value) { auto edit =
dc->drawNumber(2, 2, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s"); new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0,
255, GET_SET_DEFAULT(CFN_PARAM(cfn)));
edit->setDisplayHandler(
[=](BitmapBuffer *dc, LcdFlags flags, int32_t value) {
dc->drawNumber(2, 2, CFN_PARAM(cfn), PREC1,
sizeof(CFN_PARAM(cfn)), nullptr, "s");
}); });
break; break;
} }
@@ -197,19 +254,23 @@ class SpecialFunctionEditPage : public Page {
if (HAS_ENABLE_PARAM(func)) { if (HAS_ENABLE_PARAM(func)) {
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_ENABLE); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_ENABLE);
new CheckBox(specialFunctionOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(CFN_ACTIVE(cfn))); new CheckBox(specialFunctionOneWindow, grid.getFieldSlot(),
GET_SET_DEFAULT(CFN_ACTIVE(cfn)));
grid.nextLine(); grid.nextLine();
} } else if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
else if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_REPEAT); new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_REPEAT);
auto repeat = new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(2, 1), -1, 60/CFN_PLAY_REPEAT_MUL, GET_SET_DEFAULT(CFN_PLAY_REPEAT(cfn))); auto repeat = new NumberEdit(
repeat->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) { specialFunctionOneWindow, grid.getFieldSlot(2, 1), -1,
60 / CFN_PLAY_REPEAT_MUL, GET_SET_DEFAULT(CFN_PLAY_REPEAT(cfn)));
repeat->setDisplayHandler(
[](BitmapBuffer *dc, LcdFlags flags, int32_t value) {
if (value == 0) if (value == 0)
dc->drawText(3, 0, "1x", flags); dc->drawText(3, 0, "1x", flags);
else if (value == CFN_PLAY_REPEAT_NOSTART) else if (value == CFN_PLAY_REPEAT_NOSTART)
dc->drawText(3, 0, "!1x", flags); dc->drawText(3, 0, "!1x", flags);
else else
dc->drawNumber(3, 0, value * CFN_PLAY_REPEAT_MUL, flags, 0, nullptr, "s"); dc->drawNumber(3, 0, value * CFN_PLAY_REPEAT_MUL, flags, 0,
nullptr, "s");
}); });
grid.nextLine(); grid.nextLine();
} }
@@ -227,17 +288,21 @@ class SpecialFunctionEditPage : public Page {
// Switch // Switch
new StaticText(window, grid.getLabelSlot(), STR_SWITCH); new StaticText(window, grid.getLabelSlot(), STR_SWITCH);
auto switchChoice = new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST, SWSRC_LAST, GET_SET_DEFAULT(CFN_SWITCH(cfn))); auto switchChoice =
new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST, SWSRC_LAST,
GET_SET_DEFAULT(CFN_SWITCH(cfn)));
switchChoice->setAvailableHandler([=](int value) { switchChoice->setAvailableHandler([=](int value) {
return (functions == g_model.customFn ? isSwitchAvailable(value, ModelCustomFunctionsContext) return (functions == g_model.customFn
: isSwitchAvailable(value, ? isSwitchAvailable(value, ModelCustomFunctionsContext)
GeneralCustomFunctionsContext)); : isSwitchAvailable(value, GeneralCustomFunctionsContext));
}); });
grid.nextLine(); grid.nextLine();
// Function // Function
new StaticText(window, grid.getLabelSlot(), STR_FUNC); new StaticText(window, grid.getLabelSlot(), STR_FUNC);
auto functionChoice = new Choice(window, grid.getFieldSlot(), STR_VFSWFUNC, 0, FUNC_MAX - 1, GET_DEFAULT(CFN_FUNC(cfn))); auto functionChoice =
new Choice(window, grid.getFieldSlot(), STR_VFSWFUNC, 0, FUNC_MAX - 1,
GET_DEFAULT(CFN_FUNC(cfn)));
functionChoice->setSetValueHandler([=](int32_t newValue) { functionChoice->setSetValueHandler([=](int32_t newValue) {
CFN_FUNC(cfn) = newValue; CFN_FUNC(cfn) = newValue;
CFN_RESET(cfn); CFN_RESET(cfn);
@@ -249,7 +314,8 @@ class SpecialFunctionEditPage : public Page {
}); });
grid.nextLine(); grid.nextLine();
specialFunctionOneWindow = new FormGroup(window, {0, grid.getWindowHeight(), LCD_W, 0}, FORM_FORWARD_FOCUS); specialFunctionOneWindow = new FormGroup(
window, {0, grid.getWindowHeight(), LCD_W, 0}, FORM_FORWARD_FOCUS);
updateSpecialFunctionOneWindow(); updateSpecialFunctionOneWindow();
grid.addWindow(specialFunctionOneWindow); grid.addWindow(specialFunctionOneWindow);
} }
@@ -261,31 +327,35 @@ static constexpr coord_t col1 = 20;
static constexpr coord_t col2 = (LCD_W - 100) / 3 + col1; static constexpr coord_t col2 = (LCD_W - 100) / 3 + col1;
static constexpr coord_t col3 = ((LCD_W - 100) / 3) * 2 + col1 + 20; static constexpr coord_t col3 = ((LCD_W - 100) / 3) * 2 + col1 + 20;
class SpecialFunctionButton : public Button { class SpecialFunctionButton : public Button
{
public: public:
SpecialFunctionButton(FormWindow * parent, const rect_t &rect, CustomFunctionData * functions, uint8_t index) : SpecialFunctionButton(FormWindow *parent, const rect_t &rect,
Button(parent, rect), CustomFunctionData *functions, uint8_t index) :
functions(functions), Button(parent, rect), functions(functions), index(index)
index(index)
{ {
const CustomFunctionData *cfn = &functions[index]; const CustomFunctionData *cfn = &functions[index];
uint8_t func = CFN_FUNC(cfn); uint8_t func = CFN_FUNC(cfn);
if (!cfn->isEmpty() && if (!cfn->isEmpty() &&
(HAS_ENABLE_PARAM(func) || HAS_REPEAT_PARAM(func) || (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT))) { (HAS_ENABLE_PARAM(func) || HAS_REPEAT_PARAM(func) ||
(func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC ||
func == FUNC_PLAY_SCRIPT))) {
setHeight(line2 + PAGE_LINE_HEIGHT); setHeight(line2 + PAGE_LINE_HEIGHT);
} }
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override { return "SpecialFunctionButton"; }
{
return "SpecialFunctionButton";
}
#endif #endif
bool isActive() const bool isActive() const
{ {
return ((functions == g_model.customFn ? modelFunctionsContext.activeSwitches : globalFunctionsContext.activeSwitches) & ((MASK_CFN_TYPE)1 << index) ? 1 : 0); return ((functions == g_model.customFn
? modelFunctionsContext.activeSwitches
: globalFunctionsContext.activeSwitches) &
((MASK_CFN_TYPE)1 << index)
? 1
: 0);
} }
void checkEvents() override void checkEvents() override
@@ -300,14 +370,14 @@ class SpecialFunctionButton : public Button {
void paintSpecialFunctionLine(BitmapBuffer *dc) void paintSpecialFunctionLine(BitmapBuffer *dc)
{ {
const CustomFunctionData *cfn = &functions[index]; const CustomFunctionData *cfn = &functions[index];
if (functions[index].func == FUNC_OVERRIDE_CHANNEL && functions != g_model.customFn) { if (functions[index].func == FUNC_OVERRIDE_CHANNEL &&
functions != g_model.customFn) {
functions[index].func = FUNC_OVERRIDE_CHANNEL + 1; functions[index].func = FUNC_OVERRIDE_CHANNEL + 1;
} }
uint8_t func = CFN_FUNC(cfn); uint8_t func = CFN_FUNC(cfn);
drawSwitch(dc, col1, line1, CFN_SWITCH(cfn), 0); drawSwitch(dc, col1, line1, CFN_SWITCH(cfn), 0);
if (cfn->isEmpty()) if (cfn->isEmpty()) return;
return;
dc->drawTextAtIndex(col2, line1, STR_VFSWFUNC, func, 0); dc->drawTextAtIndex(col2, line1, STR_VFSWFUNC, func, 0);
int16_t val_min = 0; int16_t val_min = 0;
@@ -321,15 +391,18 @@ class SpecialFunctionButton : public Button {
break; break;
case FUNC_TRAINER: case FUNC_TRAINER:
drawSource(dc, col1, line2, CFN_CH_INDEX(cfn) == 0 ? 0 : MIXSRC_Rud + CFN_CH_INDEX(cfn) - 1); drawSource(
dc, col1, line2,
CFN_CH_INDEX(cfn) == 0 ? 0 : MIXSRC_Rud + CFN_CH_INDEX(cfn) - 1);
break; break;
case FUNC_RESET: case FUNC_RESET:
if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) { if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) {
dc->drawTextAtIndex(col1, line2, STR_VFSWRESET, CFN_PARAM(cfn)); dc->drawTextAtIndex(col1, line2, STR_VFSWRESET, CFN_PARAM(cfn));
} } else {
else { TelemetrySensor *sensor =
TelemetrySensor * sensor = &g_model.telemetrySensors[CFN_PARAM(cfn) - FUNC_RESET_PARAM_FIRST_TELEM]; &g_model.telemetrySensors[CFN_PARAM(cfn) -
FUNC_RESET_PARAM_FIRST_TELEM];
dc->drawSizedText(col1, line2, sensor->label, TELEM_LABEL_LEN); dc->drawSizedText(col1, line2, sensor->label, TELEM_LABEL_LEN);
} }
break; break;
@@ -350,13 +423,15 @@ class SpecialFunctionButton : public Button {
case FUNC_BACKGND_MUSIC: case FUNC_BACKGND_MUSIC:
case FUNC_PLAY_SCRIPT: case FUNC_PLAY_SCRIPT:
if (ZEXIST(cfn->play.name)) if (ZEXIST(cfn->play.name))
dc->drawSizedText(col1, line2, cfn->play.name, sizeof(cfn->play.name), 0); dc->drawSizedText(col1, line2, cfn->play.name, sizeof(cfn->play.name),
0);
else else
dc->drawTextAtIndex(col1, line2, STR_VCSWFUNC, 0, 0); dc->drawTextAtIndex(col1, line2, STR_VCSWFUNC, 0, 0);
break; break;
case FUNC_SET_TIMER: case FUNC_SET_TIMER:
drawStringWithIndex(dc, col1, line2, STR_TIMER, CFN_TIMER_INDEX(cfn) + 1, 0); drawStringWithIndex(dc, col1, line2, STR_TIMER,
CFN_TIMER_INDEX(cfn) + 1, 0);
break; break;
case FUNC_SET_FAILSAFE: case FUNC_SET_FAILSAFE:
@@ -372,21 +447,21 @@ class SpecialFunctionButton : public Button {
break; break;
case FUNC_LOGS: case FUNC_LOGS:
dc->drawNumber(col3, line1, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s"); dc->drawNumber(col3, line1, CFN_PARAM(cfn), PREC1,
sizeof(CFN_PARAM(cfn)), nullptr, "s");
break; break;
} }
if (HAS_ENABLE_PARAM(func)) { if (HAS_ENABLE_PARAM(func)) {
theme->drawCheckBox(dc, CFN_ACTIVE(cfn), col3, line2); theme->drawCheckBox(dc, CFN_ACTIVE(cfn), col3, line2);
} } else if (HAS_REPEAT_PARAM(func)) {
else if (HAS_REPEAT_PARAM(func)) {
if (CFN_PLAY_REPEAT(cfn) == 0) { if (CFN_PLAY_REPEAT(cfn) == 0) {
dc->drawText(col3, line2, "1x", 0); dc->drawText(col3, line2, "1x", 0);
} } else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
dc->drawText(col3, line2, "!1x", 0); dc->drawText(col3, line2, "!1x", 0);
} } else {
else { dc->drawNumber(col3 + 12, line2,
dc->drawNumber(col3 + 12, line2, CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0 | RIGHT, 0, nullptr, "s"); CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0 | RIGHT, 0,
nullptr, "s");
} }
} }
} }
@@ -394,12 +469,17 @@ class SpecialFunctionButton : public Button {
void paint(BitmapBuffer *dc) override void paint(BitmapBuffer *dc) override
{ {
if (active) if (active)
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, HIGHLIGHT_COLOR); dc->drawSolidFilledRect(0, 0, rect.w, rect.h, HIGHLIGHT_COLOR);
else
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, FIELD_BGCOLOR);
paintSpecialFunctionLine(dc); paintSpecialFunctionLine(dc);
// The bounding rect // The bounding rect
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? CHECKBOX_COLOR : DISABLE_COLOR); if (hasFocus())
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
else
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, FIELD_FRAME_COLOR);
} }
protected: protected:
@@ -409,13 +489,16 @@ class SpecialFunctionButton : public Button {
}; };
SpecialFunctionsPage::SpecialFunctionsPage(CustomFunctionData *functions) : SpecialFunctionsPage::SpecialFunctionsPage(CustomFunctionData *functions) :
PageTab(functions == g_model.customFn ? STR_MENUCUSTOMFUNC : STR_MENUSPECIALFUNCS, PageTab(functions == g_model.customFn ? STR_MENUCUSTOMFUNC
functions == g_model.customFn ? ICON_MODEL_SPECIAL_FUNCTIONS : ICON_RADIO_GLOBAL_FUNCTIONS), : STR_MENUSPECIALFUNCS,
functions == g_model.customFn ? ICON_MODEL_SPECIAL_FUNCTIONS
: ICON_RADIO_GLOBAL_FUNCTIONS),
functions(functions) functions(functions)
{ {
} }
void SpecialFunctionsPage::rebuild(FormWindow * window, int8_t focusSpecialFunctionIndex) void SpecialFunctionsPage::rebuild(FormWindow *window,
int8_t focusSpecialFunctionIndex)
{ {
coord_t scrollPosition = window->getScrollPositionY(); coord_t scrollPosition = window->getScrollPositionY();
window->clear(); window->clear();
@@ -423,12 +506,11 @@ void SpecialFunctionsPage::rebuild(FormWindow * window, int8_t focusSpecialFunct
window->setScrollPositionY(scrollPosition); window->setScrollPositionY(scrollPosition);
} }
void SpecialFunctionsPage::editSpecialFunction(FormWindow * window, uint8_t index) void SpecialFunctionsPage::editSpecialFunction(FormWindow *window,
uint8_t index)
{ {
auto editPage = new SpecialFunctionEditPage(functions, index); auto editPage = new SpecialFunctionEditPage(functions, index);
editPage->setCloseHandler([=]() { editPage->setCloseHandler([=]() { rebuild(window, index); });
rebuild(window, index);
});
} }
void SpecialFunctionsPage::build(FormWindow *window, int8_t focusIndex) void SpecialFunctionsPage::build(FormWindow *window, int8_t focusIndex)
@@ -440,8 +522,7 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex)
Window::clearFocus(); Window::clearFocus();
char s[] = "SFxx"; char s[] = "SFxx";
if (functions == g_eeGeneral.customFn) if (functions == g_eeGeneral.customFn) s[0] = 'G';
s[0] = 'G';
for (uint8_t i = 0; i < MAX_SPECIAL_FUNCTIONS; i++) { for (uint8_t i = 0; i < MAX_SPECIAL_FUNCTIONS; i++) {
CustomFunctionData *cfn = &functions[i]; CustomFunctionData *cfn = &functions[i];
@@ -464,17 +545,16 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex)
return 0; return 0;
}); });
grid.spacer(button->height() + 5); grid.spacer(button->height() + 5);
} } else {
else { auto txt = new StaticText(window, grid.getLabelSlot(), s,
new StaticText(window, grid.getLabelSlot(), s, BUTTON_BACKGROUND, CENTERED); BUTTON_BACKGROUND, CENTERED);
auto button = new SpecialFunctionButton(window, grid.getFieldSlot(), functions, i); auto button =
new SpecialFunctionButton(window, grid.getFieldSlot(), functions, i);
button->setPressHandler([=]() { button->setPressHandler([=]() {
button->bringToTop(); button->bringToTop();
Menu *menu = new Menu(window); Menu *menu = new Menu(window);
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() { editSpecialFunction(window, i); });
editSpecialFunction(window, i);
});
menu->addLine(STR_COPY, [=]() { menu->addLine(STR_COPY, [=]() {
clipboard.type = CLIPBOARD_TYPE_CUSTOM_FUNCTION; clipboard.type = CLIPBOARD_TYPE_CUSTOM_FUNCTION;
clipboard.data.cfn = *cfn; clipboard.data.cfn = *cfn;
@@ -488,7 +568,9 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex)
} }
if (functions[MAX_SPECIAL_FUNCTIONS - 1].isEmpty()) { if (functions[MAX_SPECIAL_FUNCTIONS - 1].isEmpty()) {
menu->addLine(STR_INSERT, [=]() { menu->addLine(STR_INSERT, [=]() {
memmove(cfn + 1, cfn, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData)); memmove(
cfn + 1, cfn,
(MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData));
memset(cfn, 0, sizeof(CustomFunctionData)); memset(cfn, 0, sizeof(CustomFunctionData));
SET_DIRTY(); SET_DIRTY();
rebuild(window, i); rebuild(window, i);
@@ -501,8 +583,11 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex)
for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) { for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) {
if (!functions[j].isEmpty()) { if (!functions[j].isEmpty()) {
menu->addLine(STR_DELETE, [=]() { menu->addLine(STR_DELETE, [=]() {
memmove(cfn, cfn + 1, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData)); memmove(
memset(&functions[MAX_SPECIAL_FUNCTIONS - 1], 0, sizeof(CustomFunctionData)); cfn, cfn + 1,
(MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData));
memset(&functions[MAX_SPECIAL_FUNCTIONS - 1], 0,
sizeof(CustomFunctionData));
SET_DIRTY(); SET_DIRTY();
rebuild(window, i); rebuild(window, i);
}); });
@@ -511,11 +596,25 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex)
} }
return 0; return 0;
}); });
button->setFocusHandler([=](bool focus) {
if (focus) {
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
} else {
txt->setBackgroundColor(FIELD_FRAME_COLOR);
txt->setTextFlags(CENTERED);
}
txt->invalidate();
});
if (focusIndex == i) { if (focusIndex == i) {
button->setFocus(SET_FOCUS_DEFAULT); button->setFocus(SET_FOCUS_DEFAULT);
txt->setBackgroundColor(FOCUS_BGCOLOR);
txt->setTextFlags(FOCUS_COLOR | CENTERED);
txt->invalidate();
} }
txt->setHeight(button->height());
grid.spacer(button->height() + 5); grid.spacer(button->height() + 5);
} }
} }
@@ -31,11 +31,7 @@ class SpecialFunctionsPage: public PageTab {
void build(FormWindow * window) override void build(FormWindow * window) override
{ {
#if defined(HARDWARE_TOUCH)
build(window, -1);
#else
build(window, 0); build(window, 0);
#endif
} }
protected: protected: