From: Mikko Rasa Date: Mon, 19 Sep 2016 20:31:45 +0000 (+0300) Subject: Implement three-finger tap and drag gestures X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=301e09d687a1217130fbb2240b7a80f1a00aacdc;p=libs%2Fgui.git Implement three-finger tap and drag gestures --- diff --git a/source/input/gesturedetector.cpp b/source/input/gesturedetector.cpp index 26968c0..62ac3f0 100644 --- a/source/input/gesturedetector.cpp +++ b/source/input/gesturedetector.cpp @@ -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) { diff --git a/source/input/gesturedetector.h b/source/input/gesturedetector.h index f39fdce..51af312 100644 --- a/source/input/gesturedetector.h +++ b/source/input/gesturedetector.h @@ -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 };