implement long press on curve in mixes to launch edit of curve
This commit is contained in:
@@ -25,6 +25,12 @@
|
|||||||
|
|
||||||
class ModelMenu: public TabsGroup {
|
class ModelMenu: public TabsGroup {
|
||||||
public:
|
public:
|
||||||
|
#if defined(DEBUG_WINDOWS)
|
||||||
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "ModelMenu";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
ModelMenu();
|
ModelMenu();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,19 @@
|
|||||||
|
|
||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||||
|
|
||||||
|
|
||||||
|
// initialize a new curves points to the default for a 5 point
|
||||||
|
// curve.
|
||||||
|
void initPoints(const CurveHeader &curve, int8_t *points)
|
||||||
|
{
|
||||||
|
int dx = 2000 / (5 + curve.points - 1);
|
||||||
|
for (uint8_t i = 0; i < 5 + curve.points; i++) {
|
||||||
|
int x = -1000 + i * dx;
|
||||||
|
points[i] = x / 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CurveEditWindow : public Page
|
class CurveEditWindow : public Page
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -264,6 +277,20 @@ ModelCurvesPage::ModelCurvesPage() :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// can be called from any other screen to edit a curve.
|
||||||
|
// currently called from model_mixes.cpp on longpress.
|
||||||
|
void ModelCurvesPage::pushEditCurve(int index)
|
||||||
|
{
|
||||||
|
if (! isCurveUsed(index)) {
|
||||||
|
CurveHeader &curve = g_model.curves[index];
|
||||||
|
int8_t * points = curveAddress(index);
|
||||||
|
initPoints(curve, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
new CurveEditWindow(index);
|
||||||
|
}
|
||||||
|
|
||||||
void ModelCurvesPage::rebuild(FormWindow * window, int8_t focusIndex)
|
void ModelCurvesPage::rebuild(FormWindow * window, int8_t focusIndex)
|
||||||
{
|
{
|
||||||
coord_t scrollPosition = window->getScrollPositionY();
|
coord_t scrollPosition = window->getScrollPositionY();
|
||||||
@@ -364,11 +391,7 @@ void ModelCurvesPage::build(FormWindow * window, int8_t focusIndex)
|
|||||||
button->setPressHandler([=]() {
|
button->setPressHandler([=]() {
|
||||||
Menu *menu = new Menu(window);
|
Menu *menu = new Menu(window);
|
||||||
menu->addLine(STR_EDIT, [=]() {
|
menu->addLine(STR_EDIT, [=]() {
|
||||||
int dx = 2000 / (5 + curve.points - 1);
|
initPoints(curve, points);
|
||||||
for (uint8_t i = 0; i < 5 + curve.points; i++) {
|
|
||||||
int x = -1000 + i * dx;
|
|
||||||
points[i] = x / 10;
|
|
||||||
}
|
|
||||||
editCurve(window, index);
|
editCurve(window, index);
|
||||||
});
|
});
|
||||||
menu->addLine(STR_CURVE_PRESET, presetCurveFct);
|
menu->addLine(STR_CURVE_PRESET, presetCurveFct);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
class ModelCurvesPage: public PageTab {
|
class ModelCurvesPage: public PageTab {
|
||||||
public:
|
public:
|
||||||
ModelCurvesPage();
|
ModelCurvesPage();
|
||||||
|
static void pushEditCurve(int index);
|
||||||
|
|
||||||
virtual void build(FormWindow * window) override
|
virtual void build(FormWindow * window) override
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,12 +24,66 @@
|
|||||||
#include "bitfield.h"
|
#include "bitfield.h"
|
||||||
#include "model_inputs.h"
|
#include "model_inputs.h"
|
||||||
#include "gvar_numberedit.h"
|
#include "gvar_numberedit.h"
|
||||||
|
#include "model_curves.h"
|
||||||
|
|
||||||
|
|
||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||||
|
|
||||||
#define PASTE_BEFORE -2
|
#define PASTE_BEFORE -2
|
||||||
#define PASTE_AFTER -1
|
#define PASTE_AFTER -1
|
||||||
|
|
||||||
|
class CurvesListChoice : public Choice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CurvesListChoice(FormGroup * parent, const rect_t &rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = 0);
|
||||||
|
void setLongPressHandler(std::function<void(event_t)> handler);
|
||||||
|
|
||||||
|
#if defined(HARDWARE_KEYS)
|
||||||
|
void onEvent(event_t event) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(DEBUG_WINDOWS)
|
||||||
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "CurvesListChoice";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::function<void(event_t)> longPressHandler = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void CurvesListChoice::setLongPressHandler(std::function<void(event_t)> handler)
|
||||||
|
{
|
||||||
|
longPressHandler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurvesListChoice::CurvesListChoice(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags) :
|
||||||
|
Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CurvesListChoice::onTouchEnd(coord_t x, coord_t y)
|
||||||
|
{
|
||||||
|
return Choice::onTouchEnd(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CurvesListChoice::onEvent(event_t event)
|
||||||
|
{
|
||||||
|
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||||
|
if (longPressHandler) {
|
||||||
|
killEvents(event);
|
||||||
|
longPressHandler(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Choice::onEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t getMixesCount()
|
uint8_t getMixesCount()
|
||||||
{
|
{
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
@@ -228,9 +282,16 @@ class MixEditWindow : public Page
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CURVE_REF_CUSTOM: {
|
case CURVE_REF_CUSTOM: {
|
||||||
auto choice = new Choice(curveParamField, rect, -MAX_CURVES, MAX_CURVES,
|
auto choice = new CurvesListChoice(curveParamField, rect, -MAX_CURVES, MAX_CURVES,
|
||||||
GET_SET_DEFAULT(line->curve.value));
|
GET_SET_DEFAULT(line->curve.value));
|
||||||
choice->setTextHandler([](int value) { return getCurveString(value); });
|
choice->setTextHandler([](int value) { return getCurveString(value); });
|
||||||
|
choice->setLongPressHandler([this](event_t event) {
|
||||||
|
MixData *mix = mixAddress(mixIndex);
|
||||||
|
auto a = parent->getName();
|
||||||
|
// if no curve is specified then dont link to curve page
|
||||||
|
if (mix->curve.value != 0)
|
||||||
|
ModelCurvesPage::pushEditCurve(abs(mix->curve.value) - 1);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user