]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/gesturedetector.cpp
Put feature control macros before any headers
[libs/gui.git] / source / input / gesturedetector.cpp
index 26968c03c988a16d1b0035c652a0bc6b991c64a6..08232cf8f0fecf023e98fe43b452d2bf9135ee0e 100644 (file)
@@ -1,7 +1,7 @@
 #define _USE_MATH_DEFINES
+#include "gesturedetector.h"
 #include <cmath>
 #include <sigc++/bind_return.h>
-#include "gesturedetector.h"
 #include "touchscreen.h"
 
 using namespace std;
@@ -10,10 +10,8 @@ namespace Msp {
 namespace Input {
 
 GestureDetector::GestureDetector(Touchscreen &ts):
-       touchscreen(ts),
-       current_gesture(GESTURE_NONE),
-       pending_tap(GESTURE_NONE),
-       invalid_gesture(false)
+       Device(UNSPECIFIED),
+       touchscreen(ts)
 {
        name = "Gesture";
 
@@ -31,10 +29,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 +78,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 +148,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 +236,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)
        {