4 using System.Collections.Generic;
6 using SiliconStudio.Core.Mathematics;
8 namespace SiliconStudio.
Paradox.Input
10 internal sealed
class GestureRecognizerTap : GestureRecognizer
12 private GestureConfigTap ConfigTap {
get {
return (GestureConfigTap)Config; } }
14 private int currentNumberOfTaps;
16 private TimeSpan elapsedSinceTakeOff;
18 private TimeSpan elapsedSinceDown;
20 private bool isTapDown;
22 private int maxNbOfFingerTouched;
24 public GestureRecognizerTap(GestureConfigTap configuration,
float screenRatio)
25 :base(configuration, screenRatio)
29 protected override void ProcessPointerEventsImpl(TimeSpan deltaTime, List<PointerEvent> events)
32 elapsedSinceDown += deltaTime;
34 elapsedSinceTakeOff += deltaTime;
36 AnalysePointerEvents(events);
39 if (HasGestureStarted && (elapsedSinceDown > ConfigTap.MaximumPressTime || elapsedSinceTakeOff > ConfigTap.MaximumTimeBetweenTaps))
46 protected override void ProcessDownEventPointer(
int id,
Vector2 pos)
48 if (!FingerIdToBeginPositions.ContainsKey(
id))
49 FingerIdToBeginPositions[
id] = pos;
51 FingerIdsToLastPos[id] = pos;
53 maxNbOfFingerTouched = Math.Max(maxNbOfFingerTouched, NbOfFingerOnScreen);
57 if (NbOfFingerOnScreen == 1)
59 elapsedSinceTakeOff = TimeSpan.Zero;
60 elapsedSinceDown = TimeSpan.Zero;
61 HasGestureStarted =
true;
64 if(HasGestureStarted && maxNbOfFingerTouched > ConfigTap.RequiredNumberOfFingers)
67 if (HasGestureStarted && !HadFingerAtThatPosition(pos))
71 maxNbOfFingerTouched = NbOfFingerOnScreen;
72 elapsedSinceTakeOff = TimeSpan.Zero;
73 elapsedSinceDown = TimeSpan.Zero;
74 HasGestureStarted =
true;
75 foreach (var key
in FingerIdsToLastPos.Keys)
76 FingerIdToBeginPositions[key] = FingerIdsToLastPos[key];
80 private bool HadFingerAtThatPosition(
Vector2 pos)
83 foreach (var beginPos
in FingerIdToBeginPositions.Values)
85 if ((pos - beginPos).Length() < ConfigTap.MaximumDistanceTaps)
92 protected override void ProcessMoveEventPointers(Dictionary<int, Vector2> fingerIdsToMovePos)
94 if (!HasGestureStarted)
97 foreach (var
id in fingerIdsToMovePos.Keys)
99 if ((fingerIdsToMovePos[
id] - FingerIdsToLastPos[
id]).Length() > ConfigTap.MaximumDistanceTaps)
107 protected override void ProcessUpEventPointer(
int id,
Vector2 pos)
109 if (!FingerIdsToLastPos.ContainsKey(
id))
112 FingerIdsToLastPos.Remove(id);
114 if (NbOfFingerOnScreen == 0)
116 elapsedSinceTakeOff = TimeSpan.Zero;
119 if (HasGestureStarted && maxNbOfFingerTouched == ConfigTap.RequiredNumberOfFingers)
120 ++currentNumberOfTaps;
122 maxNbOfFingerTouched = 0;
126 private void EndCurrentTap()
129 if (currentNumberOfTaps == ConfigTap.RequiredNumberOfTaps)
131 var tapMeanPosition = ComputeMeanPosition(FingerIdToBeginPositions.Values);
132 CurrentGestureEvents.Add(
new GestureEventTap(ElapsedSinceBeginning, ConfigTap.RequiredNumberOfFingers, currentNumberOfTaps, NormalizeVector(tapMeanPosition)));
135 currentNumberOfTaps = 0;
137 HasGestureStarted =
false;
138 FingerIdToBeginPositions.Clear();
Represents a two dimensional mathematical vector.