From 697b5b5c7d2b1c46387061fcbed24cbee51d98ce Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Wed, 4 Aug 2010 16:47:43 +0200 Subject: Introduce tapping Simplify some common parts of the recognizer code and add tapping to the gesture suite. Signed-off-by: Henrik Rydberg --- src/grail-gestures.c | 128 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 45 deletions(-) (limited to 'src/grail-gestures.c') diff --git a/src/grail-gestures.c b/src/grail-gestures.c index d79da96..27f160b 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c @@ -25,12 +25,12 @@ #include "grail-recognizer.h" #include -static const float SN_MOVE = 50; -static const float SN_ZOOM = 50; +static const float SN_MOVE = 200; +static const float SN_ZOOM = 200; static const float SN_ROTATE = 200; -static const float BAR_MOVE = 1; -static const float BAR_ZOOM = 2; -static const float BAR_ROTATE = 4; +static const float BAR_MOVE = 4; +static const float BAR_ZOOM = 12; +static const float BAR_ROTATE = 12; static void compute_position(float *x, float *y, const struct touch_frame *frame) @@ -89,15 +89,34 @@ static float compute_rotation(float x, float y, float r, return da; } -static float move_filter(float x, float x0, float fuzz) +static float move_filter(const struct filter_model *m, float val) { - if (x > x0 - fuzz / 2 && x < x0 + fuzz / 2) - return x0; - if (x > x0 - fuzz && x < x0 + fuzz) - return (x0 * 3 + x) / 4; - if (x > x0 - fuzz * 2 && x < x0 + fuzz * 2) - return (x0 + x) / 2; - return x; + if (val > m->val - m->fuzz / 2 && val < m->val + m->fuzz / 2) + return m->val; + if (val > m->val - m->fuzz && val < m->val + m->fuzz) + return (m->val * 3 + val) / 4; + if (val > m->val - m->fuzz * 2 && val < m->val + m->fuzz * 2) + return (m->val + val) / 2; + return val; +} + +static int move_reset(struct filter_model *m, float val) +{ + m->delta = 0; + m->tickle = 0; + m->active = 0; + m->val = val; + m->orig = val; +} + +static int move_update(struct filter_model *m, float val) +{ + m->delta = val - m->val; + m->tickle = fabs(m->delta) > 0; + m->val = val; + if (!m->active && fabs(val - m->orig) > m->bar) + m->active = 1; + return m->active; } void gru_init_motion(struct grail *ge, const struct touch_dev_caps *caps) @@ -107,44 +126,63 @@ void gru_init_motion(struct grail *ge, const struct touch_dev_caps *caps) float x = caps->info[TP_POS_X].maximum - caps->info[TP_POS_X].minimum; float y = caps->info[TP_POS_Y].maximum - caps->info[TP_POS_Y].minimum; float r = sqrt(x * x + y * y); - state->xfuzz = x / SN_MOVE; - state->yfuzz = y / SN_MOVE; - state->rfuzz = r / SN_ZOOM; - state->afuzz = r / SN_ROTATE; - state->xbar = BAR_MOVE * state->xfuzz; - state->ybar = BAR_MOVE * state->yfuzz; - state->rbar = BAR_ZOOM * state->rfuzz; - state->abar = BAR_ROTATE * state->afuzz; + state->x.fuzz = x / SN_MOVE; + state->y.fuzz = y / SN_MOVE; + state->r.fuzz = r / SN_ZOOM; + state->a.fuzz = r / SN_ROTATE; + state->x.bar = BAR_MOVE * state->x.fuzz; + state->y.bar = BAR_MOVE * state->y.fuzz; + state->r.bar = BAR_ZOOM * state->r.fuzz; + state->a.bar = BAR_ROTATE * state->a.fuzz; + state->motion = 0; } -void gru_reset_motion(struct grail *ge, - const struct touch_frame *frame) +void gru_motion(struct grail *ge, + const struct touch_frame *frame) { struct gesture_recognizer *gru = ge->gru; struct move_model *state = &gru->move; - compute_position(&state->x, &state->y, frame); - state->r = compute_radius(state->x, state->y, frame); - state->a = 0; - state->ntouch = frame->nactive; + int na = 0, nt = frame->nactive; + float x, y, r, a; + compute_position(&x, &y, frame); + if (nt < 2 || frame->ncreate || frame->ndestroy) { + r = compute_radius(x, y, frame); + a = 0; + move_reset(&state->x, x); + move_reset(&state->y, y); + move_reset(&state->r, r); + move_reset(&state->a, a); + state->motion = 0; + } else { + x = move_filter(&state->x, x); + y = move_filter(&state->y, y); + r = compute_radius(x, y, frame); + r = move_filter(&state->r, r); + a = state->a.val + compute_rotation(x, y, r, &gru->frame, frame); + //a = move_filter(&state->a, a); + na += move_update(&state->x, x); + na += move_update(&state->y, y); + na += move_update(&state->r, r); + na += move_update(&state->a, a); + state->motion = 1; + } + state->nactive = na; + state->ntouch = nt; + state->time = frame->time; } -void gru_compute_motion(struct grail *ge, - const struct touch_frame *frame) +void gru_event(struct grail *ge, int gid, + const struct move_model *move, + const grail_prop_t *prop, int nprop) { - struct gesture_inserter *gin = ge->gin; - struct gesture_recognizer *gru = ge->gru; - struct move_model *state = &gru->move; - float x, y, r, a; - compute_position(&x, &y, frame); - x = move_filter(x, state->x, state->xfuzz); - y = move_filter(y, state->y, state->yfuzz); - r = compute_radius(x, y, frame); - r = move_filter(r, state->r, state->rfuzz); - a = state->a + compute_rotation(x, y, r, &gru->frame, frame); - a = move_filter(a, state->a, state->afuzz); - state->x = x; - state->y = y; - state->r = r; - state->a = a; - state->ntouch = frame->nactive; + gin_gid_event(ge, gid, + move->x.val, move->y.val, move->ntouch, + prop, nprop, + GRAIL_STATUS_UPDATE); } + +void gru_end(struct grail *ge, int gid, const struct move_model *move) +{ + gin_gid_end(ge, gid, move->x.val, move->y.val, move->ntouch); +} + -- cgit v1.2.3