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.
This commit is contained in:
+2
-2
@@ -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) {
|
||||
|
||||
+6
-25
@@ -22,7 +22,7 @@
|
||||
|
||||
Window * Window::focusWindow = nullptr;
|
||||
Window * Window::slidingWindow = nullptr;
|
||||
Window * Window::touchedWindow = nullptr;
|
||||
Window * Window::capturedWindow = nullptr;
|
||||
std::list<Window *> 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) {
|
||||
|
||||
+6
-1
@@ -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<Window *> trash;
|
||||
|
||||
std::function<void()> closeHandler;
|
||||
|
||||
Reference in New Issue
Block a user