Пример #1
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;
        }
Пример #2
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));
        }
Пример #3
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);
        }
Пример #4
0
        private void ProcessDrag(TouchLocation touch)
        {
            bool dragH = GestureIsEnabled(GestureType.HorizontalDrag);
            bool dragV = GestureIsEnabled(GestureType.VerticalDrag);
            bool 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;
            }

            Vector2 delta = touch.Position - prevTouch.Position;

            // If we're free dragging then stick to it.
            if (dragGestureStarted != GestureType.FreeDrag)
            {
                bool isHorizontalDelta = Math.Abs(delta.X) > Math.Abs(delta.Y * 2.0f);
                bool isVerticalDelta = Math.Abs(delta.Y) > Math.Abs(delta.X * 2.0f);
                bool 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
                )
            );
        }
Пример #5
0
            protected override bool AcceptTouchLocation(TouchLocation touchLocation)
            {
                if(touchLocation.State != TouchLocationState.Pressed)
                {
                    return false;
                }

                TouchLocation previousLocation;
                if (!touchLocation.TryGetPreviousLocation(out previousLocation))
                {
                    previousLocation = touchLocation;
                }

                if (this.TouchArea.Contains(previousLocation.Position))
                {
                    return true;
                }

                return false;
            }
Пример #6
0
            protected override bool AcceptTouchLocation(TouchLocation touchLocation)
            {
                TouchLocation previousLocation;
                if (!touchLocation.TryGetPreviousLocation(out previousLocation))
                {
                    previousLocation = touchLocation;
                }

                // todo: InputRadiusBias to parameter when creating the thumbstick? not sure if it is always wanted (and also the amount will vary)
                const float InputRadiusBias = 32;
                if (Vector2.Distance(previousLocation.Position, this.CenterPosition.Value) < this.Radius + InputRadiusBias)
                {
                    return true;
                }

                return false;
            }
Пример #7
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));
        }
Пример #8
0
            protected override bool AcceptTouchLocation(TouchLocation touchLocation)
            {
                TouchLocation previousLocation;
                if (!touchLocation.TryGetPreviousLocation(out previousLocation))
                {
                    previousLocation = touchLocation;
                }

                if (Vector2.Distance(previousLocation.Position, this.CenterPosition.Value) < this.Radius)
                {
                    return true;
                }

                return false;
            }
Пример #9
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));
 }
Пример #10
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));
        }
Пример #11
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;
        }