From b8f7fdfe1b8974a6677e73cfe7c83da70a35f4ae Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sun, 9 Nov 2008 04:20:53 +0100 Subject: Gesture interface in place Signed-off-by: Henrik Rydberg --- src/gestures.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/gestures.c (limited to 'src/gestures.c') 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; +} + -- cgit v1.2.3