Exemple #1
0
        private void TouchHandleElement_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            var touch = _GetExistTouchFromUwpPointer(e.Pointer);

            if (e.Pointer.PointerDeviceType != PointerDeviceType.Touch)
            {
                return;
            }
            if (touch == null)
            {
                throw new NotImplementedException();
            }
            _Touches.Remove(touch);
            OnTouchAction?.Invoke(touch, TouchMotionAction.Up);
        }
Exemple #2
0
        private void TouchHandleElement_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            var touch = _GetExistTouchFromUwpPointer(e.Pointer);

            if (e.Pointer.PointerDeviceType != PointerDeviceType.Touch)
            {
                return;
            }
            if (touch == null)
            {
                throw new NotImplementedException();
            }
            var newPosition = e.GetCurrentPoint(null).Position.ToVector2() * EpxToPxCoefficient;

            touch.Position = newPosition;
            OnTouchAction?.Invoke(touch, TouchMotionAction.Move);
        }
Exemple #3
0
        public bool OnTouch(MotionEvent e)
        {
            int pointerIndex = ((int)(e.Action & MotionEventActions.PointerIndexMask)) >> ((int)(MotionEventActions.PointerIndexShift));
            int pointerId    = e.GetPointerId(pointerIndex);
            int down         = (int)(e.ActionMasked & MotionEventActions.PointerDown);
            int up           = (int)(e.ActionMasked & MotionEventActions.PointerUp);

            switch (e.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
            {
                Touch touch = new Touch(pointerId);
                touch.Position = new Vector2(e.GetX(pointerIndex), e.GetY(pointerIndex));
                _Touches.Add(pointerId, touch);
                OnTouchAction?.Invoke(touch, TouchMotionAction.Down);
                break;
            }

            case MotionEventActions.Up:
            case MotionEventActions.PointerUp:
            {
                Touch touch = _Touches[pointerId];
                _Touches.Remove(pointerId);
                OnTouchAction?.Invoke(touch, TouchMotionAction.Up);
                break;
            }

            case MotionEventActions.Move:
            {
                foreach (var pair in _Touches)
                {
                    int     pIndex     = e.FindPointerIndex(pair.Key);
                    Vector2 currentPos = new Vector2(e.GetX(pIndex), e.GetY(pIndex));
                    if (pair.Value.Position != currentPos)
                    {
                        pair.Value.Position = currentPos;
                        OnTouchAction?.Invoke(pair.Value, TouchMotionAction.Move);
                    }
                }
                break;
            }
            }
            return(true);
        }
Exemple #4
0
        private void TouchHandleElement_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            var pointer = e.Pointer;

            if (e.Pointer.PointerDeviceType != PointerDeviceType.Touch)
            {
                return;
            }
            Touch touch = new Touch((int)pointer.PointerId)
            {
                Position = e.GetCurrentPoint(null).Position.ToVector2() * EpxToPxCoefficient,

                UwpPointer = pointer
            };

            System.Diagnostics.Debug.WriteLine(touch.Position);
            _Touches.Add(touch);

            OnTouchAction?.Invoke(touch, TouchMotionAction.Down);
        }