diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index b5aea580f..edf9ca05b 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -66,6 +66,7 @@ set(GUI_SRC menu_screen.cpp screen_setup.cpp switch_warn_dialog.cpp + choiceex.cpp ) macro(add_gui_src src) diff --git a/radio/src/gui/colorlcd/choiceex.cpp b/radio/src/gui/colorlcd/choiceex.cpp new file mode 100644 index 000000000..96c44196e --- /dev/null +++ b/radio/src/gui/colorlcd/choiceex.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "choiceex.h" + +void ChoiceEx::setLongPressHandler(std::function handler) +{ + longPressHandler = handler; +} + +ChoiceEx::ChoiceEx(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function getValue, std::function 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); +} + diff --git a/radio/src/gui/colorlcd/choiceex.h b/radio/src/gui/colorlcd/choiceex.h new file mode 100644 index 000000000..4b0aeac83 --- /dev/null +++ b/radio/src/gui/colorlcd/choiceex.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include "libopenui.h" + +class ChoiceEx : public Choice +{ + public: + ChoiceEx(FormGroup * parent, const rect_t &rect, int vmin, int vmax, std::function getValue, std::function setValue = nullptr, WindowFlags windowFlags = 0); + void setLongPressHandler(std::function 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 longPressHandler = nullptr; +}; + diff --git a/radio/src/gui/colorlcd/model_inputs.cpp b/radio/src/gui/colorlcd/model_inputs.cpp index 494cc61ac..afa12776b 100644 --- a/radio/src/gui/colorlcd/model_inputs.cpp +++ b/radio/src/gui/colorlcd/model_inputs.cpp @@ -22,6 +22,8 @@ #include "opentx.h" #include "gvar_numberedit.h" #include "libopenui.h" +#include "choiceex.h" +#include "model_curves.h" #define SET_DIRTY() storageDirty(EE_MODEL) @@ -173,9 +175,16 @@ class InputEditWindow : public Page break; 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)); 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; } } diff --git a/radio/src/gui/colorlcd/model_mixes.cpp b/radio/src/gui/colorlcd/model_mixes.cpp index c04a9f230..65a4e82b8 100644 --- a/radio/src/gui/colorlcd/model_mixes.cpp +++ b/radio/src/gui/colorlcd/model_mixes.cpp @@ -21,6 +21,7 @@ #include "model_mixes.h" #include "opentx.h" #include "libopenui.h" +#include "choiceex.h" #include "bitfield.h" #include "model_inputs.h" #include "gvar_numberedit.h" @@ -31,59 +32,6 @@ #define PASTE_BEFORE -2 #define PASTE_AFTER -1 -class CurvesListChoice : public Choice -{ - public: - CurvesListChoice(FormGroup * parent, const rect_t &rect, int vmin, int vmax, std::function getValue, std::function setValue = nullptr, WindowFlags windowFlags = 0); - void setLongPressHandler(std::function 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 longPressHandler = nullptr; -}; - -void CurvesListChoice::setLongPressHandler(std::function handler) -{ - longPressHandler = handler; -} - -CurvesListChoice::CurvesListChoice(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function getValue, std::function 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 count = 0; @@ -282,7 +230,7 @@ class MixEditWindow : public Page break; case CURVE_REF_CUSTOM: { - auto choice = new CurvesListChoice(curveParamField, rect, -MAX_CURVES, MAX_CURVES, + auto choice = new ChoiceEx(curveParamField, rect, -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value)); choice->setTextHandler([](int value) { return getCurveString(value); }); choice->setLongPressHandler([this](event_t event) {