]> git.tdb.fi Git - libs/gui.git/commitdiff
Combine swipe gestures into a single drag gesture
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 Nov 2015 08:34:01 +0000 (10:34 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 Nov 2015 08:34:01 +0000 (10:34 +0200)
This makes them more versatile for different kinds of control schemes.
Directional swipes can still be approximated through the Control
interface.  Capturing swipe gestures is no longer easily possible, but
the capture interface is due for a rewrite to support activator controls
anyway.

source/input/gesturedetector.cpp
source/input/gesturedetector.h

index d626c5d08efc6dcbd909083651045c7f056c98db..cc027973fdc868a319bdce0fe5db5b312ed742a5 100644 (file)
@@ -26,14 +26,8 @@ GestureDetector::GestureDetector(Touchscreen &ts):
 
 string GestureDetector::get_button_name(unsigned btn) const
 {
 
 string GestureDetector::get_button_name(unsigned btn) const
 {
-       if(btn==GESTURE_SWIPE_DOWN)
-               return "Swipe down";
-       else if(btn==GESTURE_SWIPE_UP)
-               return "Swipe up";
-       else if(btn==GESTURE_SWIPE_LEFT)
-               return "Swipe left";
-       else if(btn==GESTURE_SWIPE_RIGHT)
-               return "Swipe right";
+       if(btn==GESTURE_DRAG)
+               return "Drag";
        else if(btn==GESTURE_PINCH)
                return "Pinch";
        else
        else if(btn==GESTURE_PINCH)
                return "Pinch";
        else
@@ -153,20 +147,10 @@ void GestureDetector::start_gesture()
        }
        else
        {
        }
        else
        {
-               // Allow a maximum deviation of about 26° to recognize a swipe gesture.
-               if(abs(p.x)>2*abs(p.y))
-                       current_gesture = (p.x>0 ? GESTURE_SWIPE_RIGHT : GESTURE_SWIPE_LEFT);
-               else if(abs(p.y)>2*abs(p.x))
-                       current_gesture = (p.y>0 ? GESTURE_SWIPE_UP : GESTURE_SWIPE_DOWN);
-               else
-                       invalid_gesture = true;
-
-               if(current_gesture!=GESTURE_NONE)
-               {
-                       active_points = 1;
-                       set_axis_value(0, p.down_x, true);
-                       set_axis_value(1, p.down_y, true);
-               }
+               current_gesture = GESTURE_DRAG;
+               active_points = 1;
+               set_axis_value(0, p.down_x, true);
+               set_axis_value(1, p.down_y, true);
        }
 
        update_progress();
        }
 
        update_progress();
@@ -179,14 +163,11 @@ void GestureDetector::update_progress()
 {
        TouchPoint &p = points[0];
 
 {
        TouchPoint &p = points[0];
 
-       if(current_gesture==GESTURE_SWIPE_DOWN)
-               set_axis_value(2, -p.y, true);
-       else if(current_gesture==GESTURE_SWIPE_UP)
-               set_axis_value(2, p.y, true);
-       else if(current_gesture==GESTURE_SWIPE_LEFT)
-               set_axis_value(2, -p.x, true);
-       else if(current_gesture==GESTURE_SWIPE_RIGHT)
+       if(current_gesture==GESTURE_DRAG)
+       {
                set_axis_value(2, p.x, true);
                set_axis_value(2, p.x, true);
+               set_axis_value(3, p.y, true);
+       }
        else if(current_gesture==GESTURE_PINCH)
        {
                TouchPoint &p2 = points[1];
        else if(current_gesture==GESTURE_PINCH)
        {
                TouchPoint &p2 = points[1];
@@ -197,6 +178,7 @@ void GestureDetector::update_progress()
                float dx = ddx+p.x-p2.x;
                float dy = ddy+p.y-p2.y;
                set_axis_value(2, sqrt(dx*dx+dy*dy)/sqrt(ddx*ddx+ddy*ddy)-1, true);
                float dx = ddx+p.x-p2.x;
                float dy = ddy+p.y-p2.y;
                set_axis_value(2, sqrt(dx*dx+dy*dy)/sqrt(ddx*ddx+ddy*ddy)-1, true);
+               set_axis_value(3, 0, true);
        }
 }
 
        }
 }
 
index b2d0d4fdd36139411c3fb61e8b1062e575ea3ba4..fdd083de0372feb7cb4cde113881f6175d1e27cb 100644 (file)
@@ -11,17 +11,14 @@ class Touchscreen;
 enum Gesture
 {
        GESTURE_NONE,
 enum Gesture
 {
        GESTURE_NONE,
-       GESTURE_SWIPE_DOWN,
-       GESTURE_SWIPE_UP,
-       GESTURE_SWIPE_LEFT,
-       GESTURE_SWIPE_RIGHT,
+       GESTURE_DRAG,
        GESTURE_PINCH
 };
 
 /**
 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
        GESTURE_PINCH
 };
 
 /**
 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
 absolute values greater than one.
 */
 class GestureDetector: public Device