summaryrefslogtreecommitdiff
path: root/src/gestures-zoom.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gestures-zoom.c')
-rw-r--r--src/gestures-zoom.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/gestures-zoom.c b/src/gestures-zoom.c
new file mode 100644
index 0000000..9e05b8b
--- /dev/null
+++ b/src/gestures-zoom.c
@@ -0,0 +1,71 @@
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_zoom(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 zoom_model *state = &gru->zoom;
35 struct move_model *move = &gru->move;
36 gin_gesture_discard_type(gin, GRAIL_TYPE_ZOOM);
37 state->r = move->r;
38 state->active = 0;
39 state->zooming = 0;
40}
41
42int gru_zoom(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 zoom_model *state = &gru->zoom;
48 struct move_model *move = &gru->move;
49 grail_prop_t prop[DIM_GRAIL_PROP];
50 float dr;
51 int i;
52 dr = move->r - state->r;
53 if (fabs(dr) < 1)
54 return 0;
55 if (!state->active) {
56 i = gin_gesture_begin(ge,
57 GRAIL_TYPE_ZOOM, 1,
58 frame->touches, sizeof(frame->touches));
59 state->geslot = i;
60 state->active = 1;
61 }
62 if (!state->zooming && fabs(dr) < move->rbar)
63 return 0;
64 state->zooming = 1;
65 prop[0] = dr;
66 gin_gesture_event(gin, state->geslot,
67 move->x, move->y, move->ntouch,
68 prop, 1);
69 state->r = move->r;
70 return 1;
71}