private static void ProcessPinch(TouchLocation[] touches) { TouchLocation aPreviousLocation1; if (!touches[0].TryGetPreviousLocation(out aPreviousLocation1)) { aPreviousLocation1 = touches[0]; } TouchLocation aPreviousLocation2; if (!touches[1].TryGetPreviousLocation(out aPreviousLocation2)) { aPreviousLocation2 = touches[1]; } Vector2 delta = touches[0].Position - aPreviousLocation1.Position; Vector2 delta2 = touches[1].Position - aPreviousLocation2.Position; TimeSpan timestamp = touches[0].Timestamp > touches[1].Timestamp ? touches[0].Timestamp : touches[1].Timestamp; if (TouchPanel._dragGestureStarted != GestureType.None) { if (TouchPanel.GestureIsEnabled(GestureType.DragComplete)) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.DragComplete, timestamp, Vector2.Zero, Vector2.Zero, Vector2.Zero, Vector2.Zero)); } TouchPanel._dragGestureStarted = GestureType.None; } TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Pinch, timestamp, touches[0].Position, touches[1].Position, delta, delta2)); TouchPanel._pinchGestureStarted = true; TouchPanel._tapDisabled = true; TouchPanel._holdDisabled = true; }
private static void ProcessHold(TouchLocation touch) { if (!TouchPanel.GestureIsEnabled(GestureType.Hold) || TouchPanel._holdDisabled || TimeSpan.FromTicks(DateTime.Now.Ticks) - touch.PressTimestamp < TouchPanel._maxTicksToProcessHold) { return; } TouchPanel._holdDisabled = true; TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Hold, touch.Timestamp, touch.Position, Vector2.Zero, Vector2.Zero, Vector2.Zero)); }
private static bool ProcessDoubleTap(TouchLocation touch) { if (!TouchPanel.GestureIsEnabled(GestureType.DoubleTap) || TouchPanel._tapDisabled || (double)Vector2.Distance(touch.Position, TouchPanel._lastTap.Position) > 35.0 || (touch.Timestamp - TouchPanel._lastTap.Timestamp).TotalMilliseconds > 300.0) { return(false); } TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.DoubleTap, touch.Timestamp, touch.Position, Vector2.Zero, Vector2.Zero, Vector2.Zero)); TouchPanel._tapDisabled = true; return(true); }
private static void ProcessTap(TouchLocation touch) { if (!TouchPanel.GestureIsEnabled(GestureType.Tap) || TouchPanel._tapDisabled || (double)Vector2.Distance(touch.PressPosition, touch.Position) > 35.0 || TimeSpan.FromTicks(DateTime.Now.Ticks) - touch.PressTimestamp > TouchPanel._maxTicksToProcessHold) { return; } TouchPanel._lastTap = touch; GestureSample gestureSample = new GestureSample(GestureType.Tap, touch.Timestamp, touch.Position, Vector2.Zero, Vector2.Zero, Vector2.Zero); TouchPanel.GestureList.Enqueue(gestureSample); }
private static void ProcessDrag(TouchLocation touch) { bool flag1 = TouchPanel.GestureIsEnabled(GestureType.HorizontalDrag); bool flag2 = TouchPanel.GestureIsEnabled(GestureType.VerticalDrag); bool flag3 = TouchPanel.GestureIsEnabled(GestureType.FreeDrag); TouchLocation aPreviousLocation; if (!flag1 && !flag2 && !flag3 || (touch.State != TouchLocationState.Moved || !touch.TryGetPreviousLocation(out aPreviousLocation))) { return; } Vector2 delta = touch.Position - aPreviousLocation.Position; if (TouchPanel._dragGestureStarted != GestureType.FreeDrag) { bool flag4 = (double)Math.Abs(delta.X) > (double)Math.Abs(delta.Y * 2f); bool flag5 = (double)Math.Abs(delta.Y) > (double)Math.Abs(delta.X * 2f); bool flag6 = TouchPanel._dragGestureStarted == GestureType.None; if (flag1 && (flag6 && flag4 || TouchPanel._dragGestureStarted == GestureType.HorizontalDrag)) { delta.Y = 0.0f; TouchPanel._dragGestureStarted = GestureType.HorizontalDrag; } else if (flag2 && (flag6 && flag5 || TouchPanel._dragGestureStarted == GestureType.VerticalDrag)) { delta.X = 0.0f; TouchPanel._dragGestureStarted = GestureType.VerticalDrag; } else { TouchPanel._dragGestureStarted = !flag3 || !flag6 ? GestureType.DragComplete : GestureType.FreeDrag; } } if (TouchPanel._dragGestureStarted == GestureType.None || TouchPanel._dragGestureStarted == GestureType.DragComplete) { return; } TouchPanel._tapDisabled = true; TouchPanel._holdDisabled = true; TouchPanel.GestureList.Enqueue(new GestureSample(TouchPanel._dragGestureStarted, touch.Timestamp, touch.Position, Vector2.Zero, delta, Vector2.Zero)); }
private static void UpdateGestures(bool stateChanged) { int num1 = 0; foreach (TouchLocation touchLocation in TouchPanel._gestureState) { num1 += touchLocation.State != TouchLocationState.Released ? 1 : 0; } if (num1 > 1) { TouchPanel._tapDisabled = true; TouchPanel._holdDisabled = true; } foreach (TouchLocation touch in TouchPanel._gestureState) { switch (touch.State) { case TouchLocationState.Moved: case TouchLocationState.Pressed: if (touch.State != TouchLocationState.Pressed || !TouchPanel.ProcessDoubleTap(touch)) { if (TouchPanel.GestureIsEnabled(GestureType.Pinch) && num1 > 1) { if (TouchPanel._pinchTouch[0].State == TouchLocationState.Invalid || TouchPanel._pinchTouch[0].Id == touch.Id) { TouchPanel._pinchTouch[0] = touch; break; } else if (TouchPanel._pinchTouch[1].State == TouchLocationState.Invalid || TouchPanel._pinchTouch[1].Id == touch.Id) { TouchPanel._pinchTouch[1] = touch; break; } else { break; } } else { float num2 = Vector2.Distance(touch.Position, touch.PressPosition); if (TouchPanel._dragGestureStarted == GestureType.None && (double)num2 < 35.0) { TouchPanel.ProcessHold(touch); break; } else if (stateChanged) { TouchPanel.ProcessDrag(touch); break; } else { break; } } } else { break; } case TouchLocationState.Released: if (stateChanged) { if (TouchPanel._pinchGestureStarted && (touch.Id == TouchPanel._pinchTouch[0].Id || touch.Id == TouchPanel._pinchTouch[1].Id)) { if (TouchPanel.GestureIsEnabled(GestureType.PinchComplete)) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.PinchComplete, touch.Timestamp, Vector2.Zero, Vector2.Zero, Vector2.Zero, Vector2.Zero)); } TouchPanel._pinchGestureStarted = false; TouchPanel._pinchTouch[0] = TouchLocation.Invalid; TouchPanel._pinchTouch[1] = TouchLocation.Invalid; break; } else if (num1 == 0) { if ((double)Vector2.Distance(touch.Position, touch.PressPosition) > 35.0 && (double)touch.Velocity.Length() > 100.0 && TouchPanel.GestureIsEnabled(GestureType.Flick)) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Flick, touch.Timestamp, Vector2.Zero, Vector2.Zero, touch.Velocity, Vector2.Zero)); TouchPanel._dragGestureStarted = GestureType.None; break; } else if (TouchPanel._dragGestureStarted != GestureType.None) { if (TouchPanel.GestureIsEnabled(GestureType.DragComplete)) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.DragComplete, touch.Timestamp, Vector2.Zero, Vector2.Zero, Vector2.Zero, Vector2.Zero)); } TouchPanel._dragGestureStarted = GestureType.None; break; } else { TouchPanel.ProcessTap(touch); break; } } else { break; } } else { break; } } } if (!stateChanged) { return; } if (TouchPanel.GestureIsEnabled(GestureType.Pinch) && TouchPanel._pinchTouch[0].State != TouchLocationState.Invalid && TouchPanel._pinchTouch[1].State != TouchLocationState.Invalid) { TouchPanel.ProcessPinch(TouchPanel._pinchTouch); } else { TouchPanel._pinchGestureStarted = false; TouchPanel._pinchTouch[0] = TouchLocation.Invalid; TouchPanel._pinchTouch[1] = TouchLocation.Invalid; } if (num1 != 0) { return; } TouchPanel._tapDisabled = false; TouchPanel._holdDisabled = false; TouchPanel._dragGestureStarted = GestureType.None; }