Exemplo n.º 1
0
        internal void ProcessDown(int id, Vector2 position, DateTime time)
        {
            TouchElement element = new TouchElement()
            {
                Origin        = position,
                Position      = position,
                Valid         = true,
                LockedGesture = GestureType.None,
                DownTime      = DateTime.Now
            };

            _gesture.GestureType = GestureType.Down;
            _gesture.Origin      = position;
            _gesture.Position    = position;
            _gesture.TouchId     = id;
            _gesture.Offset      = Vector2.Zero;
            _gesture.Time        = time;

            OnGesture();

            element.LockedListener = _gesture.PointerCapturedBy;

            _elements.Remove(id);
            _elements.Add(id, element);

            TouchDown?.Invoke(id, position);
        }
Exemplo n.º 2
0
        void ProcessMove(int id, Vector2 position, float time)
        {
            TouchElement element = _elements[id];
            Vector2      move    = position - element.Position;

            element.Position = position;

            _gesture.GestureType       = GestureType.Move;
            _gesture.Origin            = element.Origin;
            _gesture.Position          = position;
            _gesture.TouchId           = id;
            _gesture.Offset            = move;
            _gesture.PointerCapturedBy = element.LockedListener;

            if (move != Vector2.Zero)
            {
                OnGesture();
            }

            if (!_gesture.Handled)
            {
                AnalyzeMoveGestures(id, ref element, ref move);
            }

            element.LockedListener = _gesture.PointerCapturedBy;

            _elements.Remove(id);
            _elements.Add(id, element);
        }
Exemplo n.º 3
0
        void ProcessDown(int id, Vector2 position)
        {
            TouchElement element = new TouchElement()
            {
                Origin        = position,
                Position      = position,
                Valid         = true,
                LockedGesture = GestureType.None,
                DownTime      = DateTime.Now
            };

            _gesture.GestureType = GestureType.Down;
            _gesture.Origin      = position;
            _gesture.Position    = position;
            _gesture.TouchId     = id;
            _gesture.Offset      = Vector2.Zero;

            OnGesture();

            element.LockedListener = _gesture.PointerCapturedBy;

            _elements.Add(id, element);

            if (TouchDown != null)
            {
                TouchDown(id, position);
            }
        }
Exemplo n.º 4
0
        void AnalyzeMoveGestures(int id, ref TouchElement element, ref Vector2 move)
        {
            if ((element.LockedGesture & (GestureType.HorizontalDrag | GestureType.VerticalDrag | GestureType.Hold | GestureType.HoldStart | GestureType.Down)) == GestureType.None)
            {
                Vector2 drag = element.Position - element.Origin;

                if (Math.Abs(drag.X) > MinDragSize && Math.Abs(drag.X) > Math.Abs(drag.Y))
                {
                    element.LockedGesture |= GestureType.HorizontalDrag;
                }
                else if (Math.Abs(drag.Y) > MinDragSize && Math.Abs(drag.Y) > Math.Abs(drag.X))
                {
                    element.LockedGesture |= GestureType.VerticalDrag;
                }

                if (drag.Length() > MinDragSize)
                {
                    element.LockedGesture |= GestureType.FreeDrag;
                    move = drag;
                }
            }

            if ((element.LockedGesture & (GestureType.HorizontalDrag | GestureType.FreeDrag | GestureType.VerticalDrag)) != GestureType.None)
            {
                _gesture.TouchId     = id;
                _gesture.Position    = element.Position;
                _gesture.Origin      = element.Origin;
                _gesture.Offset      = move;
                _gesture.GestureType = element.LockedGesture;

                OnGesture();
            }
            else
            {
                _gesture.TouchId  = id;
                _gesture.Position = element.Position;
                _gesture.Origin   = element.Origin;
                _gesture.Offset   = Vector2.Zero;

                if (element.LockedGesture == GestureType.None)
                {
                    TimeSpan ellapsed = DateTime.Now - element.DownTime;

                    if (ellapsed.TotalMilliseconds > HoldStartTimeInMs)
                    {
                        element.LockedGesture = GestureType.HoldStart;
                        _gesture.GestureType  = GestureType.HoldStart;

                        OnGesture();
                    }
                }
                else if (element.LockedGesture == GestureType.HoldStart)
                {
                    TimeSpan ellapsed = DateTime.Now - element.DownTime;

                    if (move.Length() > MinDragSize)
                    {
                        element.LockedGesture = GestureType.Hold;
                        _gesture.GestureType  = GestureType.HoldCancel;

                        OnGesture();
                        return;
                    }

                    if (ellapsed.TotalMilliseconds > HoldTimeInMs)
                    {
                        element.LockedGesture = GestureType.Hold;
                        _gesture.GestureType  = GestureType.Hold;

                        OnGesture();
                    }
                }
            }
        }
Exemplo n.º 5
0
        void ProcessUp(int id, Vector2 position, float time)
        {
            TouchElement element = _elements[id];
            Vector2      move    = position - element.Position;

            element.Position       = position;
            element.LockedListener = null;

            _elements.Remove(id);

            _gesture.GestureType       = GestureType.Up;
            _gesture.Origin            = element.Origin;
            _gesture.Position          = position;
            _gesture.PointerCapturedBy = element.LockedListener;
            _gesture.TouchId           = id;
            _gesture.Offset            = move;

            OnGesture();

            if (element.LockedGesture == GestureType.HoldStart)
            {
                _gesture.GestureType = GestureType.HoldCancel;
                OnGesture();
            }

            if (!_gesture.Handled)
            {
                if (element.LockedGesture == GestureType.None)
                {
                    if ((element.Origin - element.Position).Length() < MinDragSize && (DateTime.Now - element.DownTime).TotalMilliseconds < HoldStartTimeInMs)
                    {
                        bool doubleTap = false;

                        if (_lastTap.HasValue)
                        {
                            if ((element.Position - _lastTap.Value.Position).Length() < DoubleTapSize)
                            {
                                _gesture.GestureType = GestureType.DoubleTap;

                                OnGesture();

                                doubleTap = true;

                                if (_gesture.Handled)
                                {
                                    _lastTap = null;
                                    return;
                                }
                            }
                        }

                        _gesture.GestureType = GestureType.Tap;
                        OnGesture();

                        if (!_gesture.Handled)
                        {
                            if (doubleTap)
                            {
                                _lastTap = null;
                            }
                            else
                            {
                                _lastTap = new LastTap()
                                {
                                    Position = _gesture.Position,
                                    Time     = 0
                                };
                            }
                        }
                    }
                }
            }
        }