Esempio n. 1
0
        public void ProcessRawEvent(RawInputEventArgs ev)
        {
            var args = (RawTouchEventArgs)ev;

            if (!_pointers.TryGetValue(args.TouchPointId, out var pointer))
            {
                if (args.Type == RawPointerEventType.TouchEnd)
                {
                    return;
                }
                var hit = args.Root.InputHitTest(args.Position);

                _pointers[args.TouchPointId] = pointer = new Pointer(Pointer.GetNextFreeId(),
                                                                     PointerType.Touch, _pointers.Count == 0);
                pointer.Capture(hit);
            }


            var target = pointer.Captured ?? args.Root;

            if (args.Type == RawPointerEventType.TouchBegin)
            {
                target.RaiseEvent(new PointerPressedEventArgs(target, pointer,
                                                              args.Root, args.Position, ev.Timestamp,
                                                              new PointerPointProperties(GetModifiers(args.InputModifiers, true),
                                                                                         PointerUpdateKind.LeftButtonPressed),
                                                              GetKeyModifiers(args.InputModifiers)));
            }

            if (args.Type == RawPointerEventType.TouchEnd)
            {
                _pointers.Remove(args.TouchPointId);
                using (pointer)
                {
                    target.RaiseEvent(new PointerReleasedEventArgs(target, pointer,
                                                                   args.Root, args.Position, ev.Timestamp,
                                                                   new PointerPointProperties(GetModifiers(args.InputModifiers, false),
                                                                                              PointerUpdateKind.LeftButtonReleased),
                                                                   GetKeyModifiers(args.InputModifiers), MouseButton.Left));
                }
            }

            if (args.Type == RawPointerEventType.TouchCancel)
            {
                _pointers.Remove(args.TouchPointId);
                using (pointer)
                    pointer.Capture(null);
            }

            if (args.Type == RawPointerEventType.TouchUpdate)
            {
                var modifiers = GetModifiers(args.InputModifiers, pointer.IsPrimary);
                target.RaiseEvent(new PointerEventArgs(InputElement.PointerMovedEvent, target, pointer, args.Root,
                                                       args.Position, ev.Timestamp,
                                                       new PointerPointProperties(GetModifiers(args.InputModifiers, true), PointerUpdateKind.Other),
                                                       GetKeyModifiers(args.InputModifiers)));
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void ProcessRawEvent(RawInputEventArgs ev)
        {
            if (ev.Handled || _disposed)
            {
                return;
            }
            var args = (RawTouchEventArgs)ev;

            if (!_pointers.TryGetValue(args.TouchPointId, out var pointer))
            {
                if (args.Type == RawPointerEventType.TouchEnd)
                {
                    return;
                }
                var hit = args.Root.InputHitTest(args.Position);

                _pointers[args.TouchPointId] = pointer = new Pointer(Pointer.GetNextFreeId(),
                                                                     PointerType.Touch, _pointers.Count == 0);
                pointer.Capture(hit);
            }


            var target = pointer.Captured ?? args.Root;

            if (args.Type == RawPointerEventType.TouchBegin)
            {
                if (_pointers.Count > 1)
                {
                    _clickCount    = 1;
                    _lastClickTime = 0;
                    _lastClickRect = new Rect();
                }
                else
                {
                    var settings = AvaloniaLocator.Current.GetRequiredService <IPlatformSettings>();

                    if (!_lastClickRect.Contains(args.Position) ||
                        ev.Timestamp - _lastClickTime > settings.TouchDoubleClickTime.TotalMilliseconds)
                    {
                        _clickCount = 0;
                    }
                    ++_clickCount;
                    _lastClickTime = ev.Timestamp;
                    _lastClickRect = new Rect(args.Position, new Size())
                                     .Inflate(new Thickness(settings.TouchDoubleClickSize.Width / 2, settings.TouchDoubleClickSize.Height / 2));
                }

                target.RaiseEvent(new PointerPressedEventArgs(target, pointer,
                                                              args.Root, args.Position, ev.Timestamp,
                                                              new PointerPointProperties(GetModifiers(args.InputModifiers, true),
                                                                                         PointerUpdateKind.LeftButtonPressed),
                                                              GetKeyModifiers(args.InputModifiers), _clickCount));
            }

            if (args.Type == RawPointerEventType.TouchEnd)
            {
                _pointers.Remove(args.TouchPointId);
                using (pointer)
                {
                    target.RaiseEvent(new PointerReleasedEventArgs(target, pointer,
                                                                   args.Root, args.Position, ev.Timestamp,
                                                                   new PointerPointProperties(GetModifiers(args.InputModifiers, false),
                                                                                              PointerUpdateKind.LeftButtonReleased),
                                                                   GetKeyModifiers(args.InputModifiers), MouseButton.Left));
                }
            }

            if (args.Type == RawPointerEventType.TouchCancel)
            {
                _pointers.Remove(args.TouchPointId);
                using (pointer)
                    pointer.Capture(null);
            }

            if (args.Type == RawPointerEventType.TouchUpdate)
            {
                var modifiers = GetModifiers(args.InputModifiers, pointer.IsPrimary);
                target.RaiseEvent(new PointerEventArgs(InputElement.PointerMovedEvent, target, pointer, args.Root,
                                                       args.Position, ev.Timestamp,
                                                       new PointerPointProperties(GetModifiers(args.InputModifiers, true), PointerUpdateKind.Other),
                                                       GetKeyModifiers(args.InputModifiers), args.IntermediatePoints));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Captures mouse input to the specified control.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <remarks>
 /// When an element captures the mouse, it receives mouse input whether the cursor is
 /// within the control's bounds or not. The current mouse capture control is exposed
 /// by the <see cref="Captured"/> property.
 /// </remarks>
 public void Capture(IInputElement control)
 {
     _pointer.Capture(control);
 }
Esempio n. 5
0
 void IPointerDevice.Capture(IInputElement?control) => _lastPointer?.Capture(control);