diff options
| author | Henrik Rydberg <rydberg@bitmath.org> | 2010-08-04 16:47:43 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-05 22:48:38 +0200 |
| commit | 697b5b5c7d2b1c46387061fcbed24cbee51d98ce (patch) | |
| tree | b8e8dbf02453f7c7dc31c691822a088123d21cd8 /src/grail-gestures.c | |
| parent | 642d7ee26f347152a106d48ddad37a8059d36fb1 (diff) | |
Introduce tapping
Simplify some common parts of the recognizer code and add tapping
to the gesture suite.
Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/grail-gestures.c')
| -rw-r--r-- | src/grail-gestures.c | 128 |
1 files changed, 83 insertions, 45 deletions
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 @@ | |||
| 25 | #include "grail-recognizer.h" | 25 | #include "grail-recognizer.h" |
| 26 | #include <math.h> | 26 | #include <math.h> |
| 27 | 27 | ||
| 28 | static const float SN_MOVE = 50; | 28 | static const float SN_MOVE = 200; |
| 29 | static const float SN_ZOOM = 50; | 29 | static const float SN_ZOOM = 200; |
| 30 | static const float SN_ROTATE = 200; | 30 | static const float SN_ROTATE = 200; |
| 31 | static const float BAR_MOVE = 1; | 31 | static const float BAR_MOVE = 4; |
| 32 | static const float BAR_ZOOM = 2; | 32 | static const float BAR_ZOOM = 12; |
| 33 | static const float BAR_ROTATE = 4; | 33 | static const float BAR_ROTATE = 12; |
| 34 | 34 | ||
| 35 | static void compute_position(float *x, float *y, | 35 | static void compute_position(float *x, float *y, |
| 36 | const struct touch_frame *frame) | 36 | const struct touch_frame *frame) |
| @@ -89,15 +89,34 @@ static float compute_rotation(float x, float y, float r, | |||
| 89 | return da; | 89 | return da; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | static float move_filter(float x, float x0, float fuzz) | 92 | static float move_filter(const struct filter_model *m, float val) |
| 93 | { | 93 | { |
| 94 | if (x > x0 - fuzz / 2 && x < x0 + fuzz / 2) | 94 | if (val > m->val - m->fuzz / 2 && val < m->val + m->fuzz / 2) |
| 95 | return x0; | 95 | return m->val; |
| 96 | if (x > x0 - fuzz && x < x0 + fuzz) | 96 | if (val > m->val - m->fuzz && val < m->val + m->fuzz) |
| 97 | return (x0 * 3 + x) / 4; | 97 | return (m->val * 3 + val) / 4; |
| 98 | if (x > x0 - fuzz * 2 && x < x0 + fuzz * 2) | 98 | if (val > m->val - m->fuzz * 2 && val < m->val + m->fuzz * 2) |
| 99 | return (x0 + x) / 2; | 99 | return (m->val + val) / 2; |
| 100 | return x; | 100 | return val; |
| 101 | } | ||
| 102 | |||
| 103 | static int move_reset(struct filter_model *m, float val) | ||
| 104 | { | ||
| 105 | m->delta = 0; | ||
| 106 | m->tickle = 0; | ||
| 107 | m->active = 0; | ||
| 108 | m->val = val; | ||
| 109 | m->orig = val; | ||
| 110 | } | ||
| 111 | |||
| 112 | static int move_update(struct filter_model *m, float val) | ||
| 113 | { | ||
| 114 | m->delta = val - m->val; | ||
| 115 | m->tickle = fabs(m->delta) > 0; | ||
| 116 | m->val = val; | ||
| 117 | if (!m->active && fabs(val - m->orig) > m->bar) | ||
| 118 | m->active = 1; | ||
| 119 | return m->active; | ||
| 101 | } | 120 | } |
| 102 | 121 | ||
| 103 | void gru_init_motion(struct grail *ge, const struct touch_dev_caps *caps) | 122 | 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) | |||
| 107 | float x = caps->info[TP_POS_X].maximum - caps->info[TP_POS_X].minimum; | 126 | float x = caps->info[TP_POS_X].maximum - caps->info[TP_POS_X].minimum; |
| 108 | float y = caps->info[TP_POS_Y].maximum - caps->info[TP_POS_Y].minimum; | 127 | float y = caps->info[TP_POS_Y].maximum - caps->info[TP_POS_Y].minimum; |
| 109 | float r = sqrt(x * x + y * y); | 128 | float r = sqrt(x * x + y * y); |
| 110 | state->xfuzz = x / SN_MOVE; | 129 | state->x.fuzz = x / SN_MOVE; |
| 111 | state->yfuzz = y / SN_MOVE; | 130 | state->y.fuzz = y / SN_MOVE; |
| 112 | state->rfuzz = r / SN_ZOOM; | 131 | state->r.fuzz = r / SN_ZOOM; |
| 113 | state->afuzz = r / SN_ROTATE; | 132 | state->a.fuzz = r / SN_ROTATE; |
| 114 | state->xbar = BAR_MOVE * state->xfuzz; | 133 | state->x.bar = BAR_MOVE * state->x.fuzz; |
| 115 | state->ybar = BAR_MOVE * state->yfuzz; | 134 | state->y.bar = BAR_MOVE * state->y.fuzz; |
| 116 | state->rbar = BAR_ZOOM * state->rfuzz; | 135 | state->r.bar = BAR_ZOOM * state->r.fuzz; |
| 117 | state->abar = BAR_ROTATE * state->afuzz; | 136 | state->a.bar = BAR_ROTATE * state->a.fuzz; |
| 137 | state->motion = 0; | ||
| 118 | } | 138 | } |
| 119 | 139 | ||
| 120 | void gru_reset_motion(struct grail *ge, | 140 | void gru_motion(struct grail *ge, |
| 121 | const struct touch_frame *frame) | 141 | const struct touch_frame *frame) |
| 122 | { | 142 | { |
| 123 | struct gesture_recognizer *gru = ge->gru; | 143 | struct gesture_recognizer *gru = ge->gru; |
| 124 | struct move_model *state = &gru->move; | 144 | struct move_model *state = &gru->move; |
| 125 | compute_position(&state->x, &state->y, frame); | 145 | int na = 0, nt = frame->nactive; |
| 126 | state->r = compute_radius(state->x, state->y, frame); | 146 | float x, y, r, a; |
| 127 | state->a = 0; | 147 | compute_position(&x, &y, frame); |
| 128 | state->ntouch = frame->nactive; | 148 | if (nt < 2 || frame->ncreate || frame->ndestroy) { |
| 149 | r = compute_radius(x, y, frame); | ||
| 150 | a = 0; | ||
| 151 | move_reset(&state->x, x); | ||
| 152 | move_reset(&state->y, y); | ||
| 153 | move_reset(&state->r, r); | ||
| 154 | move_reset(&state->a, a); | ||
| 155 | state->motion = 0; | ||
| 156 | } else { | ||
| 157 | x = move_filter(&state->x, x); | ||
| 158 | y = move_filter(&state->y, y); | ||
| 159 | r = compute_radius(x, y, frame); | ||
| 160 | r = move_filter(&state->r, r); | ||
| 161 | a = state->a.val + compute_rotation(x, y, r, &gru->frame, frame); | ||
| 162 | //a = move_filter(&state->a, a); | ||
| 163 | na += move_update(&state->x, x); | ||
| 164 | na += move_update(&state->y, y); | ||
| 165 | na += move_update(&state->r, r); | ||
| 166 | na += move_update(&state->a, a); | ||
| 167 | state->motion = 1; | ||
| 168 | } | ||
| 169 | state->nactive = na; | ||
| 170 | state->ntouch = nt; | ||
| 171 | state->time = frame->time; | ||
| 129 | } | 172 | } |
| 130 | 173 | ||
| 131 | void gru_compute_motion(struct grail *ge, | 174 | void gru_event(struct grail *ge, int gid, |
| 132 | const struct touch_frame *frame) | 175 | const struct move_model *move, |
| 176 | const grail_prop_t *prop, int nprop) | ||
| 133 | { | 177 | { |
| 134 | struct gesture_inserter *gin = ge->gin; | 178 | gin_gid_event(ge, gid, |
| 135 | struct gesture_recognizer *gru = ge->gru; | 179 | move->x.val, move->y.val, move->ntouch, |
| 136 | struct move_model *state = &gru->move; | 180 | prop, nprop, |
| 137 | float x, y, r, a; | 181 | GRAIL_STATUS_UPDATE); |
| 138 | compute_position(&x, &y, frame); | ||
| 139 | x = move_filter(x, state->x, state->xfuzz); | ||
| 140 | y = move_filter(y, state->y, state->yfuzz); | ||
| 141 | r = compute_radius(x, y, frame); | ||
| 142 | r = move_filter(r, state->r, state->rfuzz); | ||
| 143 | a = state->a + compute_rotation(x, y, r, &gru->frame, frame); | ||
| 144 | a = move_filter(a, state->a, state->afuzz); | ||
| 145 | state->x = x; | ||
| 146 | state->y = y; | ||
| 147 | state->r = r; | ||
| 148 | state->a = a; | ||
| 149 | state->ntouch = frame->nactive; | ||
| 150 | } | 182 | } |
| 183 | |||
| 184 | void gru_end(struct grail *ge, int gid, const struct move_model *move) | ||
| 185 | { | ||
| 186 | gin_gid_end(ge, gid, move->x.val, move->y.val, move->ntouch); | ||
| 187 | } | ||
| 188 | |||
