X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fgesturedetector.cpp;h=97e3d56f0fc53a3e4a7eb0e271a2a0c060303603;hb=81a662b025809d71d8dc67a2108ad7d54ba7c645;hp=49ddba2b8478173dfbd65b9e80233ab356c0da03;hpb=1d418a1547bcea8b983815403d0a07b62793a460;p=libs%2Fgui.git diff --git a/source/input/gesturedetector.cpp b/source/input/gesturedetector.cpp index 49ddba2..97e3d56 100644 --- a/source/input/gesturedetector.cpp +++ b/source/input/gesturedetector.cpp @@ -12,7 +12,6 @@ namespace Input { GestureDetector::GestureDetector(Touchscreen &ts): touchscreen(ts), current_gesture(GESTURE_NONE), - active_points(0), pending_tap(GESTURE_NONE), invalid_gesture(false) { @@ -28,10 +27,18 @@ GestureDetector::GestureDetector(Touchscreen &ts): string GestureDetector::get_button_name(unsigned btn) const { - if(btn==GESTURE_DRAG) + if(btn==GESTURE_TAP) + 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) @@ -47,7 +54,9 @@ string GestureDetector::get_axis_name(unsigned axis) const else if(axis==1) return "Y"; else if(axis==2) - return "Progress"; + return "Delta X"; + else if(axis==3) + return "Delta Y"; else return Device::get_axis_name(axis); } @@ -71,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; } } @@ -84,7 +95,7 @@ void GestureDetector::touch_up(unsigned btn) p.y += p.down_y; p.down = false; - if(active_points&(1<((pending_tap-GESTURE_TAP)+1, MAX_POINTS); - set_gesture_location((1<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; @@ -169,20 +194,13 @@ void GestureDetector::start_gesture() else if((p.x*p2.x+p.y*p2.y)>2*abs(p.x*p2.y-p.y*p2.x)) // If both points moved in the same direction, it's a two-finger drag. current_gesture = GESTURE_DRAG_2; - - if(current_gesture!=GESTURE_NONE) - active_points = 3; } else - { current_gesture = GESTURE_DRAG; - active_points = 1; - } - if(current_gesture!=GESTURE_NONE) { - set_gesture_location(active_points); + set_gesture_location(gesture_points(current_gesture)); update_progress(); set_button_state(current_gesture, true, true); } @@ -190,40 +208,41 @@ void GestureDetector::start_gesture() invalid_gesture = true; } -void GestureDetector::set_gesture_location(unsigned mask) +void GestureDetector::set_gesture_location(unsigned n_points) { float x = 0; float y = 0; - unsigned count = 0; - for(unsigned i=0; i=GESTURE_DRAG && current_gesture<=GESTURE_DRAG_3) + set_gesture_delta(gesture_points(current_gesture)); else if(current_gesture==GESTURE_PINCH || current_gesture==GESTURE_ROTATE) { + TouchPoint &p = points[0]; TouchPoint &p2 = points[1]; /* Pinch progress is the ratio between the current distance of the points and their distance when they were pressed. */ @@ -249,7 +268,6 @@ void GestureDetector::end_gesture() set_button_state(current_gesture, false, true); set_axis_value(2, 0, false); current_gesture = GESTURE_NONE; - active_points = 0; pending_tap = GESTURE_NONE; } @@ -269,5 +287,23 @@ GestureDetector::TouchPoint::TouchPoint(): threshold_exceeded(false) { } + +unsigned gesture_points(Gesture gesture) +{ + switch(gesture) + { + case GESTURE_NONE: return 0; + case GESTURE_TAP: return 1; + case GESTURE_TAP_2: return 2; + case GESTURE_TAP_3: return 3; + case GESTURE_DRAG: return 1; + case GESTURE_DRAG_2: return 2; + case GESTURE_DRAG_3: return 3; + case GESTURE_PINCH: return 2; + case GESTURE_ROTATE: return 2; + default: throw invalid_argument("gesture_points"); + } +} + } // namespace Input } // namespace Msp