feat(color): use curve select button on outputs edit page to match inputs and mixes (#5524)
This commit is contained in:
@@ -307,7 +307,6 @@ void perMain();
|
|||||||
getvalue_t getValue(mixsrc_t i, bool* valid = nullptr);
|
getvalue_t getValue(mixsrc_t i, bool* valid = nullptr);
|
||||||
|
|
||||||
int8_t getMovedSource(uint8_t min);
|
int8_t getMovedSource(uint8_t min);
|
||||||
#define GET_MOVED_SOURCE(min, max) getMovedSource(min)
|
|
||||||
|
|
||||||
#if defined(FLIGHT_MODES)
|
#if defined(FLIGHT_MODES)
|
||||||
extern uint8_t getFlightMode();
|
extern uint8_t getFlightMode();
|
||||||
|
|||||||
@@ -28,33 +28,27 @@
|
|||||||
|
|
||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||||
|
|
||||||
class CurveChoice : public Choice
|
CurveChoice::CurveChoice(Window* parent, std::function<int()> getRefValue,
|
||||||
{
|
std::function<void(int32_t)> setRefValue, std::function<void(void)> refreshView, mixsrc_t source) :
|
||||||
public:
|
Choice(parent, rect_t{}, -MAX_CURVES, MAX_CURVES, getRefValue, setRefValue),
|
||||||
CurveChoice(Window* parent, std::function<int()> getRefValue, std::function<void(int32_t)> setRefValue, std::function<void(void)> refreshView) :
|
source(source), refreshView(std::move(refreshView))
|
||||||
Choice(parent, rect_t{}, -MAX_CURVES, MAX_CURVES, getRefValue, setRefValue),
|
|
||||||
refreshView(std::move(refreshView))
|
|
||||||
{
|
|
||||||
setTextHandler([](int value) { return getCurveString(value); });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool onLongPress() override
|
|
||||||
{
|
{
|
||||||
if (modelCurvesEnabled()) {
|
setTextHandler([](int value) { return getCurveString(value); });
|
||||||
if (_getValue()) {
|
|
||||||
lv_obj_clear_state(lvobj, LV_STATE_PRESSED);
|
|
||||||
ModelCurvesPage::pushEditCurve(abs(_getValue()) - 1, refreshView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
bool CurveChoice::onLongPress()
|
||||||
std::function<void(void)> refreshView;
|
{
|
||||||
};
|
if (modelCurvesEnabled()) {
|
||||||
|
if (_getValue()) {
|
||||||
|
lv_obj_clear_state(lvobj, LV_STATE_PRESSED);
|
||||||
|
ModelCurvesPage::pushEditCurve(abs(_getValue()) - 1, refreshView, source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
|
CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
|
||||||
std::function<void(int32_t)> setRefValue, int16_t sourceMin,
|
std::function<void(int32_t)> setRefValue, int16_t sourceMin, mixsrc_t source,
|
||||||
std::function<void(void)> refreshView) :
|
std::function<void(void)> refreshView) :
|
||||||
Window(parent, rect), ref(ref), refreshView(std::move(refreshView))
|
Window(parent, rect), ref(ref), refreshView(std::move(refreshView))
|
||||||
{
|
{
|
||||||
@@ -103,7 +97,7 @@ CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
|
|||||||
v.isSource = false;
|
v.isSource = false;
|
||||||
v.value = newValue;
|
v.value = newValue;
|
||||||
setRefValue(v.rawValue);
|
setRefValue(v.rawValue);
|
||||||
}, refreshView);
|
}, refreshView, source);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,17 +22,31 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "choice.h"
|
||||||
|
|
||||||
struct CurveRef;
|
struct CurveRef;
|
||||||
class Choice;
|
|
||||||
class SourceNumberEdit;
|
class SourceNumberEdit;
|
||||||
|
|
||||||
|
class CurveChoice : public Choice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CurveChoice(Window* parent, std::function<int()> getRefValue,
|
||||||
|
std::function<void(int32_t)> setRefValue, std::function<void(void)> refreshView,
|
||||||
|
mixsrc_t source);
|
||||||
|
|
||||||
|
bool onLongPress() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mixsrc_t source;
|
||||||
|
std::function<void(void)> refreshView;
|
||||||
|
};
|
||||||
|
|
||||||
class CurveParam : public Window
|
class CurveParam : public Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
|
CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
|
||||||
std::function<void(int32_t)> setRefValue,
|
std::function<void(int32_t)> setRefValue,
|
||||||
int16_t sourceMin,
|
int16_t sourceMin, mixsrc_t source,
|
||||||
std::function<void(void)> refreshView = nullptr);
|
std::function<void(void)> refreshView = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -32,6 +32,66 @@ static const lv_coord_t default_col_dsc[] = {LV_GRID_CONTENT,
|
|||||||
static const lv_coord_t default_row_dsc[] = {LV_GRID_CONTENT,
|
static const lv_coord_t default_row_dsc[] = {LV_GRID_CONTENT,
|
||||||
LV_GRID_TEMPLATE_LAST};
|
LV_GRID_TEMPLATE_LAST};
|
||||||
|
|
||||||
|
class CurveEdit : public Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CurveEdit(Window* parent, const rect_t& rect, uint8_t index) :
|
||||||
|
Window(parent, rect),
|
||||||
|
preview(
|
||||||
|
this, {0, 0, width(), height()},
|
||||||
|
[=](int x) -> int { return applyCustomCurve(x, index); },
|
||||||
|
[=]() -> int { return getValue(currentSource); }),
|
||||||
|
index(index),
|
||||||
|
current(0)
|
||||||
|
{
|
||||||
|
setWindowFlag(NO_FOCUS);
|
||||||
|
updatePreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCurrentSource(mixsrc_t source)
|
||||||
|
{
|
||||||
|
currentSource = source;
|
||||||
|
if (source)
|
||||||
|
lockSource = true;
|
||||||
|
else
|
||||||
|
lockSource = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updatePreview()
|
||||||
|
{
|
||||||
|
preview.clearPoints();
|
||||||
|
CurveHeader& curve = g_model.curves[index];
|
||||||
|
for (uint8_t i = 0; i < 5 + curve.points; i++) {
|
||||||
|
preview.addPoint(getPoint(index, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Curve preview;
|
||||||
|
uint8_t index;
|
||||||
|
uint8_t current;
|
||||||
|
mixsrc_t currentSource = 0;
|
||||||
|
bool lockSource = false;
|
||||||
|
|
||||||
|
void deleteLater(bool detach = true, bool trash = true) override
|
||||||
|
{
|
||||||
|
if (!_deleted) {
|
||||||
|
preview.deleteLater(true, false);
|
||||||
|
Window::deleteLater(detach, trash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkEvents(void) override
|
||||||
|
{
|
||||||
|
if (!lockSource) {
|
||||||
|
int16_t val = getMovedSource(MIXSRC_FIRST_STICK);
|
||||||
|
if (val > 0)
|
||||||
|
currentSource = val;
|
||||||
|
}
|
||||||
|
Window::checkEvents();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class CurveDataEdit : public Window
|
class CurveDataEdit : public Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -180,56 +240,6 @@ class CurveDataEdit : public Window
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void CurveEdit::SetCurrentSource(mixsrc_t source)
|
|
||||||
{
|
|
||||||
CurveEdit::currentSource = source;
|
|
||||||
if (source)
|
|
||||||
lockSource = true;
|
|
||||||
else
|
|
||||||
lockSource = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mixsrc_t CurveEdit::currentSource = 0;
|
|
||||||
bool CurveEdit::lockSource = false;
|
|
||||||
|
|
||||||
CurveEdit::CurveEdit(Window* parent, const rect_t& rect, uint8_t index) :
|
|
||||||
Window(parent, rect),
|
|
||||||
preview(
|
|
||||||
this, {0, 0, width(), height()},
|
|
||||||
[=](int x) -> int { return applyCustomCurve(x, index); },
|
|
||||||
[=]() -> int { return getValue(CurveEdit::currentSource); }),
|
|
||||||
index(index),
|
|
||||||
current(0)
|
|
||||||
{
|
|
||||||
setWindowFlag(NO_FOCUS);
|
|
||||||
updatePreview();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CurveEdit::updatePreview()
|
|
||||||
{
|
|
||||||
preview.clearPoints();
|
|
||||||
CurveHeader& curve = g_model.curves[index];
|
|
||||||
for (uint8_t i = 0; i < 5 + curve.points; i++) {
|
|
||||||
preview.addPoint(getPoint(index, i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CurveEdit::checkEvents()
|
|
||||||
{
|
|
||||||
if (!lockSource) {
|
|
||||||
int16_t val = getMovedSource(MIXSRC_FIRST_INPUT);
|
|
||||||
if (val > 0) {
|
|
||||||
// TODO: this code seems odd
|
|
||||||
if (val > MAX_STICKS + MAX_POTS)
|
|
||||||
CurveEdit::currentSource = val + 1 - MIXSRC_FIRST_INPUT;
|
|
||||||
else {
|
|
||||||
CurveEdit::currentSource = expoAddress(val - 1)->srcRaw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Window::checkEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
CurveEditWindow::CurveEditWindow(uint8_t index,
|
CurveEditWindow::CurveEditWindow(uint8_t index,
|
||||||
std::function<void(void)> refreshView) :
|
std::function<void(void)> refreshView) :
|
||||||
Page(ICON_MODEL_CURVES, PAD_ZERO), index(index), refreshView(refreshView)
|
Page(ICON_MODEL_CURVES, PAD_ZERO), index(index), refreshView(refreshView)
|
||||||
@@ -389,4 +399,9 @@ void CurveEditWindow::onCancel()
|
|||||||
{
|
{
|
||||||
if (refreshView) refreshView();
|
if (refreshView) refreshView();
|
||||||
Page::onCancel();
|
Page::onCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CurveEditWindow::setCurrentSource(mixsrc_t source)
|
||||||
|
{
|
||||||
|
curveEdit->setCurrentSource(source);
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,41 +26,17 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
class NumberEdit;
|
class NumberEdit;
|
||||||
|
class CurveEdit;
|
||||||
class CurveDataEdit;
|
class CurveDataEdit;
|
||||||
|
|
||||||
class CurveEdit : public Window
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CurveEdit(Window* parent, const rect_t& rect, uint8_t index);
|
|
||||||
static void SetCurrentSource(mixsrc_t source);
|
|
||||||
|
|
||||||
void deleteLater(bool detach = true, bool trash = true) override
|
|
||||||
{
|
|
||||||
if (_deleted) return;
|
|
||||||
|
|
||||||
preview.deleteLater(true, false);
|
|
||||||
|
|
||||||
Window::deleteLater(detach, trash);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updatePreview();
|
|
||||||
|
|
||||||
void checkEvents(void) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Curve preview;
|
|
||||||
uint8_t index;
|
|
||||||
uint8_t current;
|
|
||||||
static mixsrc_t currentSource;
|
|
||||||
static bool lockSource;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CurveEditWindow : public Page
|
class CurveEditWindow : public Page
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CurveEditWindow(uint8_t index,
|
CurveEditWindow(uint8_t index,
|
||||||
std::function<void(void)> refreshView = nullptr);
|
std::function<void(void)> refreshView = nullptr);
|
||||||
|
|
||||||
|
void setCurrentSource(mixsrc_t source);
|
||||||
|
|
||||||
static LAYOUT_VAL(NUMEDT_W, 70, 70)
|
static LAYOUT_VAL(NUMEDT_W, 70, 70)
|
||||||
static LAYOUT_VAL(CURVE_WIDTH, 215, 232)
|
static LAYOUT_VAL(CURVE_WIDTH, 215, 232)
|
||||||
|
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) :
|
|||||||
return anas[line->chn];
|
return anas[line->chn];
|
||||||
},
|
},
|
||||||
[=]() -> int { return getValue(expoAddress(index)->srcRaw); });
|
[=]() -> int { return getValue(expoAddress(index)->srcRaw); });
|
||||||
|
|
||||||
CurveEdit::SetCurrentSource(expoAddress(index)->srcRaw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputEditWindow::setTitle()
|
void InputEditWindow::setTitle()
|
||||||
@@ -159,7 +157,7 @@ void InputEditWindow::buildBody(Window* form)
|
|||||||
input->curve.value = newValue;
|
input->curve.value = newValue;
|
||||||
updatePreview = true;
|
updatePreview = true;
|
||||||
SET_DIRTY();
|
SET_DIRTY();
|
||||||
}, MIXSRC_FIRST,
|
}, MIXSRC_FIRST, input->srcRaw,
|
||||||
[=]() {
|
[=]() {
|
||||||
updatePreview = true;
|
updatePreview = true;
|
||||||
});
|
});
|
||||||
@@ -176,14 +174,6 @@ void InputEditWindow::buildBody(Window* form)
|
|||||||
lv_obj_set_width(btn->getLvObj(), lv_pct(100));
|
lv_obj_set_width(btn->getLvObj(), lv_pct(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputEditWindow::deleteLater(bool detach, bool trash)
|
|
||||||
{
|
|
||||||
if (!deleted()) {
|
|
||||||
CurveEdit::SetCurrentSource(0);
|
|
||||||
Page::deleteLater(detach, trash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputEditWindow::checkEvents()
|
void InputEditWindow::checkEvents()
|
||||||
{
|
{
|
||||||
ExpoData* input = expoAddress(index);
|
ExpoData* input = expoAddress(index);
|
||||||
|
|||||||
@@ -50,5 +50,4 @@ class InputEditWindow : public Page
|
|||||||
void buildBody(Window *window);
|
void buildBody(Window *window);
|
||||||
|
|
||||||
void checkEvents() override;
|
void checkEvents() override;
|
||||||
void deleteLater(bool detach = true, bool trash = true) override;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ void MixEditWindow::buildBody(Window *form)
|
|||||||
new StaticText(line, rect_t{}, STR_SOURCE);
|
new StaticText(line, rect_t{}, STR_SOURCE);
|
||||||
new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST,
|
new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST,
|
||||||
GET_SET_DEFAULT(mix->srcRaw), true);
|
GET_SET_DEFAULT(mix->srcRaw), true);
|
||||||
CurveEdit::SetCurrentSource(mix->srcRaw);
|
|
||||||
|
|
||||||
// Weight
|
// Weight
|
||||||
line = form->newLine(grid);
|
line = form->newLine(grid);
|
||||||
@@ -127,7 +126,7 @@ void MixEditWindow::buildBody(Window *form)
|
|||||||
|
|
||||||
// Curve
|
// Curve
|
||||||
new StaticText(line, rect_t{}, STR_CURVE);
|
new StaticText(line, rect_t{}, STR_CURVE);
|
||||||
new CurveParam(line, rect_t{}, &mix->curve, SET_DEFAULT(mix->curve.value), MIXSRC_FIRST);
|
new CurveParam(line, rect_t{}, &mix->curve, SET_DEFAULT(mix->curve.value), MIXSRC_FIRST, mix->srcRaw);
|
||||||
|
|
||||||
line = form->newLine(grid);
|
line = form->newLine(grid);
|
||||||
line->padAll(PAD_LARGE);
|
line->padAll(PAD_LARGE);
|
||||||
@@ -138,11 +137,3 @@ void MixEditWindow::buildBody(Window *form)
|
|||||||
});
|
});
|
||||||
lv_obj_set_width(btn->getLvObj(), lv_pct(100));
|
lv_obj_set_width(btn->getLvObj(), lv_pct(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MixEditWindow::deleteLater(bool detach, bool trash)
|
|
||||||
{
|
|
||||||
if (!deleted()) {
|
|
||||||
CurveEdit::SetCurrentSource(0);
|
|
||||||
Page::deleteLater(detach, trash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -39,6 +39,4 @@ class MixEditWindow : public Page
|
|||||||
|
|
||||||
void buildHeader(Window *window);
|
void buildHeader(Window *window);
|
||||||
void buildBody(Window *window);
|
void buildBody(Window *window);
|
||||||
|
|
||||||
void deleteLater(bool detach = true, bool trash = true) override;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ ModelCurvesPage::ModelCurvesPage() : PageTab(STR_MENUCURVES, ICON_MODEL_CURVES)
|
|||||||
|
|
||||||
// can be called from any other screen to edit a curve.
|
// can be called from any other screen to edit a curve.
|
||||||
// currently called from model_mixes.cpp on longpress.
|
// currently called from model_mixes.cpp on longpress.
|
||||||
void ModelCurvesPage::pushEditCurve(int index, std::function<void(void)> refreshView)
|
void ModelCurvesPage::pushEditCurve(int index, std::function<void(void)> refreshView, mixsrc_t source)
|
||||||
{
|
{
|
||||||
if (!isCurveUsed(index)) {
|
if (!isCurveUsed(index)) {
|
||||||
CurveHeader &curve = g_model.curves[index];
|
CurveHeader &curve = g_model.curves[index];
|
||||||
@@ -124,7 +124,8 @@ void ModelCurvesPage::pushEditCurve(int index, std::function<void(void)> refresh
|
|||||||
initPoints(curve, points);
|
initPoints(curve, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
new CurveEditWindow(index, refreshView);
|
auto cv = new CurveEditWindow(index, refreshView);
|
||||||
|
cv->setCurrentSource(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelCurvesPage::rebuild(Window *window)
|
void ModelCurvesPage::rebuild(Window *window)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class ModelCurvesPage : public PageTab
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ModelCurvesPage();
|
ModelCurvesPage();
|
||||||
static void pushEditCurve(int index, std::function<void(void)> refreshView = nullptr);
|
static void pushEditCurve(int index, std::function<void(void)> refreshView, mixsrc_t source);
|
||||||
|
|
||||||
bool isVisible() const override { return modelCurvesEnabled(); }
|
bool isVisible() const override { return modelCurvesEnabled(); }
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "output_edit.h"
|
#include "output_edit.h"
|
||||||
|
|
||||||
#include "channel_bar.h"
|
#include "channel_bar.h"
|
||||||
|
#include "curveedit.h"
|
||||||
|
#include "curve_param.h"
|
||||||
#include "gvar_numberedit.h"
|
#include "gvar_numberedit.h"
|
||||||
#include "edgetx.h"
|
#include "edgetx.h"
|
||||||
#include "etx_lv_theme.h"
|
#include "etx_lv_theme.h"
|
||||||
@@ -175,10 +177,7 @@ void OutputEditWindow::buildBody(Window *form)
|
|||||||
|
|
||||||
// Curve
|
// Curve
|
||||||
new StaticText(line, rect_t{}, TR_CURVE);
|
new StaticText(line, rect_t{}, TR_CURVE);
|
||||||
auto edit = new NumberEdit(line, rect_t{}, -MAX_CURVES, +MAX_CURVES,
|
new CurveChoice(line, GET_SET_DEFAULT(output->curve), nullptr, channel + MIXSRC_FIRST_CH);
|
||||||
GET_SET_DEFAULT(output->curve));
|
|
||||||
edit->setDisplayHandler(
|
|
||||||
[](int32_t value) { return std::string(getCurveString(value)); });
|
|
||||||
|
|
||||||
// PPM center
|
// PPM center
|
||||||
line = form->newLine(grid);
|
line = form->newLine(grid);
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ int checkMovedInput(int newval, int i_min, int i_max, unsigned int i_flags, bool
|
|||||||
|
|
||||||
#if defined(AUTOSOURCE)
|
#if defined(AUTOSOURCE)
|
||||||
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
|
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
|
||||||
int source = GET_MOVED_SOURCE(i_min, i_max);
|
int source = getMovedSource(i_min);
|
||||||
if (source) {
|
if (source) {
|
||||||
if (i_flags & INCDEC_SOURCE_VALUE) {
|
if (i_flags & INCDEC_SOURCE_VALUE) {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
|
|||||||
Reference in New Issue
Block a user