diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index 27c459bf2..589722c51 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -39,15 +39,84 @@ void MainWindow::emptyTrash() trash.clear(); } +#if defined(HARDWARE_TOUCH) +void MainWindow::setTouchEnabled(bool enable) +{ + switch(touchEnableState) + { + case TouchOn: + if(!enable) + touchEnableState = TouchOff; + break; + case TouchOn_Touching: + if(!enable) + touchEnableState = TouchOnToOff_Touching; + break; + case TouchOnToOff_Touching: + if(enable) + touchEnableState = TouchOn_Touching; + break; + case TouchOff: + if(enable) + touchEnableState = TouchOn; + break; + case TouchOff_Touching: + if(enable) + touchEnableState = TouchOffToOn_Touching; + break; + case TouchOffToOn_Touching: + if(!enable) + touchEnableState = TouchOff_Touching; + break; + } +} +#endif + void MainWindow::checkEvents() { #if defined(HARDWARE_TOUCH) + if (touchPanelEventOccured()) { - touchPanelRead(); + touchState = touchPanelRead(); + } else { + touchState.event = TE_NONE; } - if(!touchEnabled) + TouchEnableState currentState = touchEnableState; + + switch(touchState.event) + { + case TE_DOWN: + case TE_SLIDE: + if(touchEnableState == TouchOn) + touchEnableState = TouchOn_Touching; + else if (touchEnableState == TouchOff) + touchEnableState = TouchOff_Touching; + break; + case TE_UP: + case TE_SLIDE_END: + if(touchEnableState == TouchOn_Touching) + touchEnableState = TouchOn; + else if (touchEnableState == TouchOff_Touching) + touchEnableState = TouchOff; + else if(touchEnableState == TouchOnToOff_Touching) + touchEnableState = TouchOff; + else if(touchEnableState == TouchOffToOn_Touching) + touchEnableState = TouchOn; + break; + default: + break; + } + + if(touchState.event != TE_NONE) + _touchEventOccured = true; + + if ( currentState == TouchOff + || currentState == TouchOff_Touching + || currentState == TouchOffToOn_Touching) + { touchState.event = TE_NONE; + } if (touchState.event == TE_DOWN) { onTouchStart(touchState.x + scrollPositionX, touchState.y + scrollPositionY); diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.h b/radio/src/thirdparty/libopenui/src/mainwindow.h index 009c86454..d8bf8f62b 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.h +++ b/radio/src/thirdparty/libopenui/src/mainwindow.h @@ -65,9 +65,14 @@ class MainWindow: public Window void checkEvents() override; #if defined(HARDWARE_TOUCH) - void setTouchEnabled(bool enable) - { - touchEnabled = enable; + void setTouchEnabled(bool enable); + bool touchEventOccured() { + if(_touchEventOccured) + { + _touchEventOccured = false; + return true; + } + return false; } #endif @@ -93,6 +98,17 @@ class MainWindow: public Window rect_t invalidatedRect; const char * shutdown = nullptr; #if defined(HARDWARE_TOUCH) - bool touchEnabled = true; + bool lastTouchState = false; + bool _touchEventOccured = false; + + enum TouchEnableState { + TouchOn, + TouchOn_Touching, + TouchOnToOff_Touching, + TouchOff, + TouchOff_Touching, + TouchOffToOn_Touching + }; + TouchEnableState touchEnableState = TouchOn; #endif };