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/gestures-tapping.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/gestures-tapping.c')
| -rw-r--r-- | src/gestures-tapping.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/gestures-tapping.c b/src/gestures-tapping.c new file mode 100644 index 0000000..453f77c --- /dev/null +++ b/src/gestures-tapping.c | |||
| @@ -0,0 +1,96 @@ | |||
| 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 | |||
| 28 | static const int TAP_INIT = 0; | ||
| 29 | static const int TAP_BEGIN = 1; | ||
| 30 | static const int TAP_END = 2; | ||
| 31 | static const int TAP_CANCEL = 3; | ||
| 32 | |||
| 33 | static const int TAP_MIN_GAP_MS = 25; | ||
| 34 | static const int TAP_MAX_GAP_MS = 400; | ||
| 35 | |||
| 36 | int gru_tapping(struct grail *ge, | ||
| 37 | const struct touch_frame *frame) | ||
| 38 | { | ||
| 39 | struct gesture_recognizer *gru = ge->gru; | ||
| 40 | struct tapping_model *state = &gru->tapping; | ||
| 41 | struct move_model *move = &gru->move; | ||
| 42 | grail_prop_t prop[DIM_GRAIL_PROP]; | ||
| 43 | if (state->status == TAP_CANCEL) { | ||
| 44 | if (move->ntouch) | ||
| 45 | return 0; | ||
| 46 | else | ||
| 47 | state->status = TAP_INIT; | ||
| 48 | } | ||
| 49 | if (move->ntouch > state->ntouch) { | ||
| 50 | if (!state->ntouch) { | ||
| 51 | state->start = frame->time; | ||
| 52 | state->status = TAP_BEGIN; | ||
| 53 | } | ||
| 54 | state->ntouch = move->ntouch; | ||
| 55 | } else if (move->ntouch < state->ntouch) { | ||
| 56 | if (!move->ntouch) | ||
| 57 | state->status = TAP_END; | ||
| 58 | } | ||
| 59 | if (state->status == TAP_INIT) | ||
| 60 | return 0; | ||
| 61 | if (state->ntouch < 1 || state->ntouch > 5) { | ||
| 62 | state->status = TAP_CANCEL; | ||
| 63 | } | ||
| 64 | if (frame->time - state->start > TAP_MAX_GAP_MS) { | ||
| 65 | state->status = TAP_CANCEL; | ||
| 66 | } | ||
| 67 | if (state->status == TAP_END && | ||
| 68 | frame->time - state->start < TAP_MIN_GAP_MS) { | ||
| 69 | state->status = TAP_CANCEL; | ||
| 70 | } | ||
| 71 | if (state->status == TAP_CANCEL) { | ||
| 72 | if (state->active) { | ||
| 73 | gru_end(ge, state->gid, move); | ||
| 74 | state->active = 0; | ||
| 75 | } | ||
| 76 | state->ntouch = 0; | ||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | if (frame->time - state->start < TAP_MIN_GAP_MS) | ||
| 80 | return 0; | ||
| 81 | if (!state->active) { | ||
| 82 | int type = GRAIL_TYPE_TAP1 + state->ntouch - 1; | ||
| 83 | state->gid = gin_gid_begin(ge, type, frame); | ||
| 84 | state->active = 1; | ||
| 85 | } | ||
| 86 | if (state->status != TAP_END) | ||
| 87 | return 0; | ||
| 88 | prop[0] = frame->time - state->start; | ||
| 89 | gin_gid_event(ge, state->gid, | ||
| 90 | move->x.val, move->y.val, state->ntouch, | ||
| 91 | prop, 1, GRAIL_STATUS_END); | ||
| 92 | state->status = TAP_INIT; | ||
| 93 | state->ntouch = 0; | ||
| 94 | state->active = 0; | ||
| 95 | return 1; | ||
| 96 | } | ||
