aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2016-01-23 11:16:59 +0100
committerRay <raysan5@gmail.com>2016-01-23 11:16:59 +0100
commited674d865ba2fc845a91aea6c77dffae7576e0c0 (patch)
treeacb701111e7e3b31e57c487a3d2e1e011106e979 /src
parent4e57bd1f18996990546920f2242a58894c6cec81 (diff)
parent233f7611da96ea6bc0b7c62f6a06dacef707f9d7 (diff)
downloadraylib-ed674d865ba2fc845a91aea6c77dffae7576e0c0.tar.gz
raylib-ed674d865ba2fc845a91aea6c77dffae7576e0c0.zip
Merge pull request #79 from victorfisac/develop
Fixed hold gesture detection
Diffstat (limited to 'src')
-rw-r--r--src/gestures.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gestures.c b/src/gestures.c
index 88cdb528..ea744555 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -217,8 +217,13 @@ void ProcessGestureEvent(GestureEvent event)
angle = CalculateAngle(initialDragPosition, endDragPosition, magnitude);
intensity = magnitude / (float)draggingTimeCounter;
- currentGesture = GESTURE_DRAG;
- draggingTimeCounter++;
+ // Check if drag movement is less than minimum to keep it as hold state or switch to drag state
+ if(magnitude > FORCE_TO_SWIPE)
+ {
+ currentGesture = GESTURE_DRAG;
+ draggingTimeCounter++;
+ }
+ else currentGesture = GESTURE_HOLD;
}
}
} break;
@@ -339,8 +344,13 @@ void UpdateGestures(void)
{
// NOTE: Gestures are processed through system callbacks on touch events
- if ((previousGesture == GESTURE_TAP) && (currentGesture == GESTURE_TAP)) currentGesture = GESTURE_HOLD;
- else if (currentGesture != GESTURE_HOLD) currentGesture = GESTURE_NONE;
+ // When screen is touched, in first frame GESTURE_TAP is called but in next frame touch event callback is not called (if touch position doesn't change),
+ // so we need to store previous frame gesture type manually in this update function to switch to HOLD if current gesture is
+ // GESTURE_TAP two frames in a row. Due to current gesture is set to HOLD, current gesture doesn't need to be reset to NONE every frame.
+ // It will be reset when UP is called.
+ if(currentGesture == GESTURE_TAP) previousGesture = currentGesture;
+
+ if(previousGesture == GESTURE_TAP && currentGesture == GESTURE_TAP) currentGesture = GESTURE_HOLD;
}
//----------------------------------------------------------------------------------