Пример #1
0
        /// <summary>
        /// Updates this instance.
        /// </summary>
        public override void Update()
        {
            isTouched  = false;
            hasGesture = false;

            Xenko.Input.InputManager manager = XenkoInputDevice.NativeInputManager;

            if (manager.PointerEvents.Count > 0)
            {
                var pointerEvent = manager.PointerEvents[0];
                if (pointerEvent.Pointer is IMouseDevice)
                {
                    isTouched = false;
                    return;
                }

                id               = pointerEvent.PointerId;
                isTouched        = true;
                normalizedX      = pointerEvent.Position.X;
                normalizedY      = pointerEvent.Position.Y;
                previousState    = pointerEvent.EventType;
                previousLocation = pointerEvent.Position;
                switch (pointerEvent.EventType)
                {
                case PointerEventType.Pressed:
                    action = TouchAction.Pressed;
                    break;

                case PointerEventType.Moved:
                    action = TouchAction.Moved;
                    break;

                case PointerEventType.Released:
                    action = TouchAction.Released;
                    break;

                case PointerEventType.Canceled:
                    action = TouchAction.None;
                    break;

                default:
                    break;
                }
            }
            else if (previousState == PointerEventType.Moved)
            {
                previousState = PointerEventType.Canceled;
                action        = TouchAction.Released;
                normalizedX   = previousLocation.X;
                normalizedY   = previousLocation.Y;
                isTouched     = true;
            }

            if (manager.GestureEvents.Count > 0)
            {
                hasGesture = true;
                var gestureEvent = manager.GestureEvents[0];
                switch (gestureEvent.Type)
                {
                case GestureType.Composite:
                    gesture = TouchGestures.MoveRotateAndScale;
                    var compositeEvent = gestureEvent as GestureEventComposite;
                    normalizedX = compositeEvent.CenterCurrentPosition.X;
                    normalizedY = compositeEvent.CenterCurrentPosition.Y;
                    moveX       = compositeEvent.DeltaTranslation.X;
                    moveY       = compositeEvent.DeltaTranslation.Y;
                    break;

                case GestureType.Drag:
                    gesture = TouchGestures.FreeDrag;
                    var dragGestureEvent = gestureEvent as GestureEventDrag;
                    normalizedX = dragGestureEvent.CurrentPosition.X;
                    normalizedY = dragGestureEvent.CurrentPosition.Y;
                    moveX       = dragGestureEvent.DeltaTranslation.X;
                    moveY       = dragGestureEvent.DeltaTranslation.Y;
                    break;

                case GestureType.Flick:
                    gesture = TouchGestures.Flick;
                    var flickEvent = gestureEvent as GestureEventFlick;
                    normalizedX = flickEvent.CurrentPosition.X;
                    normalizedY = flickEvent.CurrentPosition.Y;
                    moveX       = flickEvent.DeltaTranslation.X;
                    moveY       = flickEvent.DeltaTranslation.Y;
                    break;

                case GestureType.LongPress:
                    gesture = TouchGestures.Hold;
                    var longPressEvent = gestureEvent as GestureEventLongPress;
                    normalizedX = longPressEvent.Position.X;
                    normalizedY = longPressEvent.Position.Y;
                    moveX       = moveY = 0;
                    break;

                case GestureType.Tap:
                    gesture = TouchGestures.Tap;
                    var tapEvent = gestureEvent as GestureEventTap;
                    normalizedX = tapEvent.TapPosition.X;
                    normalizedY = tapEvent.TapPosition.Y;
                    moveX       = moveY = 0;
                    break;

                default:
                    break;
                }
            }
        }
Пример #2
0
 public abstract void Initialize(InputManager inputManager);