From: Mikko Rasa Date: Mon, 23 Nov 2015 17:57:11 +0000 (+0200) Subject: Implement tap gestures X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1b33313502f837e2b0d02d3f2d129c85a8c66064;p=libs%2Fgui.git Implement tap gestures --- diff --git a/source/input/gesturedetector.cpp b/source/input/gesturedetector.cpp index aecfa81..98e3ff3 100644 --- a/source/input/gesturedetector.cpp +++ b/source/input/gesturedetector.cpp @@ -12,6 +12,7 @@ GestureDetector::GestureDetector(Touchscreen &ts): touchscreen(ts), current_gesture(GESTURE_NONE), active_points(0), + pending_tap(GESTURE_NONE), invalid_gesture(false) { name = "Gesture"; @@ -62,6 +63,14 @@ void GestureDetector::touch_down(unsigned btn) p.x = 0; p.y = 0; p.threshold_exceeded = false; + + if(current_gesture==GESTURE_NONE && !invalid_gesture) + { + if(btn==0) + pending_tap = GESTURE_TAP; + else if(btn==1) + pending_tap = GESTURE_TAP_2; + } } void GestureDetector::touch_up(unsigned btn) @@ -83,6 +92,16 @@ void GestureDetector::touch_up(unsigned btn) invalid_gesture = false; for(unsigned i=0; (i((pending_tap-GESTURE_TAP)+1, MAX_POINTS); + set_gesture_location((1<=1) + { p.threshold_exceeded = true; + pending_tap = GESTURE_NONE; + } if(current_gesture==GESTURE_NONE && !invalid_gesture) start_gesture(); @@ -148,28 +170,42 @@ void GestureDetector::start_gesture() current_gesture = GESTURE_DRAG_2; if(current_gesture!=GESTURE_NONE) - { active_points = 3; - set_axis_value(0, (p.down_x+p2.down_x)/2, true); - set_axis_value(1, (p.down_y+p2.down_y)/2, true); - } } else { 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(); if(current_gesture!=GESTURE_NONE) + { + set_gesture_location(active_points); + update_progress(); set_button_state(current_gesture, true, true); + } else invalid_gesture = true; } +void GestureDetector::set_gesture_location(unsigned mask) +{ + float x = 0; + float y = 0; + unsigned count = 0; + for(unsigned i=0; i