Slide fixes

This commit is contained in:
Bertrand Songis
2020-03-18 17:05:02 +01:00
parent b1e7e09850
commit f6022058d3
3 changed files with 45 additions and 8 deletions
+14 -5
View File
@@ -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);
}
}
+28 -3
View File
@@ -21,6 +21,7 @@
#include "touch.h"
Window * Window::focusWindow = nullptr;
Window * Window::slidingWindow = nullptr;
std::list<Window *> 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;
}
+3
View File
@@ -334,6 +334,7 @@ class Window {
LcdFlags textFlags;
static Window * focusWindow;
static Window * slidingWindow;
static std::list<Window *> trash;
std::function<void()> 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_