diff options
Diffstat (limited to 'src/gestures.c')
-rw-r--r-- | src/gestures.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gestures.c b/src/gestures.c new file mode 100644 index 0000000..8dfb939 --- /dev/null +++ b/src/gestures.c @@ -0,0 +1,39 @@ +#include "gestures.h" + +/******************************************************/ + +void extract_gestures(struct Gestures *gs, struct MTouch* mt) +{ + const struct FingerState *b = mt->ns.finger; + const struct FingerState *e = b + mt->ns.nfinger; + const struct FingerState *p, *fs; + int nof = count_fingers(&mt->os); + int nsf = count_fingers(&mt->ns); + int dn = 0, i; + memset(gs, 0, sizeof(struct Gestures)); + if (nof == nsf) { + for (p = b; p != e; p++) { + if (fs = find_finger(&mt->os, p->id)) { + gs->dx += p->hw.position_x - fs->hw.position_x; + gs->dy += p->hw.position_y - fs->hw.position_y; + dn++; + } + } + } + if (gs->dx || gs->dy) { + gs->dx /= dn; + gs->dy /= dn; + if (nsf == 1) + SETBIT(gs->type, GS_MOVE); + } + for (i = 0; i < DIM_BUTTON; i++) { + if (GETBIT(mt->ns.button, i) != GETBIT(mt->os.button, i)) { + SETBIT(gs->type, GS_BUTTON); + gs->btix[gs->nbt] = i + 1; + gs->btval[gs->nbt] = GETBIT(mt->ns.button, i); + gs->nbt++; + } + } + mt->os = mt->ns; +} + |