public override void update_touch( bool pressed, bool triggered, bool released, Vector2 pressLoc, Vector2 releasedLoc) { InputStates state = InputStates.None; if (pressed) { state |= Services.Input.InputStates.Pressed; if (triggered) { state |= Services.Input.InputStates.Triggered; } } else if (released) { state |= Services.Input.InputStates.Released; } if (TouchState.HasEnumFlag(InputStates.InputConsumed)) { // @Debug: Because this waits until the input is none, an input // consumed on a trigger will stay consumed if released on the next // frame, and on the frame after that if pressed again // Basically pressing and releasing a button every 2 ticks // is impossible if (state != InputStates.None) { state |= InputStates.InputConsumed; } } TouchState = state; if (triggered) { TouchTriggerPosition = pressLoc; TouchPressOutsideTolerance = false; } TouchPressPosition = pressLoc; if ((TouchTriggerPosition - TouchPressPosition).LengthSquared() > TOUCH_PRESS_TOLERANCE * TOUCH_PRESS_TOLERANCE) { TouchPressOutsideTolerance = true; } TouchReleasePosition = releasedLoc; // If any double taps received, clear deferred taps if (Gestures.ContainsKey(TouchGestures.DoubleTap)) { DeferredTaps.Clear(); } // Else add new taps else if (Gestures.ContainsKey(TouchGestures.Tap)) { // Clear old deferred taps DeferredTaps.Clear(); // If the tap was consumed, don't defer it if (!GestureStates[TouchGestures.Tap].HasEnumFlag( InputStates.InputConsumed)) { DeferredTaps.Add(Gestures[TouchGestures.Tap]); } } // Clear gesture list each frame Gestures.Clear(); foreach (var key in GestureStates.Keys.ToList()) { GestureStates[key] = InputStates.None; } // If any taps have existed for long enough they can't be double taps var time = DateTime.Now; for (int i = DeferredTaps.Count - 1; i >= 0; i--) { var sample = DeferredTaps[i]; if (TouchPanelState.DoubleTapThresholdElapsed(sample)) { Gestures[TouchGestures.TapNoDouble] = sample; DeferredTaps.RemoveAt(i); #if DEBUG Console.WriteLine(string.Format( "{0}: Position [{1}, {2}] - [{3}, {4}]", TouchGestures.TapNoDouble, sample.Position.X, sample.Position.Y, sample.Position2.X, sample.Position2.Y)); #endif } } }