Example #1
0
        int ButtonCount(PointerPointProperties props)
        {
            var rv = 0;

            if (props.IsLeftButtonPressed)
            {
                rv++;
            }
            if (props.IsMiddleButtonPressed)
            {
                rv++;
            }
            if (props.IsRightButtonPressed)
            {
                rv++;
            }
            if (props.IsXButton1Pressed)
            {
                rv++;
            }
            if (props.IsXButton2Pressed)
            {
                rv++;
            }
            return(rv);
        }
Example #2
0
        private bool MouseWheel(IMouseDevice device, ulong timestamp, IInputRoot root, Point p,
                                PointerPointProperties props,
                                Vector delta, KeyModifiers inputModifiers, IInputElement?hitTest)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            var source = _pointer.Captured ?? hitTest;

            // KeyModifiers.Shift should scroll in horizontal direction. This does not work on every platform.
            // If Shift-Key is pressed and X is close to 0 we swap the Vector.
            if (inputModifiers == KeyModifiers.Shift && MathUtilities.IsZero(delta.X))
            {
                delta = new Vector(delta.Y, delta.X);
            }

            if (source is not null)
            {
                var e = new PointerWheelEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta);

                source?.RaiseEvent(e);
                return(e.Handled);
            }

            return(false);
        }
Example #3
0
        PointerPointProperties CreateProperties(RawPointerEventArgs args)
        {
            var rv = new PointerPointProperties(args.InputModifiers);

            if (args.Type == RawPointerEventType.LeftButtonDown)
            {
                rv.IsLeftButtonPressed = true;
            }
            if (args.Type == RawPointerEventType.MiddleButtonDown)
            {
                rv.IsMiddleButtonPressed = true;
            }
            if (args.Type == RawPointerEventType.RightButtonDown)
            {
                rv.IsRightButtonPressed = true;
            }
            if (args.Type == RawPointerEventType.LeftButtonUp)
            {
                rv.IsLeftButtonPressed = false;
            }
            if (args.Type == RawPointerEventType.MiddleButtonUp)
            {
                rv.IsMiddleButtonPressed = false;
            }
            if (args.Type == RawPointerEventType.RightButtonUp)
            {
                rv.IsRightButtonPressed = false;
            }
            return(rv);
        }
 public PointerWheelEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual,
                              Point rootVisualPosition,
                              PointerPointProperties properties, InputModifiers modifiers, Vector delta)
     : base(InputElement.PointerWheelChangedEvent, source, pointer, rootVisual, rootVisualPosition, properties, modifiers)
 {
     Delta = delta;
 }
Example #5
0
 public PointerDeltaEventArgs(RoutedEvent routedEvent, IInteractive?source,
                              IPointer pointer, IVisual rootVisual, Point rootVisualPosition, ulong timestamp,
                              PointerPointProperties properties, KeyModifiers modifiers, Vector delta)
     : base(routedEvent, source, pointer, rootVisual, rootVisualPosition,
            timestamp, properties, modifiers)
 {
     Delta = delta;
 }
 public PointerEventArgs(RoutedEvent routedEvent,
                         IInteractive?source,
                         IPointer pointer,
                         IVisual?rootVisual, Point rootVisualPosition,
                         ulong timestamp,
                         PointerPointProperties properties,
                         KeyModifiers modifiers,
                         Lazy <IReadOnlyList <RawPointerPoint>?>?previousPoints)
     : this(routedEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers)
 {
     _previousPoints = previousPoints;
 }
Example #7
0
 public PointerEventArgs(RoutedEvent routedEvent,
                         IInteractive source,
                         IPointer pointer,
                         IVisual rootVisual, Point rootVisualPosition, PointerPointProperties properties,
                         InputModifiers modifiers)
     : base(routedEvent)
 {
     Source              = source;
     _rootVisual         = rootVisual;
     _rootVisualPosition = rootVisualPosition;
     _properties         = properties;
     Pointer             = pointer;
     InputModifiers      = modifiers;
 }
Example #8
0
        internal PointerPointProperties(PointerPointProperties basedOn, RawPointerPoint rawPoint)
        {
            IsLeftButtonPressed   = basedOn.IsLeftButtonPressed;
            IsMiddleButtonPressed = basedOn.IsMiddleButtonPressed;
            IsRightButtonPressed  = basedOn.IsRightButtonPressed;
            IsXButton1Pressed     = basedOn.IsXButton1Pressed;
            IsXButton2Pressed     = basedOn.IsXButton2Pressed;
            IsInverted            = basedOn.IsInverted;
            IsEraser = basedOn.IsEraser;
            IsBarrelButtonPressed = basedOn.IsBarrelButtonPressed;

            Twist    = rawPoint.Twist;
            Pressure = rawPoint.Pressure;
            XTilt    = rawPoint.XTilt;
            YTilt    = rawPoint.YTilt;
        }
Example #9
0
 public PointerEventArgs(RoutedEvent routedEvent,
                         IInteractive?source,
                         IPointer pointer,
                         IVisual?rootVisual, Point rootVisualPosition,
                         ulong timestamp,
                         PointerPointProperties properties,
                         KeyModifiers modifiers)
     : base(routedEvent)
 {
     Source              = source;
     _rootVisual         = rootVisual;
     _rootVisualPosition = rootVisualPosition;
     _properties         = properties;
     Pointer             = pointer;
     Timestamp           = timestamp;
     KeyModifiers        = modifiers;
 }
Example #10
0
        private bool GestureSwipe(IMouseDevice device, ulong timestamp, IInputRoot root, Point p,
                                  PointerPointProperties props, Vector delta, KeyModifiers inputModifiers, IInputElement?hitTest)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            var source = _pointer.Captured ?? hitTest;

            if (source != null)
            {
                var e = new PointerDeltaEventArgs(Gestures.PointerTouchPadGestureSwipeEvent, source,
                                                  _pointer, root, p, timestamp, props, inputModifiers, delta);

                source?.RaiseEvent(e);
                return(e.Handled);
            }

            return(false);
        }
Example #11
0
        private bool MouseWheel(IMouseDevice device, ulong timestamp, IInputRoot root, Point p,
                                PointerPointProperties props,
                                Vector delta, KeyModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            var hit = HitTest(root, p);

            if (hit != null)
            {
                var source = GetSource(hit);
                var e      = new PointerWheelEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta);

                source?.RaiseEvent(e);
                return(e.Handled);
            }

            return(false);
        }
Example #12
0
        private bool MouseMove(IMouseDevice device, ulong timestamp, IInputRoot root, Point p,
                               PointerPointProperties properties, KeyModifiers inputModifiers, Lazy <IReadOnlyList <RawPointerPoint>?>?intermediatePoints,
                               IInputElement?hitTest)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            var source = _pointer.Captured ?? hitTest;

            if (source is object)
            {
                var e = new PointerEventArgs(InputElement.PointerMovedEvent, source, _pointer, root,
                                             p, timestamp, properties, inputModifiers, intermediatePoints);

                source.RaiseEvent(e);
                return(e.Handled);
            }

            return(false);
        }
Example #13
0
        private bool MouseDown(IMouseDevice device, ulong timestamp, IInputElement root, Point p,
                               PointerPointProperties properties,
                               KeyModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            var hit = HitTest(root, p);

            if (hit != null)
            {
                _pointer.Capture(hit);
                var source = GetSource(hit);
                if (source != null)
                {
                    var settings        = AvaloniaLocator.Current.GetService <IPlatformSettings>();
                    var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds;

                    if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
                    {
                        _clickCount = 0;
                    }

                    ++_clickCount;
                    _lastClickTime = timestamp;
                    _lastClickRect = new Rect(p, new Size())
                                     .Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2));
                    _lastMouseDownButton = properties.PointerUpdateKind.GetMouseButton();
                    var e = new PointerPressedEventArgs(source, _pointer, root, p, timestamp, properties, inputModifiers, _clickCount);
                    source.RaiseEvent(e);
                    return(e.Handled);
                }
            }

            return(false);
        }
Example #14
0
        private bool MouseDown(IMouseDevice device, ulong timestamp, IInputElement root, Point p,
                               PointerPointProperties properties,
                               KeyModifiers inputModifiers, IInputElement?hitTest)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            var source = _pointer.Captured ?? root.InputHitTest(p);

            if (source != null)
            {
                _pointer.Capture(source);
                if (source != null)
                {
                    var settings        = AvaloniaLocator.Current.GetService <IPlatformSettings>();
                    var doubleClickTime = settings?.DoubleClickTime.TotalMilliseconds ?? 500;
                    var doubleClickSize = settings?.DoubleClickSize ?? new Size(4, 4);

                    if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
                    {
                        _clickCount = 0;
                    }

                    ++_clickCount;
                    _lastClickTime = timestamp;
                    _lastClickRect = new Rect(p, new Size())
                                     .Inflate(new Thickness(doubleClickSize.Width / 2, doubleClickSize.Height / 2));
                    _lastMouseDownButton = properties.PointerUpdateKind.GetMouseButton();
                    var e = new PointerPressedEventArgs(source, _pointer, root, p, timestamp, properties, inputModifiers, _clickCount);
                    source.RaiseEvent(e);
                    return(e.Handled);
                }
            }

            return(false);
        }
Example #15
0
 public PointerPoint(IPointer pointer, Point position, PointerPointProperties properties)
 {
     Pointer    = pointer;
     Position   = position;
     Properties = properties;
 }
Example #16
0
 PointerEventArgs CreateSimpleEvent(RoutedEvent ev, ulong timestamp, IInteractive source,
                                    PointerPointProperties properties,
                                    KeyModifiers inputModifiers)
 {
     return(new PointerEventArgs(ev, source, _pointer, null, default,
Example #17
0
        private bool MouseUp(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, PointerPointProperties props,
                             KeyModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            var hit = HitTest(root, p);

            if (hit != null)
            {
                var source = GetSource(hit);
                var e      = new PointerReleasedEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers,
                                                          _lastMouseDownButton);

                source?.RaiseEvent(e);
                _pointer.Capture(null);
                return(e.Handled);
            }

            return(false);
        }
Example #18
0
        private void LeaveWindow(IMouseDevice device, ulong timestamp, IInputRoot root, PointerPointProperties properties,
                                 KeyModifiers inputModifiers)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            ClearPointerOver(this, timestamp, root, properties, inputModifiers);
        }
Example #19
0
        private bool MouseMove(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, PointerPointProperties properties,
                               KeyModifiers inputModifiers)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            IInputElement?source;

            if (_pointer.Captured == null)
            {
                source = SetPointerOver(this, timestamp, root, p, properties, inputModifiers);
            }
            else
            {
                SetPointerOver(this, timestamp, root, _pointer.Captured, properties, inputModifiers);
                source = _pointer.Captured;
            }

            if (source is object)
            {
                var e = new PointerEventArgs(InputElement.PointerMovedEvent, source, _pointer, root,
                                             p, timestamp, properties, inputModifiers);

                source.RaiseEvent(e);
                return(e.Handled);
            }

            return(false);
        }
Example #20
0
        private bool MouseMove(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, PointerPointProperties properties,
                               KeyModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            IInputElement source;

            if (_pointer.Captured == null)
            {
                source = SetPointerOver(this, timestamp, root, p, properties, inputModifiers);
            }
            else
            {
                SetPointerOver(this, timestamp, root, _pointer.Captured, properties, inputModifiers);
                source = _pointer.Captured;
            }

            var e = new PointerEventArgs(InputElement.PointerMovedEvent, source, _pointer, root,
                                         p, timestamp, properties, inputModifiers);

            source?.RaiseEvent(e);
            return(e.Handled);
        }
Example #21
0
        private void LeaveWindow(IMouseDevice device, ulong timestamp, IInputRoot root, PointerPointProperties properties,
                                 KeyModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            ClearPointerOver(this, timestamp, root, properties, inputModifiers);
        }
Example #22
0
        private bool MouseUp(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, PointerPointProperties props,
                             KeyModifiers inputModifiers, IInputElement?hitTest)
        {
            device = device ?? throw new ArgumentNullException(nameof(device));
            root   = root ?? throw new ArgumentNullException(nameof(root));

            var source = _pointer.Captured ?? hitTest;

            if (source is not null)
            {
                var e = new PointerReleasedEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers,
                                                     _lastMouseDownButton);

                source?.RaiseEvent(e);
                _pointer.Capture(null);
                return(e.Handled);
            }

            return(false);
        }