示例#1
0
 private void AddPointerEvent(PointerDeviceState.InputEvent evt)
 {
     PointerState.PointerInputEvents.Add(evt);
 }
示例#2
0
        private void Touched(NSSet touchesSet, UIEvent evt)
        {
            if (touchesSet != null)
            {
                // Convert touches to pointer events
                foreach (var item in touchesSet)
                {
                    var uitouch      = (UITouch)item;
                    var pointerEvent = new PointerDeviceState.InputEvent();
                    var touchId      = uitouch.Handle.ToInt32();

                    pointerEvent.Position = Normalize(CGPointToVector2(uitouch.LocationInView(uiControl.GameView)));
                    switch (uitouch.Phase)
                    {
                    case UITouchPhase.Began:
                        pointerEvent.Type = PointerEventType.Pressed;
                        break;

                    case UITouchPhase.Moved:
                    case UITouchPhase.Stationary:
                        pointerEvent.Type = PointerEventType.Moved;
                        break;

                    case UITouchPhase.Ended:
                        pointerEvent.Type = PointerEventType.Released;
                        break;

                    case UITouchPhase.Cancelled:
                        pointerEvent.Type = PointerEventType.Canceled;
                        break;

                    default:
                        throw new ArgumentException("Got an invalid Touch event in GetState");
                    }

                    // Assign finger index (starting at 0) to touch ID
                    int touchFingerIndex = 0;
                    if (pointerEvent.Type == PointerEventType.Pressed)
                    {
                        touchFingerIndex = touchCounter++;
                        touchFingerIndexMap.Add(touchId, touchFingerIndex);
                    }
                    else
                    {
                        touchFingerIndex = touchFingerIndexMap[touchId];
                    }

                    // Remove index
                    if (pointerEvent.Type == PointerEventType.Released)
                    {
                        touchFingerIndexMap.Remove(touchId);
                        touchCounter = 0; // Reset touch counter

                        // Recalculate next finger index
                        if (touchFingerIndexMap.Count > 0)
                        {
                            touchFingerIndexMap.ForEach(pair => touchCounter = Math.Max(touchCounter, pair.Value));
                            touchCounter++; // next
                        }
                    }

                    pointerEvent.Id = touchFingerIndex;
                    PointerState.PointerInputEvents.Add(pointerEvent);
                }
            }
        }