summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-04-09 13:31:57 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-10 06:29:31 +0300
commitdf99b5720bbe4f277a77d0a94fb40d3eeec6eb07 (patch)
treea4155e9797548b938c5a769c326f069c41702257
parent1f4e36bccacc0be71e11136c3bd00b3274504953 (diff)
Touch: Multitouch scrolling
Each finger is emitting scroll events at their own position, enabling scrolling multiple widgets at the same time.
-rw-r--r--src/ui/touch.c8
-rw-r--r--src/ui/touch.h2
2 files changed, 10 insertions, 0 deletions
diff --git a/src/ui/touch.c b/src/ui/touch.c
index 40e5c5d0..88746bed 100644
--- a/src/ui/touch.c
+++ b/src/ui/touch.c
@@ -80,6 +80,7 @@ iLocalDef void pushPos_Touch_(iTouch *d, const iFloat3 pos, uint32_t time) {
80struct Impl_Momentum { 80struct Impl_Momentum {
81 iWidget *affinity; 81 iWidget *affinity;
82 uint32_t releaseTime; 82 uint32_t releaseTime;
83 iFloat3 pos;
83 iFloat3 velocity; 84 iFloat3 velocity;
84 iFloat3 accum; 85 iFloat3 accum;
85}; 86};
@@ -226,6 +227,7 @@ static void update_TouchState_(void *ptr) {
226 const iInt2 pixels = initF3_I2(mom->accum); 227 const iInt2 pixels = initF3_I2(mom->accum);
227 if (pixels.x || pixels.y) { 228 if (pixels.x || pixels.y) {
228 subv_F3(&mom->accum, initI2_F3(pixels)); 229 subv_F3(&mom->accum, initI2_F3(pixels));
230 dispatchMotion_Touch_(mom->pos, 0);
229 dispatchEvent_Widget(mom->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){ 231 dispatchEvent_Widget(mom->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
230 .type = SDL_MOUSEWHEEL, 232 .type = SDL_MOUSEWHEEL,
231 .timestamp = nowTime, 233 .timestamp = nowTime,
@@ -474,6 +476,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
474// pixels.y, y_F3(amount), y_F3(touch->accum)); 476// pixels.y, y_F3(amount), y_F3(touch->accum));
475 if (pixels.x || pixels.y) { 477 if (pixels.x || pixels.y) {
476 setFocus_Widget(NULL); 478 setFocus_Widget(NULL);
479 dispatchMotion_Touch_(touch->pos[0], 0);
477 dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){ 480 dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
478 .type = SDL_MOUSEWHEEL, 481 .type = SDL_MOUSEWHEEL,
479 .timestamp = SDL_GetTicks(), 482 .timestamp = SDL_GetTicks(),
@@ -551,6 +554,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
551 iMomentum mom = { 554 iMomentum mom = {
552 .affinity = touch->affinity, 555 .affinity = touch->affinity,
553 .releaseTime = nowTime, 556 .releaseTime = nowTime,
557 .pos = touch->pos[0],
554 .velocity = velocity 558 .velocity = velocity
555 }; 559 };
556 if (isEmpty_Array(d->moms)) { 560 if (isEmpty_Array(d->moms)) {
@@ -569,3 +573,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
569 } 573 }
570 return iTrue; 574 return iTrue;
571} 575}
576
577size_t numFingers_Touch(void) {
578 return size_Array(touchState_()->touches);
579}
diff --git a/src/ui/touch.h b/src/ui/touch.h
index 39a059da..19a927ab 100644
--- a/src/ui/touch.h
+++ b/src/ui/touch.h
@@ -30,3 +30,5 @@ iDeclareType(Widget)
30iBool processEvent_Touch (const SDL_Event *); 30iBool processEvent_Touch (const SDL_Event *);
31void update_Touch (void); 31void update_Touch (void);
32void widgetDestroyed_Touch (iWidget *widget); 32void widgetDestroyed_Touch (iWidget *widget);
33
34size_t numFingers_Touch (void);