summaryrefslogtreecommitdiff
path: root/src/gestures-combo.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-08-03 15:01:50 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commitd07c43f9f19dc0ee38aaf44947cfc396f437490e (patch)
tree2f9af561594a1de5553ba85b69b50bee421d5507 /src/gestures-combo.c
parent342a43e7b2ceec1dd200bffa24b052fec33f5bdc (diff)
Introduce zoom, rotate and combo gestures
Introduce grail_mask bit functions, and add new gestures as separate functions, referring to the same move model. Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/gestures-combo.c')
-rw-r--r--src/gestures-combo.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/gestures-combo.c b/src/gestures-combo.c
new file mode 100644
index 0000000..4ecd1e4
--- /dev/null
+++ b/src/gestures-combo.c
@@ -0,0 +1,82 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include "grail-recognizer.h"
26#include <math.h>
27#include <stdio.h>
28
29void gru_reset_combo(struct grail *ge,
30 const struct touch_frame *frame)
31{
32 struct gesture_inserter *gin = ge->gin;
33 struct gesture_recognizer *gru = ge->gru;
34 struct combo_model *state = &gru->combo;
35 struct move_model *move = &gru->move;
36 gin_gesture_discard_type(gin, GRAIL_TYPE_SZRCOMBO);
37 state->r = move->r;
38 state->active = 0;
39 state->running = 0;
40}
41
42int gru_combo(struct grail *ge,
43 const struct touch_frame *frame)
44{
45 struct gesture_inserter *gin = ge->gin;
46 struct gesture_recognizer *gru = ge->gru;
47 struct combo_model *state = &gru->combo;
48 struct move_model *move = &gru->move;
49 grail_prop_t prop[DIM_GRAIL_PROP];
50 float dx, dy, dr, da;
51 int i;
52 dx = move->x - state->x;
53 dy = move->y - state->y;
54 dr = move->r - state->r;
55 da = move->a - state->a;
56 if (fabs(dx) < 1 && fabs(dy) < 1 && fabs(da) < 1 && fabs(dr) < 1)
57 return 0;
58 if (!state->active) {
59 i = gin_gesture_begin(ge,
60 GRAIL_TYPE_SZRCOMBO, 2,
61 frame->touches, sizeof(frame->touches));
62 state->geslot = i;
63 state->active = 1;
64 }
65 if (!state->running &&
66 fabs(dx) < move->xbar && fabs(dy) < move->ybar &&
67 fabs(da) < move->abar && fabs(dr) < move->rbar)
68 return 0;
69 state->running = 1;
70 prop[0] = dx;
71 prop[1] = dy;
72 prop[2] = dr;
73 prop[3] = da;
74 gin_gesture_event(gin, state->geslot,
75 move->x, move->y, move->ntouch,
76 prop, 4);
77 state->x = move->x;
78 state->y = move->y;
79 state->r = move->r;
80 state->a = move->a;
81 return 1;
82}