X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fgesturedetector.cpp;h=cc027973fdc868a319bdce0fe5db5b312ed742a5;hb=a5be5c703808817dda8feafb03b0aec04b20afbb;hp=112121ee456a86736876b01e23c09a394045c498;hpb=5858aa055277dbd376c33bb3bbeb6aa74137a17f;p=libs%2Fgui.git diff --git a/source/input/gesturedetector.cpp b/source/input/gesturedetector.cpp index 112121e..cc02797 100644 --- a/source/input/gesturedetector.cpp +++ b/source/input/gesturedetector.cpp @@ -26,14 +26,8 @@ GestureDetector::GestureDetector(Touchscreen &ts): string GestureDetector::get_button_name(unsigned btn) const { - if(btn==GESTURE_SWIPE_DOWN) - return "Swipe down"; - else if(btn==GESTURE_SWIPE_UP) - return "Swipe up"; - else if(btn==GESTURE_SWIPE_LEFT) - return "Swipe left"; - else if(btn==GESTURE_SWIPE_RIGHT) - return "Swipe right"; + if(btn==GESTURE_DRAG) + return "Drag"; else if(btn==GESTURE_PINCH) return "Pinch"; else @@ -133,9 +127,13 @@ void GestureDetector::start_gesture() TouchPoint &p2 = points[1]; float ddx = p.down_x-p2.down_x; float ddy = p.down_y-p2.down_y; - if(p.x*p2.x+p.y*p2.y<0 && (p.x*ddx+p.y*ddy)*(p2.x*ddx+p2.y*ddy)<0) - /* If the points moved in different directions and also both away from - or towards the other, it's a pinch gesture. */ + float away = p.x*ddx+p.y*ddy; + float turn = p.y*ddx-p.x*ddy; + float away2 = -(p2.x*ddx+p2.y*ddy); + float turn2 = -(p2.y*ddx-p2.x*ddy); + if(away*away2>0 && abs(away)>abs(turn) && abs(away2)>abs(turn2)) + /* If the points moved away from or towards each other without rotating + significantly, it's a pinch gesture. */ current_gesture = GESTURE_PINCH; else invalid_gesture = true; @@ -149,20 +147,10 @@ void GestureDetector::start_gesture() } else { - // Allow a maximum deviation of about 26° to recognize a swipe gesture. - if(abs(p.x)>2*abs(p.y)) - current_gesture = (p.x>0 ? GESTURE_SWIPE_RIGHT : GESTURE_SWIPE_LEFT); - else if(abs(p.y)>2*abs(p.x)) - current_gesture = (p.y>0 ? GESTURE_SWIPE_UP : GESTURE_SWIPE_DOWN); - else - invalid_gesture = true; - - if(current_gesture!=GESTURE_NONE) - { - active_points = 1; - set_axis_value(0, p.down_x, true); - set_axis_value(1, p.down_y, true); - } + 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(); @@ -175,14 +163,11 @@ void GestureDetector::update_progress() { TouchPoint &p = points[0]; - if(current_gesture==GESTURE_SWIPE_DOWN) - set_axis_value(2, -p.y, true); - else if(current_gesture==GESTURE_SWIPE_UP) - set_axis_value(2, p.y, true); - else if(current_gesture==GESTURE_SWIPE_LEFT) - set_axis_value(2, -p.x, true); - else if(current_gesture==GESTURE_SWIPE_RIGHT) + if(current_gesture==GESTURE_DRAG) + { set_axis_value(2, p.x, true); + set_axis_value(3, p.y, true); + } else if(current_gesture==GESTURE_PINCH) { TouchPoint &p2 = points[1]; @@ -193,6 +178,7 @@ void GestureDetector::update_progress() float dx = ddx+p.x-p2.x; float dy = ddy+p.y-p2.y; set_axis_value(2, sqrt(dx*dx+dy*dy)/sqrt(ddx*ddx+ddy*ddy)-1, true); + set_axis_value(3, 0, true); } }