From f6022058d3dc8505d275d6ee60aa052529e670d3 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 18 Mar 2020 17:05:02 +0100 Subject: [PATCH] Slide fixes --- .../thirdparty/libopenui/src/mainwindow.cpp | 19 +++++++++--- radio/src/thirdparty/libopenui/src/window.cpp | 31 +++++++++++++++++-- radio/src/thirdparty/libopenui/src/window.h | 3 ++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index c52910aa2..046c936d2 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -48,21 +48,23 @@ void MainWindow::checkEvents() if (touchState.event == TE_DOWN) { onTouchStart(touchState.x + scrollPositionX, touchState.y + scrollPositionY); + slidingWindow = nullptr; } else if (touchState.event == TE_UP) { onTouchEnd(touchState.startX + scrollPositionX, touchState.startY + scrollPositionY); touchState.event = TE_NONE; + slidingWindow = nullptr; } else if (touchState.event == TE_SLIDE) { - if (touchState.deltaX) { - onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.deltaX, 0); + if (touchState.deltaX || touchState.deltaY) { + onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.deltaX, touchState.deltaY); touchState.deltaX = 0; - } - else if (touchState.deltaY) { - onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, 0, touchState.deltaY); touchState.deltaY = 0; } } + else { + slidingWindow = nullptr; + } #endif Window::checkEvents(); @@ -108,6 +110,8 @@ bool MainWindow::refresh() void MainWindow::run(bool trash) { + auto start = ticksNow(); + checkEvents(); if (trash) { @@ -117,4 +121,9 @@ void MainWindow::run(bool trash) if (refresh()) { lcdRefresh(); } + + auto delta = ticksNow() - start; + if (delta > 10 * SYSTEM_TICKS_1MS) { + TRACE_WINDOWS("MainWindow::run took %dms", (ticksNow() - start) / SYSTEM_TICKS_1MS); + } } diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 70c5cc24c..d8ea137ed 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -21,6 +21,7 @@ #include "touch.h" Window * Window::focusWindow = nullptr; +Window * Window::slidingWindow = nullptr; std::list Window::trash; Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags): @@ -191,24 +192,42 @@ void Window::scrollTo(const rect_t & rect) } } +bool Window::hasOpaqueRect(const rect_t & rect) +{ + if (!this->rect.contains(rect)) + return false; + + if (windowFlags & OPAQUE) { + return true; + } + + for (auto child: children) { + if (child->hasOpaqueRect(rect)) + return true; + } + + return false; +} + void Window::fullPaint(BitmapBuffer * dc) { bool paintNeeded = true; + coord_t xmin, xmax, ymin, ymax; + dc->getClippingRect(xmin, xmax, ymin, ymax); + auto firstChild = children.end(); while (firstChild != children.begin()) { auto child = *(--firstChild); - if ((child->windowFlags & OPAQUE) && isChildFullSize(child)) { + if (child->hasOpaqueRect({xmin, ymin, xmax - xmin, ymax - ymin})) { paintNeeded = false; break; } } if (windowFlags & PAINT_CHILDREN_FIRST) { - coord_t xmin, xmax, ymin, ymax; coord_t x = dc->getOffsetX(); coord_t y = dc->getOffsetY(); - dc->getClippingRect(xmin, xmax, ymin, ymax); paintChildren(dc, firstChild); dc->setOffset(x, y); dc->setClippingRect(xmin, xmax, ymin, ymax); @@ -374,13 +393,19 @@ bool Window::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, } } + if (slidingWindow && slidingWindow != this) { + return false; + } + if (slideY && innerHeight > rect.h) { setScrollPositionY(scrollPositionY - slideY); + slidingWindow = this; return true; } if (slideX && innerWidth > rect.w) { setScrollPositionX(scrollPositionX - slideX); + slidingWindow = this; return true; } diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index b8890ea1a..3b1a72f98 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -334,6 +334,7 @@ class Window { LcdFlags textFlags; static Window * focusWindow; + static Window * slidingWindow; static std::list trash; std::function closeHandler; @@ -380,6 +381,8 @@ class Window { #endif bool forwardTouchEnd(coord_t x, coord_t y); + + bool hasOpaqueRect(const rect_t & rect); }; #endif // _WINDOW_H_