]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/gesturedetector.h
Update .gitignore to include build products on Windows
[libs/gui.git] / source / input / gesturedetector.h
index 2b5ea3c3203219d2153b78cd22e19c65aed3d291..8804dd1abc76a073439a1dae8d8fb64bd33cc4ce 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_INPUT_GESTUREDETECTOR_H_
 #define MSP_INPUT_GESTUREDETECTOR_H_
 
+#include <msp/graphics/mspgui_api.h>
 #include "device.h"
 
 namespace Msp {
@@ -11,22 +12,27 @@ class Touchscreen;
 enum Gesture
 {
        GESTURE_NONE,
-       GESTURE_SWIPE_DOWN,
-       GESTURE_SWIPE_UP,
-       GESTURE_SWIPE_LEFT,
-       GESTURE_SWIPE_RIGHT,
-       GESTURE_PINCH
+       GESTURE_TAP,
+       GESTURE_TAP_2,
+       GESTURE_TAP_3,
+       GESTURE_DRAG,
+       GESTURE_DRAG_2,
+       GESTURE_DRAG_3,
+       GESTURE_PINCH,
+       GESTURE_ROTATE
 };
 
 /**
 Interprets events from a Touchscreen as high-level gestures.  One button is
 provided for each type of gesture.  Axes 0 and 1 indicate the starting position
-of the gesture; axis 2 tracks its progress.  The progress axis may exhibit
+of the gesture; axes 2 and 3 track its progress.  The progress axis may exhibit
 absolute values greater than one.
 */
-class GestureDetector: public Device
+class MSPGUI_API GestureDetector: public Device
 {
 private:
+       static constexpr size_t MAX_POINTS = 3;
+
        struct TouchPoint
        {
                bool down;
@@ -34,33 +40,40 @@ private:
                float down_y;
                float x;
                float y;
+               bool threshold_exceeded;
 
                TouchPoint();
        };
 
        Touchscreen &touchscreen;
-       TouchPoint points[3];
-       Gesture current_gesture;
-       unsigned active_points;
-       bool invalid_gesture;
-       float threshold_x_sq;
-       float threshold_y_sq;
+       TouchPoint points[MAX_POINTS];
+       Gesture current_gesture = GESTURE_NONE;
+       Gesture pending_tap = GESTURE_NONE;
+       bool invalid_gesture = false;
+       float threshold_x_sq = 1.0f;
+       float threshold_y_sq = 1.0f;
 
 public:
        GestureDetector(Touchscreen &);
 
-       virtual std::string get_button_name(unsigned) const;
-       virtual std::string get_axis_name(unsigned) const;
+       std::string get_button_name(unsigned) const override;
+       std::string get_axis_name(unsigned) const override;
 
 private:
        void touch_down(unsigned);
        void touch_up(unsigned);
        void touch_move(unsigned, float, float);
        void start_gesture();
+       void set_gesture_location(unsigned);
+       void set_gesture_delta(unsigned);
        void update_progress();
+       void end_gesture();
        void window_resized(unsigned, unsigned);
 };
 
+
+MSPGUI_API unsigned gesture_points(Gesture);
+
 } // namespace Input
 } // namespace Msp