]> git.tdb.fi Git - libs/gui.git/commitdiff
Implement three-finger tap and drag gestures
authorMikko Rasa <tdb@tdb.fi>
Mon, 19 Sep 2016 20:31:45 +0000 (23:31 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 19 Sep 2016 20:31:45 +0000 (23:31 +0300)
source/input/gesturedetector.cpp
source/input/gesturedetector.h

index 26968c03c988a16d1b0035c652a0bc6b991c64a6..62ac3f050d09c9c849b7e0c6c62ecf8e3185a3bf 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;
        }
 }
 
@@ -153,7 +159,21 @@ void GestureDetector::start_gesture()
                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 +237,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)
        {
index f39fdce98e609f5b345d02efdcb9c9a5fe8be9c7..51af312720c17da85a4f49692a6116c9022ab5bf 100644 (file)
@@ -13,8 +13,10 @@ enum Gesture
        GESTURE_NONE,
        GESTURE_TAP,
        GESTURE_TAP_2,
+       GESTURE_TAP_3,
        GESTURE_DRAG,
        GESTURE_DRAG_2,
+       GESTURE_DRAG_3,
        GESTURE_PINCH,
        GESTURE_ROTATE
 };