summaryrefslogtreecommitdiff
path: root/src/ui/touch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/touch.c')
-rw-r--r--src/ui/touch.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/ui/touch.c b/src/ui/touch.c
index 14e5fe48..a55d370d 100644
--- a/src/ui/touch.c
+++ b/src/ui/touch.c
@@ -54,6 +54,7 @@ enum iTouchAxis {
54struct Impl_Touch { 54struct Impl_Touch {
55 SDL_FingerID id; 55 SDL_FingerID id;
56 iWidget *affinity; /* widget on which the touch started */ 56 iWidget *affinity; /* widget on which the touch started */
57 iWidget *edgeDragging;
57 iBool hasMoved; 58 iBool hasMoved;
58 iBool isTapAndHold; 59 iBool isTapAndHold;
59 enum iTouchEdge edge; 60 enum iTouchEdge edge;
@@ -277,6 +278,15 @@ static iWidget *findOverflowScrollable_Widget_(iWidget *d) {
277 return NULL; 278 return NULL;
278} 279}
279 280
281static iWidget *findSlidePanel_Widget_(iWidget *d) {
282 for (iWidget *w = d; w; w = parent_Widget(w)) {
283 if (isVisible_Widget(w) && flags_Widget(w) & horizontalOffset_WidgetFlag) {
284 return w;
285 }
286 }
287 return NULL;
288}
289
280iBool processEvent_Touch(const SDL_Event *ev) { 290iBool processEvent_Touch(const SDL_Event *ev) {
281 /* We only handle finger events here. */ 291 /* We only handle finger events here. */
282 if (ev->type != SDL_FINGERDOWN && ev->type != SDL_FINGERMOTION && ev->type != SDL_FINGERUP) { 292 if (ev->type != SDL_FINGERDOWN && ev->type != SDL_FINGERMOTION && ev->type != SDL_FINGERUP) {
@@ -297,6 +307,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
297 const float x = x_F3(pos); 307 const float x = x_F3(pos);
298 enum iTouchEdge edge = none_TouchEdge; 308 enum iTouchEdge edge = none_TouchEdge;
299 const int edgeWidth = 30 * window->pixelRatio; 309 const int edgeWidth = 30 * window->pixelRatio;
310 iWidget *dragging = NULL;
300 if (x < edgeWidth) { 311 if (x < edgeWidth) {
301 edge = left_TouchEdge; 312 edge = left_TouchEdge;
302 } 313 }
@@ -304,9 +315,18 @@ iBool processEvent_Touch(const SDL_Event *ev) {
304 edge = right_TouchEdge; 315 edge = right_TouchEdge;
305 } 316 }
306 iWidget *aff = hitChild_Widget(window->root, init_I2(iRound(x), iRound(y_F3(pos)))); 317 iWidget *aff = hitChild_Widget(window->root, init_I2(iRound(x), iRound(y_F3(pos))));
318 if (edge == left_TouchEdge) {
319 dragging = findSlidePanel_Widget_(aff);
320 if (dragging) {
321 setFlags_Widget(dragging, dragged_WidgetFlag, iTrue);
322 }
323 }
307 /* TODO: We must retain a reference to the affinity widget, or otherwise it might 324 /* TODO: We must retain a reference to the affinity widget, or otherwise it might
308 be destroyed during the gesture. */ 325 be destroyed during the gesture. */
309 printf("aff:%p (%s)\n", aff, aff ? class_Widget(aff)->name : "-"); 326 printf("aff:[%p] %s:'%s'\n", aff, aff ? class_Widget(aff)->name : "-",
327 cstr_String(id_Widget(aff)));
328 printf("drg:[%p] %s:'%s'\n", dragging, dragging ? class_Widget(dragging)->name : "-",
329 cstr_String(id_Widget(dragging)));
310 if (flags_Widget(aff) & touchDrag_WidgetFlag) { 330 if (flags_Widget(aff) & touchDrag_WidgetFlag) {
311 dispatchEvent_Widget(window->root, (SDL_Event *) &(SDL_MouseButtonEvent){ 331 dispatchEvent_Widget(window->root, (SDL_Event *) &(SDL_MouseButtonEvent){
312 .type = SDL_MOUSEBUTTONDOWN, 332 .type = SDL_MOUSEBUTTONDOWN,
@@ -323,6 +343,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
323 iTouch newTouch = { 343 iTouch newTouch = {
324 .id = fing->fingerId, 344 .id = fing->fingerId,
325 .affinity = aff, 345 .affinity = aff,
346 .edgeDragging = dragging,
326 .hasMoved = (flags_Widget(aff) & touchDrag_WidgetFlag) != 0, 347 .hasMoved = (flags_Widget(aff) & touchDrag_WidgetFlag) != 0,
327 .edge = edge, 348 .edge = edge,
328 .startTime = nowTime, 349 .startTime = nowTime,
@@ -390,8 +411,18 @@ iBool processEvent_Touch(const SDL_Event *ev) {
390 } 411 }
391 } 412 }
392 /* Edge swipe aborted? */ 413 /* Edge swipe aborted? */
393 if (touch->edge == left_TouchEdge && fing->dx < 0) { 414 if (touch->edge == left_TouchEdge) {
394 touch->edge = none_TouchEdge; 415 if (fing->dx < 0) {
416 touch->edge = none_TouchEdge;
417 if (touch->edgeDragging) {
418 setFlags_Widget(touch->edgeDragging, dragged_WidgetFlag, iFalse);
419 setVisualOffset_Widget(touch->edgeDragging, 0, 200, easeOut_AnimFlag);
420 touch->edgeDragging = NULL;
421 }
422 }
423 else if (touch->edgeDragging) {
424 setVisualOffset_Widget(touch->edgeDragging, x_F3(pos) - x_F3(touch->startPos), 10, 0);
425 }
395 } 426 }
396 if (touch->edge == right_TouchEdge && fing->dx > 0) { 427 if (touch->edge == right_TouchEdge && fing->dx > 0) {
397 touch->edge = none_TouchEdge; 428 touch->edge = none_TouchEdge;
@@ -430,6 +461,9 @@ iBool processEvent_Touch(const SDL_Event *ev) {
430 if (touch->id != fing->fingerId) { 461 if (touch->id != fing->fingerId) {
431 continue; 462 continue;
432 } 463 }
464 if (touch->edgeDragging) {
465 setFlags_Widget(touch->edgeDragging, dragged_WidgetFlag, iFalse);
466 }
433 if (touch->isTapAndHold) { 467 if (touch->isTapAndHold) {
434 if (!isStationary_Touch_(touch)) { 468 if (!isStationary_Touch_(touch)) {
435 dispatchClick_Touch_(touch, SDL_BUTTON_LEFT); 469 dispatchClick_Touch_(touch, SDL_BUTTON_LEFT);