Example #1
0
        private void AnalizeMovement(PointerId pointerId, PointerDownElement pointer, Vector2 move, TimeSpan time)
        {
            Vector2 drag = pointer.Position - pointer.Origin;

            if ((pointer.LockedGesture & (GestureType.HorizontalDrag | GestureType.VerticalDrag | GestureType.Hold | GestureType.HoldStart | GestureType.Down)) == GestureType.None)
            {
                if (Math.Abs(drag.X) > MinDragSize && Math.Abs(drag.X) > Math.Abs(drag.Y))
                {
                    pointer.LockedGesture = GestureType.HorizontalDrag;
                    move = drag;
                }
                else if (Math.Abs(drag.Y) > MinDragSize && Math.Abs(drag.Y) > Math.Abs(drag.X))
                {
                    pointer.LockedGesture = GestureType.VerticalDrag;
                    move = drag;
                }
                else if (drag.Length() > MinDragSize)
                {
                    pointer.LockedGesture = GestureType.FreeDrag;
                    move = drag;
                }
            }

            if ((pointer.LockedGesture & GestureType.DragGestures) != GestureType.None)
            {
                var offset = move;

                if (pointer.LockedGesture.HasFlag(GestureType.HorizontalDrag))
                {
                    offset.Y = 0;
                }
                if (pointer.LockedGesture.HasFlag(GestureType.VerticalDrag))
                {
                    offset.X = 0;
                }

                var gesture = gesturesPool.Get();
                gesture.Init(pointerId, pointer.Origin, pointer.Position, time);
                gesture.GestureType = pointer.LockedGesture & GestureType.DragGestures;
                gesture.Offset      = offset;
                Publish(gesture);

                if (!pointer.LockedGesture.HasFlag(GestureType.FreeDrag))
                {
                    gesture = gesturesPool.Get();
                    gesture.Init(pointerId, pointer.Origin, pointer.Position, time);
                    gesture.GestureType = GestureType.FreeDrag;
                    gesture.Offset      = move;
                    Publish(gesture);
                }
            }
        }
Example #2
0
        private void AnalizeHolds(PointerId pointerId, PointerDownElement pointer, TimeSpan time)
        {
            Vector2 drag = pointer.Position - pointer.Origin;

            if (pointer.LockedGesture == GestureType.None && drag.Length() < MinDragSize)
            {
                TimeSpan elapsed = time - pointer.DownTime;

                if (elapsed > HoldStartTime)
                {
                    pointer.LockedGesture = GestureType.HoldStart;

                    var gesture = gesturesPool.Get();
                    gesture.Init(pointerId, pointer.Origin, pointer.Position, time);
                    gesture.GestureType = GestureType.HoldStart;

                    Publish(gesture);
                }
            }
            else if (pointer.LockedGesture == GestureType.HoldStart)
            {
                TimeSpan elapsed = time - pointer.DownTime;

                if (drag.Length() > MinDragSize)
                {
                    pointer.LockedGesture &= ~GestureType.HoldGestures;

                    var gesture = gesturesPool.Get();
                    gesture.Init(pointerId, pointer.Origin, pointer.Position, time);
                    gesture.GestureType = GestureType.HoldCancel;
                    Publish(gesture);
                    return;
                }

                if (elapsed > HoldTime)
                {
                    pointer.LockedGesture = GestureType.Hold;

                    var gesture = gesturesPool.Get();
                    gesture.Init(pointerId, pointer.Origin, pointer.Position, time);
                    gesture.GestureType = GestureType.Hold;

                    Publish(gesture);
                }
            }
        }