From 9b020a9c6ff875c5f6511b50480f07beabb9a694 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Wed, 11 Aug 2010 17:30:43 +0100 Subject: split out bounding box computation Signed-off-by: Henrik Rydberg --- src/gestures-pinch.c | 28 ++++++---------------------- src/grail-gestures.c | 24 ++++++++++++++++++++++++ src/grail-gestures.h | 2 ++ 3 files changed, 32 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/gestures-pinch.c b/src/gestures-pinch.c index 91e6504..d05b06f 100644 --- a/src/gestures-pinch.c +++ b/src/gestures-pinch.c @@ -39,34 +39,18 @@ static void set_props(struct combo_model *s, const struct move_model *m, const struct touch_frame *frame) { - float x1, y1, x2, y2, x, y; - int i; + struct grail_coord min, max; s->prop[GRAIL_PROP_PINCH_DR] = m->fm[FM_R].action_delta; s->prop[GRAIL_PROP_PINCH_VR] = m->fm[FM_R].velocity; s->prop[GRAIL_PROP_PINCH_R] = m->fm[FM_R].value; s->nprop = 3; if (!frame->nactive) return; - x = frame->active[0]->prop[TP_POS_X]; - y = frame->active[0]->prop[TP_POS_Y]; - x1 = x2 = x; - y1 = y2 = y; - for (i = 1; i < frame->nactive; i++) { - x = frame->active[i]->prop[TP_POS_X]; - y = frame->active[i]->prop[TP_POS_Y]; - if (x < x1) - x1 = x; - if (y < y1) - y1 = y; - if (x > x2) - x2 = x; - if (y > y2) - y2 = y; - } - s->prop[GRAIL_PROP_PINCH_X1] = x1; - s->prop[GRAIL_PROP_PINCH_Y1] = y1; - s->prop[GRAIL_PROP_PINCH_X2] = x2; - s->prop[GRAIL_PROP_PINCH_Y2] = y2; + gru_compute_bbox(&min, &max, frame); + s->prop[GRAIL_PROP_PINCH_X1] = min.x; + s->prop[GRAIL_PROP_PINCH_Y1] = min.y; + s->prop[GRAIL_PROP_PINCH_X2] = max.x; + s->prop[GRAIL_PROP_PINCH_Y2] = max.y; s->nprop = 7; } diff --git a/src/grail-gestures.c b/src/grail-gestures.c index f1e2093..33d848c 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c @@ -218,3 +218,27 @@ void gru_end(struct grail *ge, int gid, const struct move_model *m, prop, nprop); } +void gru_compute_bbox(struct grail_coord *min, struct grail_coord *max, + const struct touch_frame *frame) +{ + float x, y; + int i; + if (frame->nactive < 1) + return; + x = frame->active[0]->prop[TP_POS_X]; + y = frame->active[0]->prop[TP_POS_Y]; + min->x = max->x = x; + min->y = max->y = y; + for (i = 1; i < frame->nactive; i++) { + x = frame->active[i]->prop[TP_POS_X]; + y = frame->active[i]->prop[TP_POS_Y]; + if (x < min->x) + min->x = x; + if (y < min->y) + min->y = y; + if (x > max->x) + max->x = x; + if (y > max->y) + max->y = y; + } +} diff --git a/src/grail-gestures.h b/src/grail-gestures.h index e716757..edd641b 100644 --- a/src/grail-gestures.h +++ b/src/grail-gestures.h @@ -68,6 +68,8 @@ void gru_event(struct grail *ge, int gid, void gru_end(struct grail *ge, int gid, const struct move_model *move, const grail_prop_t *prop, int nprop); +void gru_compute_bbox(struct grail_coord *min, struct grail_coord *max, + const struct touch_frame *frame); struct combo_model { int active, gid; -- cgit v1.2.3