Esempio n. 1
0
        // TODO: Review FillTouchCollection
        private void FillTouchCollection(NSSet touches)
        {
            if (touches.Count == 0)
            {
                return;
            }

            TouchCollection collection   = TouchPanel.Collection;
            var             touchesArray = touches.ToArray <UITouch> ();

            for (int i = 0; i < touchesArray.Length; ++i)
            {
                var touch = touchesArray [i];

                //Get position touch
                var location = touch.LocationInView(touch.View);
                var position = GetOffsetPosition(new Vector2(location.X, location.Y), true);
                var id       = touch.Handle.ToInt32();

                switch (touch.Phase)
                {
                case UITouchPhase.Stationary:
                case UITouchPhase.Moved:
                    collection.Update(id, TouchLocationState.Moved, position);

                    if (i == 0)
                    {
                        Mouse.State.X = (int)position.X;
                        Mouse.State.Y = (int)position.Y;
                    }
                    break;

                case UITouchPhase.Began:
                    collection.Add(id, position);
                    if (i == 0)
                    {
                        Mouse.State.X          = (int)position.X;
                        Mouse.State.Y          = (int)position.Y;
                        Mouse.State.LeftButton = ButtonState.Pressed;
                    }
                    break;

                case UITouchPhase.Ended:
                    collection.Update(id, TouchLocationState.Released, position);

                    if (i == 0)
                    {
                        Mouse.State.X          = (int)position.X;
                        Mouse.State.Y          = (int)position.Y;
                        Mouse.State.LeftButton = ButtonState.Released;
                    }
                    break;

                case UITouchPhase.Cancelled:
                    collection.Update(id, TouchLocationState.Invalid, position);
                    break;

                default:
                    break;
                }
            }
        }