Merge pull request #678 from kevinkoenig/jump-curve
Implement Jump to Curve Edit from input and mixer screens
This commit is contained in:
@@ -66,6 +66,7 @@ set(GUI_SRC
|
|||||||
menu_screen.cpp
|
menu_screen.cpp
|
||||||
screen_setup.cpp
|
screen_setup.cpp
|
||||||
switch_warn_dialog.cpp
|
switch_warn_dialog.cpp
|
||||||
|
choiceex.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
macro(add_gui_src src)
|
macro(add_gui_src src)
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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 "choiceex.h"
|
||||||
|
|
||||||
|
void ChoiceEx::setLongPressHandler(std::function<void(event_t)> handler)
|
||||||
|
{
|
||||||
|
longPressHandler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChoiceEx::ChoiceEx(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 ChoiceEx::onTouchEnd(coord_t x, coord_t y)
|
||||||
|
{
|
||||||
|
return Choice::onTouchEnd(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChoiceEx::onEvent(event_t event)
|
||||||
|
{
|
||||||
|
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||||
|
if (longPressHandler) {
|
||||||
|
killEvents(event);
|
||||||
|
longPressHandler(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Choice::onEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) EdgeTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* opentx - https://github.com/opentx/opentx
|
||||||
|
* 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 "libopenui.h"
|
||||||
|
|
||||||
|
class ChoiceEx : public Choice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ChoiceEx(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;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "gvar_numberedit.h"
|
#include "gvar_numberedit.h"
|
||||||
#include "libopenui.h"
|
#include "libopenui.h"
|
||||||
|
#include "choiceex.h"
|
||||||
|
#include "model_curves.h"
|
||||||
|
|
||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||||
|
|
||||||
@@ -173,9 +175,16 @@ class InputEditWindow : 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 ChoiceEx(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) {
|
||||||
|
ExpoData *line = expoAddress(index);
|
||||||
|
|
||||||
|
// if no curve is specified then dont link to curve page
|
||||||
|
if (line->curve.value != 0)
|
||||||
|
ModelCurvesPage::pushEditCurve(abs(line->curve.value) - 1);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,15 @@
|
|||||||
#include "model_mixes.h"
|
#include "model_mixes.h"
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "libopenui.h"
|
#include "libopenui.h"
|
||||||
|
#include "choiceex.h"
|
||||||
#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"
|
||||||
#include "dataconstants.h"
|
#include "dataconstants.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
|
||||||
|
|
||||||
@@ -229,9 +231,15 @@ 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 ChoiceEx(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);
|
||||||
|
// 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