Esempio n. 1
0
 public MouseDevice(Pointer?pointer = null)
 {
     _pointer = pointer ?? new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true);
 }
Esempio n. 2
0
        public void ProcessRawEvent(RawInputEventArgs ev)
        {
            if (_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)));
            }
        }