示例#1
0
 PaintMode GetPaintModeForTool(MotionEventToolType toolType, PaintMode defaultMode)
 {
     if (toolType == MotionEventToolType.Eraser)
     {
         return(PaintMode.Erase);
     }
     return(defaultMode);
 }
        private static SKMouseButton GetButton(MotionEvent evt, MotionEventToolType toolType)
        {
            var button = SKMouseButton.Left;

            if (toolType == MotionEventToolType.Eraser)
            {
                button = SKMouseButton.Middle;
            }
            else if (evt.ButtonState.HasFlag(MotionEventButtonState.StylusSecondary))
            {
                button = SKMouseButton.Right;
            }

            return(button);
        }
        public static PointerDeviceType ToPointerDeviceType(this MotionEventToolType nativeType)
        {
            switch (nativeType)
            {
            case Android.Views.MotionEventToolType.Eraser:
            case Android.Views.MotionEventToolType.Stylus:
                return(PointerDeviceType.Pen);

            case Android.Views.MotionEventToolType.Finger:
                return(PointerDeviceType.Touch);

            case Android.Views.MotionEventToolType.Mouse:
                return(PointerDeviceType.Mouse);

            case Android.Views.MotionEventToolType.Unknown:                     // used by Xamarin.UITest
            default:
                return(default(PointerDeviceType));
            }
        }
示例#4
0
        private PointerPointProperties GetProperties(MotionEventToolType type, MotionEventActions action, MotionEventButtonState buttons)
        {
            var props = new PointerPointProperties
            {
                IsPrimary = true,
                IsInRange = Pointer.IsInRange
            };

            var isDown  = action == /* 0 = */ MotionEventActions.Down || action.HasFlag(MotionEventActions.PointerDown);
            var isUp    = action.HasFlag(MotionEventActions.Up) || action.HasFlag(MotionEventActions.PointerUp);
            var updates = _none;

            switch (type)
            {
            case MotionEventToolType.Finger:
            case MotionEventToolType.Unknown:                     // used by Xamarin.UITest
                props.IsLeftButtonPressed = Pointer.IsInContact;
                updates = isDown ? _fingerDownUpdates : isUp ? _fingerUpUpdates : _none;
                // Pressure = .5f => Keeps default as UWP returns .5 for fingers.
                break;

            case MotionEventToolType.Mouse:
                props.IsLeftButtonPressed   = buttons.HasFlag(MotionEventButtonState.Primary);
                props.IsMiddleButtonPressed = buttons.HasFlag(MotionEventButtonState.Tertiary);
                props.IsRightButtonPressed  = buttons.HasFlag(MotionEventButtonState.Secondary);
                updates = isDown ? _mouseDownUpdates : isUp ? _mouseUpUpdates : _none;
                // Pressure = .5f => Keeps default as UWP returns .5 for Mouse no matter is button is pressed or not (Android return 1.0 while pressing a button, but 0 otherwise).
                break;

            // Note: On UWP, if you touch screen while already holding the barrel button, you will get a right + barrel,
            //		 ** BUT ** if you touch screen and THEN press the barrel button props will be left + barrel until released.
            //		 On Android this distinction seems to be flagged by the "1101 ****" action flag (i.e. "StylusWithBarrel***" actions),
            //		 so here we set the Is<Left|Right>ButtonPressed based on the action and we don't try to link it to the barrel button state.
            case MotionEventToolType.Stylus when action == StylusWithBarrelDown:
            case MotionEventToolType.Stylus when action == StylusWithBarrelMove:
            case MotionEventToolType.Stylus when action == StylusWithBarrelUp:
                // Note: We still validate the "IsButtonPressed(StylusPrimary)" as the user might release the button while pressed.
                //		 In that case we will still receive moves and up with the "StylusWithBarrel***" actions.
                props.IsBarrelButtonPressed = buttons.HasFlag(MotionEventButtonState.StylusPrimary);
                props.IsRightButtonPressed  = Pointer.IsInContact;
                props.Pressure = Math.Min(1f, _nativeEvent.GetPressure(_pointerIndex));                         // Might exceed 1.0 on Android
                break;

            case MotionEventToolType.Stylus:
                props.IsBarrelButtonPressed = buttons.HasFlag(MotionEventButtonState.StylusPrimary);
                props.IsLeftButtonPressed   = Pointer.IsInContact;
                props.Pressure = Math.Min(1f, _nativeEvent.GetPressure(_pointerIndex));                         // Might exceed 1.0 on Android
                break;

            case MotionEventToolType.Eraser:
                props.IsEraser = true;
                props.Pressure = Math.Min(1f, _nativeEvent.GetPressure(_pointerIndex));                         // Might exceed 1.0 on Android
                break;

            default:
                break;
            }

            if (updates.TryGetValue(_nativeEvent.ActionButton, out var update))
            {
                props.PointerUpdateKind = update;
            }

            return(props);
        }
示例#5
0
			PaintMode GetPaintModeForTool (MotionEventToolType toolType, PaintMode defaultMode)
			{
				if (toolType == MotionEventToolType.Eraser) {
					return PaintMode.Erase;
				}
				return defaultMode;
			}
 private static SKTouchDeviceType GetDeviceType(MotionEventToolType toolType) =>
 toolType switch
 {