]> git.tdb.fi Git - libs/gui.git/blob - source/input/gesturedetector.h
Implement additional two-finger gestures
[libs/gui.git] / source / input / gesturedetector.h
1 #ifndef MSP_INPUT_GESTUREDETECTOR_H_
2 #define MSP_INPUT_GESTUREDETECTOR_H_
3
4 #include "device.h"
5
6 namespace Msp {
7 namespace Input {
8
9 class Touchscreen;
10
11 enum Gesture
12 {
13         GESTURE_NONE,
14         GESTURE_DRAG,
15         GESTURE_DRAG_2,
16         GESTURE_PINCH,
17         GESTURE_ROTATE
18 };
19
20 /**
21 Interprets events from a Touchscreen as high-level gestures.  One button is
22 provided for each type of gesture.  Axes 0 and 1 indicate the starting position
23 of the gesture; axes 2 and 3 track its progress.  The progress axis may exhibit
24 absolute values greater than one.
25 */
26 class GestureDetector: public Device
27 {
28 private:
29         enum
30         {
31                 MAX_POINTS = 3
32         };
33
34         struct TouchPoint
35         {
36                 bool down;
37                 float down_x;
38                 float down_y;
39                 float x;
40                 float y;
41                 bool threshold_exceeded;
42
43                 TouchPoint();
44         };
45
46         Touchscreen &touchscreen;
47         TouchPoint points[MAX_POINTS];
48         Gesture current_gesture;
49         unsigned active_points;
50         bool invalid_gesture;
51         float threshold_x_sq;
52         float threshold_y_sq;
53
54 public:
55         GestureDetector(Touchscreen &);
56
57         virtual std::string get_button_name(unsigned) const;
58         virtual std::string get_axis_name(unsigned) const;
59
60 private:
61         void touch_down(unsigned);
62         void touch_up(unsigned);
63         void touch_move(unsigned, float, float);
64         void start_gesture();
65         void update_progress();
66         void end_gesture();
67         void window_resized(unsigned, unsigned);
68 };
69
70 } // namespace Input
71 } // namespace Msp
72
73 #endif