Example #1
0
        private void ApplyTouch(List <TouchLocation> state, TouchLocation touch)
        {
            if (touch.State == TouchLocationState.Pressed)
            {
                state.Add(touch);
                return;
            }

            // Find the matching touch
            for (int i = 0; i < state.Count; i += 1)
            {
                TouchLocation existingTouch = state[i];
                if (existingTouch.Id == touch.Id)
                {
                    /* If we are moving straight from Pressed to Released,
                     * that means we've never been seen, so just get rid of us.
                     */
                    if (existingTouch.State == TouchLocationState.Pressed &&
                        touch.State == TouchLocationState.Released)
                    {
                        state.RemoveAt(i);
                    }
                    else
                    {
                        // Otherwise, update the touch based on the new one
                        existingTouch.UpdateState(touch);
                        state[i] = existingTouch;
                    }
                    break;
                }
            }
        }
Example #2
0
 protected override void OnTouch(TouchLocation touch)
 {
     base.OnTouch(touch);
     this.Direction = -1 * (touch.Position - new Vector2(Game1.ScreenWidth / 2, Game1.ScrrenHeight / 2));
     this.DistanceToMove = this.Direction.Length();
     this.Direction.Normalize();
 }
Example #3
0
        internal static Motion Create( TouchLocation location, bool is8D )
        {
            Motion motion = new Motion ( );

            switch ( location.State )
            {
                case TouchLocationState.Invalid:
                    motion.Type = MotionType.None;
                    break;

                case TouchLocationState.Pressed:
                    motion.Type = MotionType.Down;
                    break;

                case TouchLocationState.Moved:
                    motion.Type = MotionType.Press;
                    break;

                case TouchLocationState.Released:
                    motion.Type = MotionType.Up;
                    break;
            }

            motion.Position = location.Position / World.Scale;

            TouchLocation prevLocation;

            if ( location.TryGetPreviousLocation ( out prevLocation ) && prevLocation.State != TouchLocationState.Invalid )
                motion.Offset = ( location.Position - prevLocation.Position ) / World.Scale;

            return motion;
        }
Example #4
0
        public TouchCollection GetState()
        {
            /* Clear out touches from previous frames that were
             * released on the same frame they were touched that
             * haven't been seen.
             */
            for (int i = touchState.Count - 1; i >= 0; i -= 1)
            {
                TouchLocation touch = touchState[i];

                /* If a touch was pressed and released in a
                 * previous frame and the user didn't ask about
                 * it then trash it.
                 */
                if (touch.SameFrameReleased &&
                    touch.Timestamp < CurrentTimestamp &&
                    touch.State == TouchLocationState.Pressed)
                {
                    touchState.RemoveAt(i);
                }
            }

            TouchCollection result = (touchState.Count > 0) ?
                                     new TouchCollection(touchState.ToArray()) :
                                     TouchCollection.Empty;

            AgeTouches(touchState);
            return(result);
        }
Example #5
0
 public static TouchLocation Unproject(TouchLocation touchLocation)
 {
     return new TouchLocation(
                   touchLocation.Id,
                   touchLocation.State,
                   Unproject(touchLocation.Position));
 }
Example #6
0
 public void Update(TouchLocation touchLocation)
 {
     if (touchLocation.State == TouchLocationState.Pressed && _picked < 0)
     {
         Vector2 delta = touchLocation.Position - _position;
         if (delta.LengthSquared() <= 2025f)
         {
             _picked = touchLocation.Id;
         }
     }
     if ((touchLocation.State == TouchLocationState.Pressed ||
         touchLocation.State == TouchLocationState.Moved) && touchLocation.Id == _picked)
     {
         Vector2 delta = touchLocation.Position - _center;
         if (delta != Vector2.Zero)
         {
             float _length = delta.Length();
             if (_length > 25f)
             {
                 delta *= (25f / _length);
             }
             StickPosition = delta / 25f;
             StickPosition.Y *= -1f;
             _position = _center + delta;
         }
     }
     if (touchLocation.State == TouchLocationState.Released && touchLocation.Id == _picked)
     {
         _picked = -1;
         _position = _center;
         StickPosition = Vector2.Zero;
     }
 }
Example #7
0
        private void ProcessHold(TouchLocation touch)
        {
            if (!GestureIsEnabled(GestureType.Hold) || holdDisabled)
            {
                return;
            }

            TimeSpan elapsed = CurrentTimestamp - touch.PressTimestamp;

            if (elapsed < TimeRequiredForHold)
            {
                return;
            }

            holdDisabled = true;

            GestureList.Enqueue(
                new GestureSample(
                    GestureType.Hold,
                    touch.Timestamp,
                    touch.Position,
                    Vector2.Zero,
                    Vector2.Zero,
                    Vector2.Zero
                    )
                );
        }
Example #8
0
        /// <summary>
        /// Apply the given new touch to the state. If it is a Pressed it will be added as a new touch, otherwise we update the existing touch it matches
        /// </summary>
        private void ApplyTouch(List <TouchLocation> state, TouchLocation touch)
        {
            if (touch.State == TouchLocationState.Pressed)
            {
                state.Add(touch);
                return;
            }

            //Find the matching touch
            for (var i = 0; i < state.Count; i++)
            {
                var existingTouch = state[i];

                if (existingTouch.Id == touch.Id)
                {
                    //If we are moving straight from Pressed to Released and we've existed for multiple frames, that means we've never been seen, so just get rid of us
                    if (existingTouch.State == TouchLocationState.Pressed && touch.State == TouchLocationState.Released && existingTouch.PressTimestamp != touch.Timestamp)
                    {
                        state.RemoveAt(i);
                    }
                    else
                    {
                        //Otherwise update the touch based on the new one
                        existingTouch.UpdateState(touch);
                        state[i] = existingTouch;
                    }

                    break;
                }
            }
        }
 public Touch(TouchLocation location)
 {
     this.systemTouch = location;
     this.TouchID = location.Id;
     this.positions.Begin = this.systemTouch.Position;
     this.positions.Current = this.systemTouch.Position;
 }
        public override void Update(GameTime gameTime)
        {
            _touchData.Clear();
            TouchCollection currentTouches = TouchPanel.GetState();
            foreach (TouchLocation touchLocation in currentTouches)
            {
                if ((touchLocation.State != TouchLocationState.Invalid) && (touchLocation.State != TouchLocationState.Released))
                {
                    TouchLocation previousLocationContainer = new TouchLocation();
                    if (touchLocation.TryGetPreviousLocation(out previousLocationContainer))
                    {
                        _touchData.Add(new Touch(
                            TranslatePositionFromScreenToBuffer(touchLocation.Position),
                            TranslatePositionFromScreenToBuffer(previousLocationContainer.Position)));
                    }
                    else
                    {
                        _touchData.Add(new Touch(
                            TranslatePositionFromScreenToBuffer(touchLocation.Position),
                            TranslatePositionFromScreenToBuffer(touchLocation.Position)));
                    }
                }
            }

            base.Update(gameTime);
        }
        private void ProcessTap(TouchLocation touch)
        {
            if (_tapDisabled)
                return;

            // If the release is too far away from the press 
            // position then this cannot be a tap event.
            var dist = Vector2.Distance(touch.PressPosition, touch.Position);
            if (dist > TapJitterTolerance)
                return;

            // If we pressed and held too long then don't 
            // generate a tap event for it.
            var elapsed = CurrentTimestamp - touch.PressTimestamp;
            if (elapsed > TimeRequiredForHold)
                return;

            // Store the last tap for 
            // double tap processing.
            _lastTap = touch;

            // Fire off the tap event immediately.
            if (GestureIsEnabled(GestureType.Tap))
            {
                var tap = new GestureSample(
                    GestureType.Tap, touch.Timestamp,
                    touch.Position, Vector2.Zero,
                    Vector2.Zero, Vector2.Zero);
                GestureList.Enqueue(tap);
            }
        }
Example #12
0
 public void Update(TouchCollection NewCollection)
 {
     this.touchCollection = NewCollection;
     Touch = touchCollection[0];
     prevTouchState = curTouchState;
     curTouchState = Touch.State;
 }
Example #13
0
        internal static void AddEvent(int id, TouchLocationState state, Vector2 position)
        {
            if (state == TouchLocationState.Pressed)
            {
                TouchPanel._touchIds[id] = TouchPanel._nextTouchId++;
            }
            int id1;

            if (!TouchPanel._touchIds.TryGetValue(id, out id1))
            {
                return;
            }
            TouchLocation touchLocation = new TouchLocation(id1, state, position * TouchPanel._touchScale);

            TouchPanel._touchEvents.Add(touchLocation);
            if (TouchPanel._touchEvents.Count > 100)
            {
                TouchPanel._touchEvents.RemoveRange(0, TouchPanel._touchEvents.Count - 100);
            }
            if (TouchPanel.EnabledGestures != GestureType.None)
            {
                TouchPanel._gestureEvents.Add(touchLocation);
                if (TouchPanel._gestureEvents.Count > 100)
                {
                    TouchPanel._gestureEvents.RemoveRange(0, TouchPanel._gestureEvents.Count - 100);
                }
            }
            if (state != TouchLocationState.Released)
            {
                return;
            }
            TouchPanel._touchIds.Remove(id);
        }
Example #14
0
        public void Evaluate(GameTime gameTime, Control focused, UserInterface ui)
        {
            var type = typeof(TouchDevice);

            for (int i = 0; i < _touches.Count; i++)
            {
                var t = _touches[i];
                Current = t;

                ui.FindControls(t.Position.FromXNA(), _buffer);
                _current.AddRange(_buffer);

                for (int j = 0; j < _buffer.Count; j++)
                {
                    _buffer[j].Gestures.Evaluate(gameTime, this);

                    if (_buffer[j].Gestures.BlockedDevices.Contains(type))
                        break;
                }

                ui.EvaluateGlobalGestures(gameTime, this);
                _blocked.Clear();
                _buffer.Clear();
            }

            foreach (var item in _cooled)
                item.HeatCount--;
            foreach (var item in _warmed)
                item.HeatCount++;

            _previous.Clear();
            _previous.AddRange(_current);
            _current.Clear();
        }
Example #15
0
        public override void Update(GameTime gameTime)
        {
            _touchLocation = TouchPanel.GetState().FirstOrDefault<TouchLocation>();

             	            if (_touchLocation.State == TouchLocationState.Pressed)
             	            {
             	                _intersectRect.X = (int)_touchLocation.Position.X;
             	                _intersectRect.Y = (int)_touchLocation.Position.Y;
             	                _intersectRect.Width = 1;
             	                _intersectRect.Height = 1;

             	                if (_intersectRect.Intersects(_rightRect))
             	                    PressedDirection = DpadDirection.dRIGTH;
             	                else if (_intersectRect.Intersects(_leftRect))
             	                    PressedDirection = DpadDirection.dLEFT;
             	                else if (_intersectRect.Intersects(_upRect))
             	                    PressedDirection = DpadDirection.dUP;
             	                else if (_intersectRect.Intersects(_downRect))
             	                    PressedDirection = DpadDirection.dDOWN;
             	                else
             	                    PressedDirection = DpadDirection.dNONE;

             	            }
             	            else if ((_touchLocation.State == TouchLocationState.Invalid) || (_touchLocation.State == TouchLocationState.Released))
             	                PressedDirection = DpadDirection.dNONE;

                base.Update(gameTime);
        }
Example #16
0
        private bool ProcessDoubleTap(TouchLocation touch)
        {
            if (!GestureIsEnabled(GestureType.DoubleTap) || _tapDisabled)
            {
                return(false);
            }

            // If the new tap is too far away from the last then
            // this cannot be a double tap event.
            var dist = Vector2.Distance(touch.Position, _lastTap.Position);

            if (dist > TapJitterTolerance)
            {
                return(false);
            }

            // Check that this tap happened within the standard
            // double tap time threshold of 300 milliseconds.
            var elapsed = touch.Timestamp - _lastTap.Timestamp;

            if (elapsed.TotalMilliseconds > 300)
            {
                return(false);
            }

            GestureList.Enqueue(new GestureSample(
                                    GestureType.DoubleTap, touch.Timestamp,
                                    touch.Position, Vector2.Zero,
                                    Vector2.Zero, Vector2.Zero));

            // Disable taps until after the next release.
            _tapDisabled = true;

            return(true);
        }
Example #17
0
        private void ProcessHold(TouchLocation touch)
        {
            if (!GestureIsEnabled(GestureType.Hold) || holdDisabled)
            {
                return;
            }

            TimeSpan elapsed = TimeSpan.FromTicks(DateTime.Now.Ticks) - touch.PressTimestamp;

            if (elapsed < maxTicksToProcessHold)
            {
                return;
            }

            holdDisabled = true;

            GestureList.Enqueue(
                new GestureSample(
                    GestureType.Hold,
                    touch.Timestamp,
                    touch.Position,
                    Vector2.Zero,
                    Vector2.Zero,
                    Vector2.Zero
                    )
                );
        }
Example #18
0
		public override void OnTouchMove (TouchLocation state) {
			var offset = Math.Min (0, state.Position.Y - startPos);
			if (-offset > (contentHeight - (this.ActualHeight - 50)))
				offset = -(contentHeight - (this.ActualHeight - 50));

			this.VerticalOffset = (int)offset;
			base.OnTouchMove (state);
		}
 public override void CheckUserTouch(TouchLocation tl)
 {
     if (tl.State == TouchLocationState.Pressed)
        {
        if (BlockHitBoxTouch.Intersects(new Rectangle((int)tl.Position.X, (int)tl.Position.Y, 1, 1)))
            Destroy();
        }
 }
Example #20
0
        private static void ProcessDrag(TouchLocation touch)
        {
            var dragH = GestureIsEnabled(GestureType.HorizontalDrag);
            var dragV = GestureIsEnabled(GestureType.VerticalDrag);
            var drag  = GestureIsEnabled(GestureType.FreeDrag);

            if (!dragH && !dragV && !drag)
            {
                return;
            }

            // Make sure this is a move event and that we have
            // a previous touch location.
            TouchLocation prevTouch;

            if (touch.State != TouchLocationState.Moved ||
                !touch.TryGetPreviousLocation(out prevTouch))
            {
                return;
            }

            var delta = touch.Position - prevTouch.Position;

            // Free drag takes priority over a directional one.
            var gestureType = GestureType.FreeDrag;

            if (!drag)
            {
                // Horizontal drag takes precedence over a vertical one.
                if (dragH)
                {
                    // Direction delta come back with it's 'other' component set to 0.
                    if (Math.Abs(delta.X) >= Math.Abs(delta.Y))
                    {
                        delta.Y     = 0;
                        gestureType = GestureType.HorizontalDrag;
                    }
                    else if (dragV)
                    {
                        delta.X     = 0;
                        gestureType = GestureType.VerticalDrag;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            _dragGestureStarted = true;
            _tapDisabled        = true;
            _holdDisabled       = true;

            GestureList.Enqueue(new GestureSample(
                                    gestureType, touch.Timestamp,
                                    touch.Position, Vector2.Zero,
                                    delta, Vector2.Zero));
        }
Example #21
0
        private static bool RefreshState(bool consumeState, List <TouchLocation> state, List <TouchLocation> events)
        {
            bool flag1 = false;

            for (int index1 = 0; index1 < state.Count; ++index1)
            {
                TouchLocation touchLocation = state[index1];
                if (consumeState || touchLocation.State == TouchLocationState.Moved)
                {
                    if (consumeState && touchLocation.State == TouchLocationState.Released)
                    {
                        state.RemoveAt(index1);
                        --index1;
                    }
                    else
                    {
                        bool flag2 = false;
                        for (int index2 = 0; index2 < events.Count; ++index2)
                        {
                            TouchLocation touchEvent = events[index2];
                            if ((consumeState || touchEvent.State != TouchLocationState.Released) && touchEvent.Id == touchLocation.Id)
                            {
                                flag1 = flag1 | touchLocation.UpdateState(touchEvent);
                                flag2 = true;
                                events.RemoveAt(index2);
                                break;
                            }
                        }
                        if (flag2)
                        {
                            state[index1] = touchLocation;
                        }
                        else if (consumeState)
                        {
                            state[index1] = touchLocation.AsMovedState();
                        }
                    }
                }
            }
            int index = 0;

            while (index < events.Count)
            {
                TouchLocation touchLocation = events[index];
                if (touchLocation.State == TouchLocationState.Pressed)
                {
                    state.Add(touchLocation);
                    events.RemoveAt(index);
                    flag1 = true;
                }
                else
                {
                    ++index;
                }
            }
            return(flag1);
        }
Example #22
0
		public override void OnTouchMove (TouchLocation state) {
			base.OnTouchMove (state);
			if (mouseDown) {
				if (DateTime.UtcNow - lastClick >= this.Interval) {
					OnClick ();
					lastClick = DateTime.UtcNow;
				}
			}
		}
Example #23
0
        internal static void AddEvent(int id, TouchLocationState state, Vector2 position)
        {
            // Different platforms return different touch identifiers
            // based on the specifics of their implementation and the
            // system drivers.
            //
            // Sometimes these ids are suitable for our use, but other
            // times it can recycle ids or do cute things like return
            // the same id for double tap events.
            //
            // We instead provide consistent ids by generating them
            // ourselves on the press and looking them up on move
            // and release events.
            //
            if (state == TouchLocationState.Pressed)
            {
                _touchIds[id] = _nextTouchId++;
            }

            // Try to find the touch id.
            int touchId;

            if (!_touchIds.TryGetValue(id, out touchId))
            {
                // If we got here that means either the device is sending
                // us bad, out of order, or old touch events.  In any case
                // just ignore them.
                return;
            }

            // Add the new touch event keeping the list from getting
            // too large if no one happens to be requesting the state.
            var evt = new TouchLocation(touchId, state, position * _touchScale);

            _touchEvents.Add(evt);
            if (_touchEvents.Count > MaxEvents)
            {
                _touchEvents.RemoveRange(0, _touchEvents.Count - MaxEvents);
            }

            // If we have gestures enabled then start to collect
            // events for those too.
            if (EnabledGestures != GestureType.None)
            {
                _gestureEvents.Add(evt);
                if (_gestureEvents.Count > MaxEvents)
                {
                    _gestureEvents.RemoveRange(0, _gestureEvents.Count - MaxEvents);
                }
            }

            // If this is a release unmap the hardware id.
            if (state == TouchLocationState.Released)
            {
                _touchIds.Remove(id);
            }
        }
Example #24
0
 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));
 }
Example #25
0
		public override void OnTouchUp (TouchLocation state) {
			foreach (var c in this.Children.OfType<Control>())
				if (c.IsEnabled 
						&& c.Opacity > 0 
						&& VisualTreeHelper.IsVisible ( c ) 
						&& (c.HitTest(state.Position) || c.IsTouchDown))
					c.OnTouchUp(state);

			base.OnTouchUp (state);
		}
Example #26
0
 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);
 }
Example #27
0
        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);
        }
Example #28
0
 public void handeTouch( TouchLocation touch )
 {
     if (this.rect.Contains((int)touch.Position.X, (int)touch.Position.Y))
     {
         pressed = true;
     }
     else
     {
         pressed = false;
     }
 }
Example #29
0
		public override void OnTouchDown (TouchLocation state) {
			foreach (var c in this.Children.OfType<Control>()) {
				if (c.IsEnabled 
						&& c.Opacity > 0 // TODO Should remove, in WPF, transparent Buttons are clickable
						&& VisualTreeHelper.IsVisible ( c ) 
						&& c.HitTest(state.Position)) {
					c.OnTouchDown(state);
				}
			}
			base.OnTouchDown (state);
		}
        public void Update(TouchCollection toucheCollection, GameTime gameTime)
        {
            TouchLocation[] touchLocs = new TouchLocation[toucheCollection.Count];
            int i = 0;
            foreach (var touch in toucheCollection)
            {
                touchLocs[i++] = new TouchLocation(touch.Id, touch.State, orientation.Transform(touch.Position));
            }

            baseTC.Update(new TouchCollection(touchLocs), gameTime);
        }
        internal void UpdateLocation(TouchLocation touchLocation)
        {
            if (this.TouchID == touchLocation.Id)
            {
                this.systemTouch = touchLocation;
                this.positions.UpdateLocation(touchLocation.Position);
                return;
            }

            throw new InvalidOperationException(string.Format("TouchLocation id({0}) must be matched with TouchID({1})", touchLocation.Id, TouchID));
        }
Example #32
0
        public bool IsPressed(TouchLocation touchLocation, float gameWindowHeight)
        {
            var gY = gameWindowHeight - touchLocation.Position.X;
              var gX = touchLocation.Position.Y;

              if ((gX > Position.X && gX < (Position.X + Size.Width)) && (gY < (Position.Y + Size.Height)) && gY > Position.Y)
              {
            return true;
              }
              return false;
        }
 public void Update(TouchLocation touchLocation)
 {
     if (touchLocation.State == TouchLocationState.Pressed ||
         touchLocation.State == TouchLocationState.Moved)
     {
         Vector2 delta = touchLocation.Position - _position;
         if (delta.LengthSquared() <= 400f)
         {
             Pressed = true;
         }
     }
 }
Example #34
0
        /// <summary>
        /// Updates the state and location of the touch
        /// </summary>
        public virtual void Update()
        {
            TouchCollection touchCollection = TouchPanel.GetState();

            if (touchCollection.Count() > 0)
            {
                touchLocation = touchCollection[0];
                touchChanged = true;
            }
            else if (touchChanged)
                touchChanged = false;
        }
Example #35
0
        internal static void SetFinger(int index, int fingerId, Vector2 fingerPos)
        {
            if (fingerId == NO_FINGER)
            {
                // Was there a finger here before and the user just released it?
                if (prevTouches[index].State != TouchLocationState.Invalid &&
                    prevTouches[index].State != TouchLocationState.Released)
                {
                    touches[index] = new TouchLocation(
                        prevTouches[index].Id,
                        TouchLocationState.Released,
                        prevTouches[index].Position,
                        prevTouches[index].State,
                        prevTouches[index].Position
                        );
                }
                else
                {
                    /* Nothing interesting here at all.
                     * Insert invalid data so this element
                     * is not included in GetState().
                     */
                    touches[index] = new TouchLocation(
                        NO_FINGER,
                        TouchLocationState.Invalid,
                        Vector2.Zero
                        );
                }

                return;
            }

            // Is this a newly pressed finger?
            if (prevTouches[index].State == TouchLocationState.Invalid)
            {
                touches[index] = new TouchLocation(
                    fingerId,
                    TouchLocationState.Pressed,
                    fingerPos
                    );
            }
            else
            {
                // This finger was already down, so it's "moved"
                touches[index] = new TouchLocation(
                    fingerId,
                    TouchLocationState.Moved,
                    fingerPos,
                    prevTouches[index].State,
                    prevTouches[index].Position
                    );
            }
        }
Example #36
0
 public void InteractLocation(TouchLocation touchLocation)
 {
     if (touchLocation.State == TouchLocationState.Pressed)
         m_pressLocation = touchLocation.Position;
     else if (touchLocation.State == TouchLocationState.Moved)
     {
         Vector2 position = new Vector2();
         position = WorldGameMode.m_Instance.WorldPosition + m_pressLocation - touchLocation.Position;
         m_pressLocation = touchLocation.Position;
         CenterOn(position);
     }
 }
        public override void CheckUserTouch(TouchLocation tl)
        {
            if (moved)
                return;

            if (BlockHitBoxTouch.Intersects(new Rectangle((int)tl.Position.X, (int)tl.Position.Y, 1, 1)))
            {
                moved = true;
            }

            base.CheckUserTouch(tl);
        }
Example #38
0
		public override bool IsPointInAsset(TouchLocation TL)
		{
			if (TL.Position.X >= gridX * GlobalConstants.TILE_WIDTH && TL.Position.X <= (gridX + width) * GlobalConstants.TILE_WIDTH)
			{
				if (TL.Position.Y >= gridY * GlobalConstants.TILE_HEIGHT && TL.Position.Y <= (gridY + height) * GlobalConstants.TILE_HEIGHT)
				{
					return true;
				}
			}

			return false;
		}
Example #39
0
 private void AgeTouches(List <TouchLocation> state)
 {
     for (int i = state.Count - 1; i >= 0; i -= 1)
     {
         TouchLocation touch = state[i];
         if (touch.State == TouchLocationState.Released)
         {
             state.RemoveAt(i);
         }
         else if (touch.State == TouchLocationState.Pressed)
         {
             touch.AgeState();
             state[i] = touch;
         }
     }
 }
Example #40
0
        /// <summary>
        /// Handles Source deck touch. Moves card to Waste deck
        /// </summary>
        /// <param name="tl"></param>
        /// <returns></returns>
        public override Card HandleTouch(TouchLocation tl)
        {
            Card ret = null;

            foreach (Card c in m_cards)
            {
                if (c.isInTouch(tl))
                {
                    // Take most upper cards from the deck
                    if (ret != null && ret.m_z < c.m_z)
                    {
                        ret = c;
                    }
                    else if (ret == null)
                    {
                        ret = c;
                    }
                }
            }

            if (ret != null)
            {
                // If card found, turn it
                ret.setTurned(true);
                // and move to waste deck
                RemoveCard(ret);
                p_wasteDeck.AddCard(ret);
            }
            else
            {
                // Source deck is empty
                // Copy cards back to source deck from waste
                if (IsInTouch(tl) && CardCount() == 0)
                {
                    for (int i = 0; i < p_wasteDeck.CardCount(); i++)
                    {
                        Card lastCard = p_wasteDeck.RemoveLast();
                        lastCard.setTurned(false);
                        AddCard(lastCard);
                        i--;
                    }
                }

            }

            return null;
        }
Example #41
0
        public void AgeStateUpdatesPreviousDetails([Values(true, false)] bool isSameFrameReleased)
        {
            var touch = new TouchLocation(1, TouchLocationState.Pressed, new Vector2(1, 2), TimeSpan.FromSeconds(1));

            if (isSameFrameReleased)
                touch.SameFrameReleased = true;

            touch.AgeState();

            TouchLocation previous;
            Assert.True(touch.TryGetPreviousLocation(out previous));

            Assert.AreEqual(TouchLocationState.Pressed, previous.State);
            Assert.AreEqual(touch.Id, previous.Id);
            Assert.AreEqual(touch.Position, previous.Position);
            Assert.AreEqual(touch.Timestamp, previous.Timestamp);
        }
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            /// <summary>
            /// Read Touchscreen input
            /// </summary>
            /// <remarks>
            /// The base HandleInput has already populated lastTouchInput
            /// </remarks>
            if (lastTouchInput.Count > 0)
            {
                foreach (var touch in lastTouchInput)
                {
                    switch (touch.State)
                    {
                        case TouchLocationState.Pressed:
                            if (topPaddleTouchId == -1 &&
                                touch.Position.Y < topPaddle.Position.Y + topPaddle.Height &&
                                touch.Position.X > topPaddle.Position.X - 20 &&
                                touch.Position.X < topPaddle.Position.X + topPaddle.Width + 20)
                            {
                                topPaddleTouch = touch;
                                topPaddleTouchId = touch.Id;
                                //TODO: remove touch from lastTouchInput?
                            }
                            break;
                        case TouchLocationState.Moved:
                            if (touch.Id == topPaddleTouchId)
                            {
                                topPaddleTouch = touch;
                            }
                            break;
                        case TouchLocationState.Released:
                            if (touch.Id == topPaddleTouchId)
                            {
                                topPaddleTouchId = -1;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
Example #43
0
        public bool ProcessTouch(TouchLocation touch)
        {
            if (Texture == null)
                return false;

            bool touchHandled = false;

            switch (touch.State)
            {
                case TouchLocationState.Pressed:
                    if ((touch.Position.X > Position.X - Origin.X) &&
                        (touch.Position.X < Position.X - Origin.X + Texture.Width) &&
                        (touch.Position.Y > Position.Y - Origin.Y) &&
                        (touch.Position.Y < Position.Y - Origin.Y + Texture.Height))
                    {
                        touchId = touch.Id;
                        touchHandled = true;
                    }
                    break;

                case TouchLocationState.Moved:
                    if (touchId.HasValue && touchId.Value == touch.Id)
                    {
                        TouchLocation previousTouch;
                        touch.TryGetPreviousLocation(out previousTouch);
                        Position += touch.Position - previousTouch.Position;

                        // Fire the event!
                        if (PositionChanged != null)
                            PositionChanged(this, EventArgs.Empty);

                        touchHandled = true;
                    }
                    break;

                case TouchLocationState.Released:
                    if (touchId.HasValue && touchId.Value == touch.Id)
                    {
                        touchId = null;
                        touchHandled = true;
                    }
                    break;
            }
            return touchHandled;
        }
 public virtual void HandleInput(InputManager touches)
 {
     if (!_inTouch && touches.Count > 0 && touches[0].State == TouchLocationState.Pressed)
     {
         var touch = touches[0];
         if (InActiveArea(touch.Position))
         {
             _touch = touch;
             _inTouch = true;
         }
     }
     else if (_inTouch)
     {
         TouchLocation touch;
         if (!touches.FindById(_touch.Id, out touch))
         {
             _inTouch = false;
             BeginUnhighlight();
         }
         else
         {
             if (touch.State == TouchLocationState.Released && InActiveArea(touch.Position))
             {
                 if (!touches.IsHandled(touch.Id))
                 {
                     OnOnTap();
                     touches.MarkAsHandled(touch.Id);
                 }
                 _inTouch = false;
                 BeginUnhighlight();
             }
             else
             {
                 if (InActiveArea(touch.Position))
                 {
                     BeginHighlight();
                 }
                 else
                 {
                     BeginUnhighlight();
                 }
             }
         }
     }
 }
Example #45
0
        public static void Update()
        {
            OldTouchState = TouchState;
            TouchState = TouchPanel.GetState().FirstOrDefault();
            //Debug.WriteLine(TouchPanel.GetState().Count);

            OldMouseState = MouseState;
            MouseState = Mouse.GetState();

            if (OldMouseState.X != MouseState.X || OldMouseState.Y != MouseState.Y || MouseState.LeftButton == ButtonState.Pressed) {
                IsUsingTouchScreen = false;
            }

            //Debug.WriteLine(TouchState.State == TouchLocationState.Invalid);
            if (TouchState != null && TouchState.State != TouchLocationState.Invalid) {
                IsUsingTouchScreen = true;
            }
        }
Example #46
0
        public override bool HandleTouch(TouchCollection tc)
        {
            TouchLocation tl = tc[0];
            TouchLocation tl2;

            bool shoot = false;
            bool moveGun = false;

            if ((tc[0].State == TouchLocationState.Released && tc[0].Position.X > 400)
                    || (tc.Count > 1 && tc[1].Position.X > 400 && tc[1].State == TouchLocationState.Released))
            {
                shoot = true;
            }

            if (tc[0].Position.X < 400)
            {
                tl = tc[0];
                moveGun = true;
            }
            else if(tc.Count > 1 && tc[1].Position.X < 400)
            {
                tl = tc[1];
                moveGun = true;
            }

            if (shoot)
            {
                PerformShoot();
            }

            if (moveGun)
            {
                if (tl.State == TouchLocationState.Pressed)
                {
                    pressedLocation = tl;
                }
                else if (tl.State == TouchLocationState.Moved)
                {
                    armyMan.GunAngle = (float)Math.PI * (tl.Position.Y - pressedLocation.Position.Y) / 100;
                }
            }

            return true;
        }
Example #47
0
        private void ProcessTap(TouchLocation touch)
        {
            if (!GestureIsEnabled(GestureType.Tap) || tapDisabled)
            {
                return;
            }

            /* If the release is too far away from the press
             * position then this cannot be a tap event.
             */
            float dist = Vector2.Distance(touch.PressPosition, touch.Position);

            if (dist > TapJitterTolerance)
            {
                return;
            }

            /* If we pressed and held too long then don't
             * generate a tap event for it.
             */
            TimeSpan elapsed = TimeSpan.FromTicks(DateTime.Now.Ticks) - touch.PressTimestamp;

            if (elapsed > maxTicksToProcessHold)
            {
                return;
            }

            // Store the last tap for double tap processing.
            lastTap = touch;

            // Fire off the tap event immediately.
            GestureSample tap = new GestureSample(
                GestureType.Tap,
                touch.Timestamp,
                touch.Position,
                Vector2.Zero,
                Vector2.Zero,
                Vector2.Zero
                );

            GestureList.Enqueue(tap);
        }
Example #48
0
        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));
        }
Example #49
0
        internal void ResetState()
        {
            _touchState.Clear();
            _touchEvents.Clear();
            _gestureState.Clear();
            _gestureEvents.Clear();

            _touchScale  = Vector2.One;
            _displaySize = Point.Zero;

            _nextTouchId = 2;

            _touchIds.Clear();

            GestureList.Clear();

            _pinchGestureStarted = false;
            _tapDisabled         = false;

            _holdDisabled = false;

            _dragGestureStarted = GestureType.None;
            _lastTap            = new TouchLocation();
        }
Example #50
0
        internal void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse)
        {
            // Different platforms return different touch identifiers
            // based on the specifics of their implementation and the
            // system drivers.
            //
            // Sometimes these ids are suitable for our use, but other
            // times it can recycle ids or do cute things like return
            // the same id for double tap events.
            //
            // We instead provide consistent ids by generating them
            // ourselves on the press and looking them up on move
            // and release events.
            //
            if (state == TouchLocationState.Pressed)
            {
                if (isMouse)
                {
                    // Mouse pointing devices always use a reserved Id
                    _touchIds[id] = MouseTouchId;
                }
                else
                {
                    _touchIds[id] = _nextTouchId++;
                }
            }

            // Try to find the touch id.
            int touchId;

            if (!_touchIds.TryGetValue(id, out touchId))
            {
                // If we got here that means either the device is sending
                // us bad, out of order, or old touch events.  In any case
                // just ignore them.
                return;
            }

            if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures)
            {
                // Add the new touch event keeping the list from getting
                // too large if no one happens to be requesting the state.
                var evt = new TouchLocation(touchId, state, position * _touchScale, CurrentTimestamp);

                if (!isMouse || EnableMouseTouchPoint)
                {
                    ApplyTouch(_touchState, evt);
                }

                //If we have gestures enabled then collect events for those too.
                //We also have to keep tracking any touches while we know about touches so we don't miss releases even if gesture recognition is disabled
                if ((EnabledGestures != GestureType.None || _gestureState.Count > 0) && (!isMouse || EnableMouseGestures))
                {
                    ApplyTouch(_gestureState, evt);

                    if (EnabledGestures != GestureType.None)
                    {
                        UpdateGestures(true);
                    }

                    AgeTouches(_gestureState);
                }
            }

            // If this is a release unmap the hardware id.
            if (state == TouchLocationState.Released)
            {
                _touchIds.Remove(id);
            }
        }
Example #51
0
        internal void AddEvent(int id, TouchLocationState state, Vector2 position, bool isMouse)
        {
            /* Different platforms return different touch identifiers
             * based on the specifics of their implementation and the
             * system drivers.
             *
             * Sometimes these ids are suitable for our use, but other
             * times it can recycle ids or do cute things like return
             * the same id for double tap events.
             *
             * We instead provide consistent ids by generating them
             * ourselves on the press and looking them up on move
             * and release events.
             */
            if (state == TouchLocationState.Pressed)
            {
                if (isMouse)
                {
                    // Mouse pointing devices always use a reserved Id
                    touchIds[id] = MouseTouchId;
                }
                else
                {
                    touchIds[id] = nextTouchId += 1;
                }
            }

            // Try to find the touch id.
            int touchId;

            if (!touchIds.TryGetValue(id, out touchId))
            {
                /* If we got here that means either the device is sending
                 * us bad, out of order, or old touch events.  In any case
                 * just ignore them.
                 */
                return;
            }

            if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures)
            {
                /* Add the new touch event keeping the list from getting
                 * too large if no one happens to be requesting the state.
                 */
                TouchLocation evt = new TouchLocation(touchId, state, position * touchScale);

                if (!isMouse || EnableMouseTouchPoint)
                {
                    touchEvents.Add(evt);
                    if (touchEvents.Count > MaxEvents)
                    {
                        touchEvents.RemoveRange(
                            0,
                            touchEvents.Count - MaxEvents
                            );
                    }
                }

                /* If we have gestures enabled then start to collect
                 * events for those too.
                 */
                if (EnabledGestures != GestureType.None && (!isMouse || EnableMouseGestures))
                {
                    gestureEvents.Add(evt);
                    if (gestureEvents.Count > MaxEvents)
                    {
                        gestureEvents.RemoveRange(
                            0,
                            gestureEvents.Count - MaxEvents
                            );
                    }
                }
            }

            // If this is a release unmap the hardware id.
            if (state == TouchLocationState.Released)
            {
                touchIds.Remove(id);
            }
        }
Example #52
0
        private void ProcessDrag(TouchLocation touch)
        {
            var dragH = GestureIsEnabled(GestureType.HorizontalDrag);
            var dragV = GestureIsEnabled(GestureType.VerticalDrag);
            var dragF = GestureIsEnabled(GestureType.FreeDrag);

            if (!dragH && !dragV && !dragF)
            {
                return;
            }

            // Make sure this is a move event and that we have
            // a previous touch location.
            TouchLocation prevTouch;

            if (touch.State != TouchLocationState.Moved ||
                !touch.TryGetPreviousLocation(out prevTouch))
            {
                return;
            }

            var delta = touch.Position - prevTouch.Position;

            // If we're free dragging then stick to it.
            if (_dragGestureStarted != GestureType.FreeDrag)
            {
                var isHorizontalDelta = Math.Abs(delta.X) > Math.Abs(delta.Y * 2.0f);
                var isVerticalDelta   = Math.Abs(delta.Y) > Math.Abs(delta.X * 2.0f);
                var classify          = _dragGestureStarted == GestureType.None;

                // Once we enter either vertical or horizontal drags
                // we stick to it... regardless of the delta.
                if (dragH && ((classify && isHorizontalDelta) || _dragGestureStarted == GestureType.HorizontalDrag))
                {
                    delta.Y             = 0;
                    _dragGestureStarted = GestureType.HorizontalDrag;
                }
                else if (dragV && ((classify && isVerticalDelta) || _dragGestureStarted == GestureType.VerticalDrag))
                {
                    delta.X             = 0;
                    _dragGestureStarted = GestureType.VerticalDrag;
                }

                // If the delta isn't either horizontal or vertical
                //then it could be a free drag if not classified.
                else if (dragF && classify)
                {
                    _dragGestureStarted = GestureType.FreeDrag;
                }
                else
                {
                    // If we couldn't classify the drag then
                    // it is nothing... set it to complete.
                    _dragGestureStarted = GestureType.DragComplete;
                }
            }

            // If the drag could not be classified then no gesture.
            if (_dragGestureStarted == GestureType.None ||
                _dragGestureStarted == GestureType.DragComplete)
            {
                return;
            }

            _tapDisabled  = true;
            _holdDisabled = true;

            GestureList.Enqueue(new GestureSample(
                                    _dragGestureStarted, touch.Timestamp,
                                    touch.Position, Vector2.Zero,
                                    delta, Vector2.Zero));
        }
Example #53
0
        internal void AddEvent(
            int id,
            TouchLocationState state,
            Vector2 position,
            bool isMouse
            )
        {
#if JSIL
            // HACK: IsConnected is determined statically, but in browsers
            //  you can't physically detect a touch panel and need to respond
            //  to the first tap you get instead.
            capabilities.isConnected = true;
#endif

            /* Different platforms return different touch identifiers
             * based on the specifics of their implementation and the
             * system drivers.
             *
             * Sometimes these ids are suitable for our use, but other
             * times it can recycle ids or do cute things like return
             * the same id for double tap events.
             *
             * We instead provide consistent ids by generating them
             * ourselves on the press and looking them up on move
             * and release events.
             */
            if (state == TouchLocationState.Pressed)
            {
                if (isMouse)
                {
                    // Mouse pointing devices always use a reserved Id
                    touchIds[id] = MouseTouchId;
                }
                else
                {
                    touchIds[id] = nextTouchId += 1;
                }
            }

            // Try to find the touch id.
            int touchId;
            if (!touchIds.TryGetValue(id, out touchId))
            {
                /* If we got here that means either the device is sending
                 * us bad, out of order, or old touch events.
                 * In any case, just ignore them.
                 */
                return;
            }

            if (!isMouse || EnableMouseTouchPoint || EnableMouseGestures)
            {
                /* Add the new touch event keeping the list from getting
                 * too large if no one happens to be requesting the state.
                 */
                TouchLocation evt = new TouchLocation(
                    touchId,
                    state,
                    position * touchScale,
                    CurrentTimestamp
                    );

                if (!isMouse || EnableMouseTouchPoint)
                {
                    ApplyTouch(touchState, evt);
                }

                /* If we have gestures enabled then start to collect
                 * events for those too.
                 * We also have to keep tracking any touches while
                 * we know about touches so we don't miss releases
                 * even if gesture recognition is disabled.
                 */
                if ((EnabledGestures != GestureType.None || gestureState.Count > 0) &&
                    (!isMouse || EnableMouseGestures))
                {
                    ApplyTouch(gestureState, evt);
                    if (EnabledGestures != GestureType.None)
                    {
                        UpdateGestures(true);
                    }
                    AgeTouches(gestureState);
                }
            }

            // If this is a release unmap the hardware id.
            if (state == TouchLocationState.Released)
            {
                touchIds.Remove(id);
            }
        }
Example #54
0
        internal static void Update()
        {
            // Remove all touches that were released last frame
            touches.RemoveAll(touch => touch.State == TouchLocationState.Released);

            // Update Gesture Detector for time-sensitive gestures
            GestureDetector.OnTick();

            // Save touch states and positions for future reference
            List <TouchLocation> prevTouches = new List <TouchLocation>(touches);

            // Process Pressed touch events from last frame
            for (int i = 0; i < touches.Count; i += 1)
            {
                if (touches[i].State == TouchLocationState.Pressed)
                {
                    // If this press was marked for release
                    if (touchIDsToRelease.Contains(touches[i].Id))
                    {
                        // Change the touch's state to Released
                        touches[i] = new TouchLocation(
                            touches[i].Id,
                            TouchLocationState.Released,
                            touches[i].Position,
                            prevTouches[i].State,
                            prevTouches[i].Position
                            );
                    }
                    else
                    {
                        // Change the touch's state to Moved
                        touches[i] = new TouchLocation(
                            touches[i].Id,
                            TouchLocationState.Moved,
                            touches[i].Position,
                            prevTouches[i].State,
                            prevTouches[i].Position
                            );
                    }
                }
            }
            touchIDsToRelease.Clear();

            // Process new touch events
            while (touchEvents.Count > 0)
            {
                TouchLocation touchEvent = touchEvents.Dequeue();

                // Add a new touch to the list if we have room
                if (touchEvent.State == TouchLocationState.Pressed &&
                    touches.Count < MAX_TOUCHES)
                {
                    touches.Add(touchEvent);
                }
                else
                {
                    // Update touches that were already registered
                    for (int i = 0; i < touches.Count; i += 1)
                    {
                        if (touches[i].Id == touchEvent.Id)
                        {
                            if (touches[i].State == TouchLocationState.Pressed)
                            {
                                // If the touch was pressed and released in the same frame
                                if (touchEvent.State == TouchLocationState.Released)
                                {
                                    // Mark it for release on the next frame
                                    touchIDsToRelease.Add(touches[i].Id);
                                }
                            }
                            else
                            {
                                // Update the existing touch with new data
                                touches[i] = new TouchLocation(
                                    touches[i].Id,
                                    touchEvent.State,
                                    touchEvent.Position,
                                    prevTouches[i].State,
                                    prevTouches[i].Position
                                    );
                            }

                            // We found the touch we were looking for.
                            break;
                        }
                    }
                }
            }
        }
Example #55
0
        internal bool Refresh(
            bool consumeState,
            List <TouchLocation> state,
            List <TouchLocation> events
            )
        {
            bool stateChanged = false;

            // Update the existing touch locations.
            for (int i = 0; i < state.Count; i += 1)
            {
                // Get the next touch location for update.
                TouchLocation touch = state[i];

                // If this location isn't in the move state yet then skip it.
                if (!consumeState && touch.State != TouchLocationState.Moved)
                {
                    continue;
                }

                /* If the touch state has been consumed then we can
                 * remove old release locations.
                 */
                if (consumeState && touch.State == TouchLocationState.Released)
                {
                    state.RemoveAt(i);
                    i -= 1;
                    continue;
                }

                bool foundEvent = false;

                /* Remove the next pending event with the
                 * same id and make it the new touch state.
                 */
                for (int j = 0; j < events.Count; j += 1)
                {
                    TouchLocation newTouch = events[j];

                    /* Don't let a release event occur until we're
                     * ready to consume state again.
                     */
                    if (!consumeState && newTouch.State == TouchLocationState.Released)
                    {
                        continue;
                    }

                    if (newTouch.Id == touch.Id)
                    {
                        stateChanged |= touch.UpdateState(newTouch);
                        foundEvent    = true;
                        events.RemoveAt(j);
                        j -= 1;

                        // Consume unchanged events.
                        if (!stateChanged)
                        {
                            continue;
                        }
                        break;
                    }
                }

                // If a new event was found then store it.
                if (foundEvent)
                {
                    state[i] = touch;
                }

                /* Else if no event has come in then promote it to
                 * the moved state, but only when we're consuming state.
                 */
                else if (consumeState)
                {
                    state[i] = touch.AsMovedState();
                }
            }

            /* We add new pressed events last so they are not
             * consumed before the touch state is returned.
             */
            for (int i = 0; i < events.Count;)
            {
                TouchLocation loc = events[i];

                if (loc.State == TouchLocationState.Pressed)
                {
                    state.Add(loc);
                    events.RemoveAt(i);
                    stateChanged = true;
                    continue;
                }

                i += 1;
            }

            return(stateChanged);
        }