summaryrefslogtreecommitdiff
path: root/src/gestures-scroll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gestures-scroll.c')
-rw-r--r--src/gestures-scroll.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/gestures-scroll.c b/src/gestures-scroll.c
new file mode 100644
index 0000000..96e153b
--- /dev/null
+++ b/src/gestures-scroll.c
@@ -0,0 +1,74 @@
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
28void gru_reset_scroll(struct grail *ge,
29 const struct touch_frame *frame)
30{
31 struct gesture_inserter *gin = ge->gin;
32 struct gesture_recognizer *gru = ge->gru;
33 struct scroll_model *state = &gru->scroll;
34 struct move_model *move = &gru->move;
35 gin_gesture_discard_type(gin, GRAIL_TYPE_SCROLL);
36 state->x = move->x;
37 state->y = move->y;
38 state->active = 0;
39 state->moving = 0;
40}
41
42int gru_scroll(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 scroll_model *state = &gru->scroll;
48 struct move_model *move = &gru->move;
49 grail_prop_t prop[DIM_GRAIL_PROP];
50 float dx, dy;
51 int i;
52 dx = move->x - state->x;
53 dy = move->y - state->y;
54 if (fabs(dx) < 1 && fabs(dy) < 1)
55 return 0;
56 if (!state->active) {
57 i = gin_gesture_begin(ge, GRAIL_TYPE_SCROLL, 1,
58 frame->touches, sizeof(frame->touches));
59 state->geslot = i;
60 state->active = 1;
61 }
62 if (!state->moving && fabs(dx) < move->xbar && fabs(dy) < move->ybar)
63 return 0;
64 state->moving = 1;
65 prop[0] = dx;
66 prop[1] = dy;
67 gin_gesture_event(gin, state->geslot,
68 move->x, move->y, move->ntouch,
69 prop, 2);
70 state->x = move->x;
71 state->y = move->y;
72 return 1;
73}
74