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.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/ui/touch.c b/src/ui/touch.c
index dac1152e..613f2c0d 100644
--- a/src/ui/touch.c
+++ b/src/ui/touch.c
@@ -59,7 +59,6 @@ enum iTouchAxis {
59struct Impl_Touch { 59struct Impl_Touch {
60 SDL_FingerID id; 60 SDL_FingerID id;
61 iWidget *affinity; /* widget on which the touch started */ 61 iWidget *affinity; /* widget on which the touch started */
62// iWidget *edgeDragging;
63 iBool hasMoved; 62 iBool hasMoved;
64 iBool isTapBegun; 63 iBool isTapBegun;
65 iBool isLeftDown; 64 iBool isLeftDown;
@@ -254,6 +253,8 @@ static iFloat3 gestureVector_Touch_(const iTouch *d) {
254} 253}
255 254
256static void update_TouchState_(void *ptr) { 255static void update_TouchState_(void *ptr) {
256 iWindow *win = get_Window();
257 const iWidget *oldHover = win->hover;
257 iTouchState *d = ptr; 258 iTouchState *d = ptr;
258 /* Check for long presses to simulate right clicks. */ 259 /* Check for long presses to simulate right clicks. */
259 const uint32_t nowTime = SDL_GetTicks(); 260 const uint32_t nowTime = SDL_GetTicks();
@@ -291,8 +292,10 @@ static void update_TouchState_(void *ptr) {
291 } 292 }
292 if (elapsed > 50 && !touch->isTapBegun) { 293 if (elapsed > 50 && !touch->isTapBegun) {
293 /* Looks like a possible tap. */ 294 /* Looks like a possible tap. */
295 touchState_()->currentTouchPos = initF3_I2(touch->pos[0]);
294 dispatchNotification_Touch_(touch, widgetTapBegins_UserEventCode); 296 dispatchNotification_Touch_(touch, widgetTapBegins_UserEventCode);
295 dispatchMotion_Touch_(touch->pos[0], 0); 297 dispatchMotion_Touch_(touch->pos[0], 0);
298 refresh_Widget(touch->affinity);
296 touch->isTapBegun = iTrue; 299 touch->isTapBegun = iTrue;
297 } 300 }
298 if (!touch->isTapAndHold && nowTime - touch->startTime >= longPressSpanMs_ && 301 if (!touch->isTapAndHold && nowTime - touch->startTime >= longPressSpanMs_ &&
@@ -347,6 +350,7 @@ static void update_TouchState_(void *ptr) {
347 setCurrent_Root(mom->affinity->root); 350 setCurrent_Root(mom->affinity->root);
348 dispatchEvent_Widget(mom->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){ 351 dispatchEvent_Widget(mom->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
349 .type = SDL_MOUSEWHEEL, 352 .type = SDL_MOUSEWHEEL,
353 .which = SDL_TOUCH_MOUSEID,
350 .timestamp = nowTime, 354 .timestamp = nowTime,
351 .x = pixels.x, 355 .x = pixels.x,
352 .y = pixels.y, 356 .y = pixels.y,
@@ -363,6 +367,10 @@ static void update_TouchState_(void *ptr) {
363 if (!isEmpty_Array(d->touches) || !isEmpty_Array(d->moms)) { 367 if (!isEmpty_Array(d->touches) || !isEmpty_Array(d->moms)) {
364 addTickerRoot_App(update_TouchState_, NULL, ptr); 368 addTickerRoot_App(update_TouchState_, NULL, ptr);
365 } 369 }
370 if (oldHover != win->hover) {
371 refresh_Widget(oldHover);
372 refresh_Widget(win->hover);
373 }
366} 374}
367 375
368#if 0 376#if 0
@@ -464,13 +472,9 @@ iBool processEvent_Touch(const SDL_Event *ev) {
464 } 472 }
465 iTouchState *d = touchState_(); 473 iTouchState *d = touchState_();
466 iWindow *window = get_Window(); 474 iWindow *window = get_Window();
467 if (!isFinished_Anim(&window->rootOffset)) {
468 return iFalse;
469 }
470 const iInt2 rootSize = size_Window(window); 475 const iInt2 rootSize = size_Window(window);
471 const SDL_TouchFingerEvent *fing = &ev->tfinger; 476 const SDL_TouchFingerEvent *fing = &ev->tfinger;
472 const iFloat3 pos = add_F3(init_F3(fing->x * rootSize.x, fing->y * rootSize.y, 0), /* pixels */ 477 const iFloat3 pos = init_F3(fing->x * rootSize.x, fing->y * rootSize.y, 0); /* pixels */
473 init_F3(0, -value_Anim(&window->rootOffset), 0));
474 const uint32_t nowTime = SDL_GetTicks(); 478 const uint32_t nowTime = SDL_GetTicks();
475 if (ev->type == SDL_FINGERDOWN) { 479 if (ev->type == SDL_FINGERDOWN) {
476 /* Register the new touch. */ 480 /* Register the new touch. */
@@ -614,15 +618,16 @@ iBool processEvent_Touch(const SDL_Event *ev) {
614// pixels.y, y_F3(amount), y_F3(touch->accum), 618// pixels.y, y_F3(amount), y_F3(touch->accum),
615// touch->edge); 619// touch->edge);
616 if (pixels.x || pixels.y) { 620 if (pixels.x || pixels.y) {
617 setFocus_Widget(NULL); 621 //setFocus_Widget(NULL);
618 dispatchMotion_Touch_(touch->pos[0], 0); 622 dispatchMotion_Touch_(touch->startPos /*pos[0]*/, 0);
619 setCurrent_Root(touch->affinity->root); 623 setCurrent_Root(touch->affinity->root);
620 dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){ 624 dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
621 .type = SDL_MOUSEWHEEL, 625 .type = SDL_MOUSEWHEEL,
626 .which = SDL_TOUCH_MOUSEID,
622 .timestamp = SDL_GetTicks(), 627 .timestamp = SDL_GetTicks(),
623 .x = pixels.x, 628 .x = pixels.x,
624 .y = pixels.y, 629 .y = pixels.y,
625 .direction = perPixel_MouseWheelFlag 630 .direction = perPixel_MouseWheelFlag,
626 }); 631 });
627 /* TODO: Keep increasing movement if the direction is the same. */ 632 /* TODO: Keep increasing movement if the direction is the same. */
628 clearWidgetMomentum_TouchState_(d, touch->affinity); 633 clearWidgetMomentum_TouchState_(d, touch->affinity);
@@ -715,7 +720,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
715 iMomentum mom = { 720 iMomentum mom = {
716 .affinity = touch->affinity, 721 .affinity = touch->affinity,
717 .releaseTime = nowTime, 722 .releaseTime = nowTime,
718 .pos = touch->pos[0], 723 .pos = touch->startPos, // pos[0],
719 .velocity = velocity 724 .velocity = velocity
720 }; 725 };
721 if (isEmpty_Array(d->moms)) { 726 if (isEmpty_Array(d->moms)) {