Falkon Develop
Cross-platform Qt-based web browser
mousegesturerecognizer.h
Go to the documentation of this file.
1/*
2 * This file is part of the mouse gesture package.
3 * Copyright (C) 2006 Johan Thelin <e8johan@gmail.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the
8 * following conditions are met:
9 *
10 * - Redistributions of source code must retain the above
11 * copyright notice, this list of conditions and the
12 * following disclaimer.
13 * - Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions and
15 * the following disclaimer in the documentation and/or
16 * other materials provided with the distribution.
17 * - The names of its contributors may be used to endorse
18 * or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38#ifndef MOUSEGESTURERECOGNIZER_H
39#define MOUSEGESTURERECOGNIZER_H
40
41#include <list>
42#include <vector>
43
44namespace Gesture
45{
46
47/*
48 * Sub-class and implement callback method and register along a gesture description.
49 */
51{
52public:
53 virtual void callback() = 0;
55};
56
57/*
58 * The available directions.
59 */
61/*
62 * A list of directions.
63 */
64typedef std::list<Direction> DirectionList;
65
66/*
67 * Create lists of directions and connect to a callback.
68 */
71
74};
75
76/*
77 * Data types for internal use
78 */
79struct Pos {
80 Pos(int ix, int iy) : x(ix), y(iy) {}
81
82 int x, y;
83};
84
85typedef std::vector<Pos> PosList;
86typedef std::vector<GestureDefinition> GestureList;
87
89{
90public:
91 MouseGestureRecognizer(int minimumMovement = 5, double minimumMatch = 0.9, bool allowDiagonals = false);
93
94 void addGestureDefinition(const GestureDefinition &gesture);
96
97 void startGesture(int x, int y);
98 void addPoint(int x, int y);
99 bool endGesture(int x, int y);
100 void abortGesture();
101 PosList currentPath() const;
102private:
103 bool recognizeGesture();
104
105 static PosList limitDirections(const PosList &positions, bool allowDiagnonals);
106 static PosList simplify(const PosList &positions);
107 static PosList removeShortest(const PosList &positions);
108 static int calcLength(const PosList &positions);
109
110 struct Private;
111 Private* d;
112};
113
114};
115
116#endif // MOUSEGESTURERECOGNIZER_H
117
MouseGestureRecognizer(int minimumMovement=5, double minimumMatch=0.9, bool allowDiagonals=false)
void addGestureDefinition(const GestureDefinition &gesture)
std::vector< Pos > PosList
std::list< Direction > DirectionList
std::vector< GestureDefinition > GestureList
GestureDefinition(const DirectionList &d, MouseGestureCallback *c)
MouseGestureCallback * callbackClass
Pos(int ix, int iy)