From f81fa679d79dec9c83b4a42c8ecaf249e448e29d Mon Sep 17 00:00:00 2001 From: Kevin Koenig Date: Sun, 12 Dec 2021 16:39:44 -0500 Subject: [PATCH] Change touch end processing (#45) 1. removed the generic touchedWindow processing 2. replaced it with an implicit capture processing 3. therefore it works like normal in all instances except ListBox() which explicitely captures the up. --- .../thirdparty/libopenui/src/mainwindow.cpp | 4 +-- radio/src/thirdparty/libopenui/src/window.cpp | 31 ++++--------------- radio/src/thirdparty/libopenui/src/window.h | 7 ++++- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index 406829613..c256d0b06 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -150,8 +150,8 @@ void MainWindow::checkEvents() touchState.lastDeltaY += SLIDE_SPEED_REDUCTION; else touchState.lastDeltaY = 0; - - touchedWindow = nullptr; // this is also an end of a touch so reset the touched window. Fixes scroll and touch bug + + Window::capturedWindow = nullptr; onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.lastDeltaX, touchState.lastDeltaY); } else if (touchState.event == TE_SLIDE_END && slidingWindow == nullptr) { diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 46f5d4ce4..28ba8c027 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -22,7 +22,7 @@ Window * Window::focusWindow = nullptr; Window * Window::slidingWindow = nullptr; -Window * Window::touchedWindow = nullptr; +Window * Window::capturedWindow = nullptr; std::list Window::trash; Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags): @@ -412,12 +412,6 @@ bool Window::onTouchStart(coord_t x, coord_t y) auto child = *it; if (child->rect.contains(x, y)) { if (child->onTouchStart(x - child->rect.x + child->scrollPositionX, y - child->rect.y + child->scrollPositionY)) { - // remember the first window that processed the touch start event. We will give that window - // the opportunity to process the touchend first, and also after a slide end so the touched window - // always gets a touchEnd if it processed the touch start. - if (touchedWindow == nullptr) { - touchedWindow = child; - } return true; } } @@ -428,24 +422,11 @@ bool Window::onTouchStart(coord_t x, coord_t y) bool Window::forwardTouchEnd(coord_t x, coord_t y) { - // give the touched window the opportunity to process the touch first before it is - // forwarded: See on touchstart - if (touchedWindow != nullptr) { - auto savedTouchWindow = touchedWindow; - touchedWindow = nullptr; - // transalte x and y through the parent hierarchy - auto myParent = savedTouchWindow->parent; - while(myParent != nullptr) { - x = x - myParent->rect.x + myParent->scrollPositionX; - y = y - myParent->rect.y + myParent->scrollPositionY; - myParent = myParent->parent; - } - - if (savedTouchWindow->onTouchEnd( - x - savedTouchWindow->rect.x + savedTouchWindow->scrollPositionX, - y - savedTouchWindow->rect.y + savedTouchWindow->scrollPositionY)) { - return true; - } + if (capturedWindow != nullptr) + { + capturedWindow->onTouchEnd(x, y); + capturedWindow = nullptr; + return true; } for (auto it = children.rbegin(); it != children.rend(); ++it) { diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index 2b9b045e6..8f731010f 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -321,6 +321,11 @@ class Window return scrollPositionX; } + void captureWindow(Window *window) + { + capturedWindow = window; + } + coord_t getScrollPositionY() const { return scrollPositionY; @@ -395,7 +400,7 @@ class Window static Window * focusWindow; static Window * slidingWindow; - static Window * touchedWindow; + static Window * capturedWindow; static std::list trash; std::function closeHandler;