]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/gesturedetector.cpp
Alter the starting condition for gestures
[libs/gui.git] / source / input / gesturedetector.cpp
index 26968c03c988a16d1b0035c652a0bc6b991c64a6..97e3d56f0fc53a3e4a7eb0e271a2a0c060303603 100644 (file)
@@ -31,10 +31,14 @@ string GestureDetector::get_button_name(unsigned btn) const
                return "Tap";
        else if(btn==GESTURE_TAP_2)
                return "Two-finger tap";
+       else if(btn==GESTURE_TAP_3)
+               return "Three-finger tap";
        else if(btn==GESTURE_DRAG)
                return "Drag";
        else if(btn==GESTURE_DRAG_2)
                return "Two-finger drag";
+       else if(btn==GESTURE_DRAG_3)
+               return "Three-finger drag";
        else if(btn==GESTURE_PINCH)
                return "Pinch";
        else if(btn==GESTURE_ROTATE)
@@ -76,6 +80,8 @@ void GestureDetector::touch_down(unsigned btn)
                        pending_tap = GESTURE_TAP;
                else if(btn==1)
                        pending_tap = GESTURE_TAP_2;
+               else if(btn==2)
+                       pending_tap = GESTURE_TAP_3;
        }
 }
 
@@ -144,16 +150,31 @@ void GestureDetector::start_gesture()
        if(!p.down)
                return;
 
-       /* At least one point needs to have moved more than the threshold to start
-       the gesture. */
-       bool threshold_exceeded = false;
-       for(unsigned i=0; (i<MAX_POINTS && !threshold_exceeded); ++i)
-               threshold_exceeded = (points[i].down && points[i].threshold_exceeded);
+       /* All held points need to have moved more than the threshold to start the
+       gesture. */
+       bool threshold_exceeded = true;
+       for(unsigned i=0; (i<MAX_POINTS && threshold_exceeded); ++i)
+               if(points[i].down && !points[i].threshold_exceeded)
+                       threshold_exceeded = false;
        if(!threshold_exceeded)
                return;
 
        invalid_gesture = false;
-       if(points[1].down)
+       if(points[2].down)
+       {
+               bool same_direction = true;
+               for(unsigned i=0; (same_direction && i<2); ++i)
+                       for(unsigned j=i+1; (same_direction && j<3); ++j)
+                       {
+                               TouchPoint &pi = points[i];
+                               TouchPoint &pj = points[j];
+                               same_direction = ((pi.x*pj.x+pi.y*pj.y)>2*abs(pi.x*pj.y-pi.y*pj.x));
+                       }
+
+               if(same_direction)
+                       current_gesture = GESTURE_DRAG_3;
+       }
+       else if(points[1].down)
        {
                TouchPoint &p2 = points[1];
                float ddx = p.down_x-p2.down_x;
@@ -217,7 +238,7 @@ void GestureDetector::set_gesture_delta(unsigned n_points)
 
 void GestureDetector::update_progress()
 {
-       if(current_gesture>=GESTURE_DRAG && current_gesture<=GESTURE_DRAG_2)
+       if(current_gesture>=GESTURE_DRAG && current_gesture<=GESTURE_DRAG_3)
                set_gesture_delta(gesture_points(current_gesture));
        else if(current_gesture==GESTURE_PINCH || current_gesture==GESTURE_ROTATE)
        {