diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-01-02 11:00:52 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-01-02 12:39:07 +0100 |
| commit | c0666a895e7fe8e488332263fd106ced0ed7cab7 (patch) | |
| tree | fca88fbee4aaed6e1eed050a749ce6246a7f1966 /src/grail-gestures.c | |
| parent | 1e07054fbeab6e90f104c279d3246097dd838a17 (diff) | |
Replace touch logic with utouch frame engine
The original grail uses an internal touch framework and exports some
touch information as extended attributes to gesture events. This was
never quite the intention, but rather to expose gestures and touches
on a similar footing, such that grail can be input agnostic. This
patch starts off by replacing the internal touch framework with the
utouch-frame engine.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/grail-gestures.c')
| -rw-r--r-- | src/grail-gestures.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/grail-gestures.c b/src/grail-gestures.c index ed937a4..035a199 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c | |||
| @@ -31,15 +31,15 @@ static const grail_time_t SAMPLE_MS = 10; | |||
| 31 | static const float EPS = 1e-3; | 31 | static const float EPS = 1e-3; |
| 32 | 32 | ||
| 33 | static void compute_position(float *x, float *y, | 33 | static void compute_position(float *x, float *y, |
| 34 | const struct touch_frame *frame) | 34 | const struct utouch_frame *frame) |
| 35 | { | 35 | { |
| 36 | int i, n = frame->nactive; | 36 | int i, n = frame->num_active; |
| 37 | *x = 0; | 37 | *x = 0; |
| 38 | *y = 0; | 38 | *y = 0; |
| 39 | if (n < 1) | 39 | if (n < 1) |
| 40 | return; | 40 | return; |
| 41 | for (i = 0; i < n; i++) { | 41 | for (i = 0; i < n; i++) { |
| 42 | const struct touch *t = frame->active[i]; | 42 | const struct utouch_contact *t = frame->active[i]; |
| 43 | *x += t->x; | 43 | *x += t->x; |
| 44 | *y += t->y; | 44 | *y += t->y; |
| 45 | } | 45 | } |
| @@ -48,14 +48,14 @@ static void compute_position(float *x, float *y, | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | static float compute_radius(float x, float y, | 50 | static float compute_radius(float x, float y, |
| 51 | const struct touch_frame *frame) | 51 | const struct utouch_frame *frame) |
| 52 | { | 52 | { |
| 53 | int i, n = frame->nactive; | 53 | int i, n = frame->num_active; |
| 54 | float r = 0, r2 = 0; | 54 | float r = 0, r2 = 0; |
| 55 | if (n < 2) | 55 | if (n < 2) |
| 56 | return r; | 56 | return r; |
| 57 | for (i = 0; i < n; i++) { | 57 | for (i = 0; i < n; i++) { |
| 58 | const struct touch *t = frame->active[i]; | 58 | const struct utouch_contact *t = frame->active[i]; |
| 59 | float dx = t->x - x; | 59 | float dx = t->x - x; |
| 60 | float dy = t->y - y; | 60 | float dy = t->y - y; |
| 61 | r2 += dx * dx + dy * dy; | 61 | r2 += dx * dx + dy * dy; |
| @@ -66,16 +66,15 @@ static float compute_radius(float x, float y, | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | static float compute_rotation(float x, float y, float r, | 68 | static float compute_rotation(float x, float y, float r, |
| 69 | const struct touch_frame *prev, | 69 | const struct utouch_frame *frame) |
| 70 | const struct touch_frame *frame) | ||
| 71 | { | 70 | { |
| 72 | int i, n = frame->nactive; | 71 | int i, n = frame->num_active; |
| 73 | float da = 0, darc2 = 0; | 72 | float da = 0, darc2 = 0; |
| 74 | if (n < 2) | 73 | if (n < 2) |
| 75 | return da; | 74 | return da; |
| 76 | for (i = 0; i < n; i++) { | 75 | for (i = 0; i < n; i++) { |
| 77 | const struct touch *t = frame->active[i]; | 76 | const struct utouch_contact *t = frame->active[i]; |
| 78 | const struct touch *ot = &prev->touch[t->slot]; | 77 | const struct utouch_contact *ot = t->prev; |
| 79 | float dx = t->x - x; | 78 | float dx = t->x - x; |
| 80 | float dy = t->y - y; | 79 | float dy = t->y - y; |
| 81 | float mx = t->x - ot->x; | 80 | float mx = t->x - ot->x; |
| @@ -142,13 +141,13 @@ static void move_update(struct move_model *m, int i, float x, grail_time_t t) | |||
| 142 | 141 | ||
| 143 | void gru_init_motion(struct grail *ge) | 142 | void gru_init_motion(struct grail *ge) |
| 144 | { | 143 | { |
| 145 | struct touch_caps *caps = &ge->impl->dev.caps; | 144 | struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh); |
| 146 | struct gesture_recognizer *gru = ge->gru; | 145 | struct gesture_recognizer *gru = ge->gru; |
| 147 | struct move_model *m = &gru->move; | 146 | struct move_model *m = &gru->move; |
| 148 | float D[DIM_FM]; | 147 | float D[DIM_FM]; |
| 149 | int i; | 148 | int i; |
| 150 | D[FM_X] = caps->max_x - caps->min_x; | 149 | D[FM_X] = s->max_x - s->min_x; |
| 151 | D[FM_Y] = caps->max_y - caps->min_y; | 150 | D[FM_Y] = s->max_y - s->min_y; |
| 152 | D[FM_R] = sqrt(D[FM_X] * D[FM_X] + D[FM_Y] * D[FM_Y]); | 151 | D[FM_R] = sqrt(D[FM_X] * D[FM_X] + D[FM_Y] * D[FM_Y]); |
| 153 | D[FM_A] = 2 * M_PI; | 152 | D[FM_A] = 2 * M_PI; |
| 154 | for (i = 0; i < DIM_FM; i++) { | 153 | for (i = 0; i < DIM_FM; i++) { |
| @@ -159,14 +158,15 @@ void gru_init_motion(struct grail *ge) | |||
| 159 | } | 158 | } |
| 160 | 159 | ||
| 161 | void gru_motion(struct grail *ge, | 160 | void gru_motion(struct grail *ge, |
| 162 | const struct touch_frame *frame) | 161 | const struct utouch_frame *frame) |
| 163 | { | 162 | { |
| 164 | struct gesture_recognizer *gru = ge->gru; | 163 | struct gesture_recognizer *gru = ge->gru; |
| 165 | struct move_model *m = &gru->move; | 164 | struct move_model *m = &gru->move; |
| 166 | grail_time_t t = frame->time; | 165 | grail_time_t t = frame->time; |
| 167 | float x, y, r, a; | 166 | float x, y, r, a; |
| 167 | |||
| 168 | compute_position(&x, &y, frame); | 168 | compute_position(&x, &y, frame); |
| 169 | if (frame->ncreate || frame->ndestroy) { | 169 | if (frame->prev->revision != frame->revision) { |
| 170 | r = compute_radius(x, y, frame); | 170 | r = compute_radius(x, y, frame); |
| 171 | a = 0; | 171 | a = 0; |
| 172 | move_reset(m, FM_X, x, t); | 172 | move_reset(m, FM_X, x, t); |
| @@ -175,7 +175,7 @@ void gru_motion(struct grail *ge, | |||
| 175 | move_reset(m, FM_A, a, t); | 175 | move_reset(m, FM_A, a, t); |
| 176 | m->single = 0; | 176 | m->single = 0; |
| 177 | m->multi = 0; | 177 | m->multi = 0; |
| 178 | } else if (frame->nactive < 2) { | 178 | } else if (frame->num_active < 2) { |
| 179 | r = 0; | 179 | r = 0; |
| 180 | a = 0; | 180 | a = 0; |
| 181 | move_update(m, FM_X, x, t); | 181 | move_update(m, FM_X, x, t); |
| @@ -190,7 +190,7 @@ void gru_motion(struct grail *ge, | |||
| 190 | r = compute_radius(x, y, frame); | 190 | r = compute_radius(x, y, frame); |
| 191 | r = move_filter(&m->fm[FM_R], r); | 191 | r = move_filter(&m->fm[FM_R], r); |
| 192 | a = m->fm[FM_A].value; | 192 | a = m->fm[FM_A].value; |
| 193 | a += compute_rotation(x, y, r, &gru->frame, frame); | 193 | a += compute_rotation(x, y, r, frame); |
| 194 | a = move_filter(&m->fm[FM_A], a); | 194 | a = move_filter(&m->fm[FM_A], a); |
| 195 | move_update(m, FM_X, x, t); | 195 | move_update(m, FM_X, x, t); |
| 196 | move_update(m, FM_Y, y, t); | 196 | move_update(m, FM_Y, y, t); |
| @@ -199,7 +199,7 @@ void gru_motion(struct grail *ge, | |||
| 199 | m->single = 0; | 199 | m->single = 0; |
| 200 | m->multi = 1; | 200 | m->multi = 1; |
| 201 | } | 201 | } |
| 202 | m->ntouch = frame->nactive; | 202 | m->ntouch = frame->num_active; |
| 203 | m->time = t; | 203 | m->time = t; |
| 204 | } | 204 | } |
| 205 | 205 | ||
