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