Merge pull request #689 from kevinkoenig/lng-press
Implement long touch to launch curves in mixes and inputs
This commit is contained in:
@@ -28,13 +28,12 @@ void ChoiceEx::setLongPressHandler(std::function<void(event_t)> handler)
|
|||||||
ChoiceEx::ChoiceEx(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags) :
|
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)
|
Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags)
|
||||||
{
|
{
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
duration10ms = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChoiceEx::onTouchEnd(coord_t x, coord_t y)
|
#if defined(HARDWARE_KEYS)
|
||||||
{
|
|
||||||
return Choice::onTouchEnd(x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChoiceEx::onEvent(event_t event)
|
void ChoiceEx::onEvent(event_t event)
|
||||||
{
|
{
|
||||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||||
@@ -47,4 +46,54 @@ void ChoiceEx::onEvent(event_t event)
|
|||||||
|
|
||||||
Choice::onEvent(event);
|
Choice::onEvent(event);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
bool ChoiceEx::onTouchStart(coord_t x, coord_t y)
|
||||||
|
{
|
||||||
|
if (duration10ms == 0) {
|
||||||
|
duration10ms = get_tmr10ms();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Choice::onTouchStart(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChoiceEx::isLongPress()
|
||||||
|
{
|
||||||
|
tmr10ms_t curTimer = get_tmr10ms();
|
||||||
|
return (duration10ms != 0 && curTimer - duration10ms > LONG_PRESS_10MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChoiceEx::checkEvents(void)
|
||||||
|
{
|
||||||
|
event_t event = getEvent();
|
||||||
|
|
||||||
|
if (isLongPress()) {
|
||||||
|
if (longPressHandler) {
|
||||||
|
longPressHandler(event);
|
||||||
|
duration10ms = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasFocus())
|
||||||
|
onEvent(event);
|
||||||
|
else
|
||||||
|
pushEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ChoiceEx::onTouchEnd(coord_t x, coord_t y)
|
||||||
|
{
|
||||||
|
if (isLongPress()) {
|
||||||
|
if (longPressHandler) {
|
||||||
|
longPressHandler(0);
|
||||||
|
duration10ms = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
duration10ms = 0;
|
||||||
|
return Choice::onTouchEnd(x,y);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -32,16 +32,22 @@ class ChoiceEx : public Choice
|
|||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||||
|
bool onTouchStart(coord_t x, coord_t y) override;
|
||||||
|
void checkEvents(void) override;
|
||||||
|
bool isLongPress();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
{
|
{
|
||||||
return "CurvesListChoice";
|
return "ChoceEx";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<void(event_t)> longPressHandler = nullptr;
|
std::function<void(event_t)> longPressHandler = nullptr;
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
tmr10ms_t duration10ms;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user