Esempio n. 1
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            TouchLocation   tlocation;
            TouchCollection collection = TouchPanel.Collection;
            Vector2         position   = Vector2.Zero;

            position.X = e.GetX(e.ActionIndex);
            position.Y = e.GetY(e.ActionIndex);
            UpdateTouchPosition(ref position);
            int id = e.GetPointerId(e.ActionIndex);
            int index;

            switch (e.ActionMasked)
            {
            // DOWN
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                index = collection.FindIndexById(e.GetPointerId(e.ActionIndex), out tlocation);
                if (index < 0)
                {
                    tlocation = new TouchLocation(id, TouchLocationState.Pressed, position);
                    collection.Add(tlocation);
                }
                else
                {
                    tlocation.State    = TouchLocationState.Pressed;
                    tlocation.Position = position;
                }
                break;

            // UP
            case MotionEventActions.Up:
            case MotionEventActions.PointerUp:
                index = collection.FindIndexById(e.GetPointerId(e.ActionIndex), out tlocation);
                if (index >= 0)
                {
                    tlocation.State   = TouchLocationState.Released;
                    collection[index] = tlocation;
                }
                break;

            // MOVE
            case MotionEventActions.Move:
                for (int i = 0; i < e.PointerCount; i++)
                {
                    id         = e.GetPointerId(i);
                    position.X = e.GetX(i);
                    position.Y = e.GetY(i);
                    UpdateTouchPosition(ref position);
                    index = collection.FindIndexById(id, out tlocation);
                    if (index >= 0)
                    {
                        tlocation.State    = TouchLocationState.Moved;
                        tlocation.Position = position;
                        collection[index]  = tlocation;
                    }
                }
                break;

            // CANCEL, OUTSIDE
            case MotionEventActions.Cancel:
            case  MotionEventActions.Outside:
                index = collection.FindIndexById(id, out tlocation);
                if (index >= 0)
                {
                    tlocation.State   = TouchLocationState.Invalid;
                    collection[index] = tlocation;
                }
                break;
            }


            if (gesture != null)
            {
                GestureListener.CheckForDrag(e, position);
                gesture.OnTouchEvent(e);
            }

            return(true);
        }