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