Beispiel #1
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);
        }
Beispiel #2
0
 public IPointer?TryGetPointer(RawPointerEventArgs ev)
 {
     return(ev is RawTouchEventArgs args &&
            _pointers.TryGetValue(args.TouchPointId, out var pointer)
         ? pointer
         : null);
 }
Beispiel #3
0
        PointerPointProperties CreateProperties(RawPointerEventArgs args)
        {
            var kind = PointerUpdateKind.Other;

            if (args.Type == RawPointerEventType.LeftButtonDown)
            {
                kind = PointerUpdateKind.LeftButtonPressed;
            }
            if (args.Type == RawPointerEventType.MiddleButtonDown)
            {
                kind = PointerUpdateKind.MiddleButtonPressed;
            }
            if (args.Type == RawPointerEventType.RightButtonDown)
            {
                kind = PointerUpdateKind.RightButtonPressed;
            }
            if (args.Type == RawPointerEventType.LeftButtonUp)
            {
                kind = PointerUpdateKind.LeftButtonReleased;
            }
            if (args.Type == RawPointerEventType.MiddleButtonUp)
            {
                kind = PointerUpdateKind.MiddleButtonReleased;
            }
            if (args.Type == RawPointerEventType.RightButtonUp)
            {
                kind = PointerUpdateKind.RightButtonReleased;
            }

            return(new PointerPointProperties(args.InputModifiers, kind));
        }
Beispiel #4
0
        private void ProcessRawEvent(RawPointerEventArgs e)
        {
            Contract.Requires <ArgumentNullException>(e != null);

            var mouse = (MouseDevice)e.Device;

            if (mouse._disposed)
            {
                return;
            }

            Position = e.Root.PointToScreen(e.Position);
            var props        = CreateProperties(e);
            var keyModifiers = KeyModifiersUtils.ConvertToKey(e.InputModifiers);

            switch (e.Type)
            {
            case RawPointerEventType.LeaveWindow:
                LeaveWindow(mouse, e.Timestamp, e.Root, props, keyModifiers);
                break;

            case RawPointerEventType.LeftButtonDown:
            case RawPointerEventType.RightButtonDown:
            case RawPointerEventType.MiddleButtonDown:
                if (ButtonCount(props) > 1)
                {
                    e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                }
                else
                {
                    e.Handled = MouseDown(mouse, e.Timestamp, e.Root, e.Position,
                                          props, keyModifiers);
                }
                break;

            case RawPointerEventType.LeftButtonUp:
            case RawPointerEventType.RightButtonUp:
            case RawPointerEventType.MiddleButtonUp:
                if (ButtonCount(props) != 0)
                {
                    e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                }
                else
                {
                    e.Handled = MouseUp(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                }
                break;

            case RawPointerEventType.Move:
                e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                break;

            case RawPointerEventType.Wheel:
                e.Handled = MouseWheel(mouse, e.Timestamp, e.Root, e.Position, props, ((RawMouseWheelEventArgs)e).Delta, keyModifiers);
                break;
            }
        }
Beispiel #5
0
 protected override bool ChromeHitTest(RawPointerEventArgs e)
 {
     if (_isExtended)
     {
         if (e.Type == RawPointerEventType.LeftButtonDown)
         {
             var visual = (_inputRoot as Window).Renderer.HitTestFirst(e.Position, _inputRoot as Window, x =>
             {
                 if (x is IInputElement ie && !ie.IsHitTestVisible)
                 {
                     return(false);
                 }
                 return(true);
             });
Beispiel #6
0
        private unsafe bool OnMotion(IntPtr w, IntPtr ev, IntPtr userdata)
        {
            var evnt     = (GdkEventMotion *)ev;
            var position = new Point(evnt->x, evnt->y);

            Native.GdkEventRequestMotions(ev);
            var e = new RawPointerEventArgs(
                Gtk3Platform.Mouse,
                evnt->time,
                _inputRoot,
                RawPointerEventType.Move,
                position, GetModifierKeys(evnt->state));

            OnInput(e);

            return(true);
        }
Beispiel #7
0
        private unsafe bool OnButton(IntPtr w, IntPtr ev, IntPtr userdata)
        {
            var evnt = (GdkEventButton *)ev;
            var e    = new RawPointerEventArgs(
                Gtk3Platform.Mouse,
                evnt->time,
                _inputRoot,
                evnt->type == GdkEventType.ButtonRelease
                    ? evnt->button == 1
                        ? RawPointerEventType.LeftButtonUp
                        : evnt->button == 3 ? RawPointerEventType.RightButtonUp : RawPointerEventType.MiddleButtonUp
                    : evnt->button == 1
                        ? RawPointerEventType.LeftButtonDown
                        : evnt->button == 3 ? RawPointerEventType.RightButtonDown : RawPointerEventType.MiddleButtonDown,
                new Point(evnt->x, evnt->y), GetModifierKeys(evnt->state));

            OnInput(e);
            return(true);
        }
Beispiel #8
0
        public void RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta)
        {
            Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1);

            switch (type)
            {
            case AvnRawMouseEventType.Wheel:
                Input?.Invoke(new RawMouseWheelEventArgs(_mouse, timeStamp, _inputRoot, point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (RawInputModifiers)modifiers));
                break;

            default:
                var e = new RawPointerEventArgs(_mouse, timeStamp, _inputRoot, (RawPointerEventType)type, point.ToAvaloniaPoint(), (RawInputModifiers)modifiers);

                if (!ChromeHitTest(e))
                {
                    Input?.Invoke(e);
                }
                break;
            }
        }
Beispiel #9
0
 protected virtual bool ChromeHitTest(RawPointerEventArgs e)
 {
     return(false);
 }
Beispiel #10
0
        protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            bool unicode = UnmanagedMethods.IsWindowUnicode(hWnd);

            const double wheelDelta = 120.0;
            uint         timestamp  = unchecked ((uint)UnmanagedMethods.GetMessageTime());

            RawInputEventArgs e = null;

            WindowsMouseDevice.Instance.CurrentWindow = this;

            switch ((UnmanagedMethods.WindowsMessage)msg)
            {
            case UnmanagedMethods.WindowsMessage.WM_ACTIVATE:
                var wa = (UnmanagedMethods.WindowActivate)(ToInt32(wParam) & 0xffff);

                switch (wa)
                {
                case UnmanagedMethods.WindowActivate.WA_ACTIVE:
                case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE:
                    Activated?.Invoke();
                    break;

                case UnmanagedMethods.WindowActivate.WA_INACTIVE:
                    Deactivated?.Invoke();
                    break;
                }

                return(IntPtr.Zero);

            case WindowsMessage.WM_NCCALCSIZE:
                if (ToInt32(wParam) == 1 && !_decorated)
                {
                    return(IntPtr.Zero);
                }
                break;

            case UnmanagedMethods.WindowsMessage.WM_CLOSE:
                bool?preventClosing = Closing?.Invoke();
                if (preventClosing == true)
                {
                    return(IntPtr.Zero);
                }
                break;

            case UnmanagedMethods.WindowsMessage.WM_DESTROY:
                //Window doesn't exist anymore
                _hwnd = IntPtr.Zero;
                //Remove root reference to this class, so unmanaged delegate can be collected
                s_instances.Remove(this);
                Closed?.Invoke();
                if (_parent != null)
                {
                    _parent._disabledBy.Remove(this);
                    _parent.UpdateEnabled();
                }
                //Free other resources
                Dispose();
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_DPICHANGED:
                var dpi            = ToInt32(wParam) & 0xffff;
                var newDisplayRect = Marshal.PtrToStructure <UnmanagedMethods.RECT>(lParam);
                _scaling = dpi / 96.0;
                ScalingChanged?.Invoke(_scaling);
                SetWindowPos(hWnd,
                             IntPtr.Zero,
                             newDisplayRect.left,
                             newDisplayRect.top,
                             newDisplayRect.right - newDisplayRect.left,
                             newDisplayRect.bottom - newDisplayRect.top,
                             SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE);
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_KEYDOWN:
            case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN:
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    RawKeyEventType.KeyDown,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_KEYUP:
            case UnmanagedMethods.WindowsMessage.WM_SYSKEYUP:
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    RawKeyEventType.KeyUp,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_CHAR:
                // Ignore control chars
                if (ToInt32(wParam) >= 32)
                {
                    e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp,
                                                  new string((char)ToInt32(wParam), 1));
                }

                break;

            case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_MBUTTONDOWN:
                if (ShouldIgnoreTouchEmulatedMessage())
                {
                    break;
                }
                e = new RawPointerEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN
                            ? RawPointerEventType.LeftButtonDown
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN
                                ? RawPointerEventType.RightButtonDown
                                : RawPointerEventType.MiddleButtonDown,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP:
            case UnmanagedMethods.WindowsMessage.WM_RBUTTONUP:
            case UnmanagedMethods.WindowsMessage.WM_MBUTTONUP:
                if (ShouldIgnoreTouchEmulatedMessage())
                {
                    break;
                }
                e = new RawPointerEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONUP
                            ? RawPointerEventType.LeftButtonUp
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONUP
                                ? RawPointerEventType.RightButtonUp
                                : RawPointerEventType.MiddleButtonUp,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE:
                if (ShouldIgnoreTouchEmulatedMessage())
                {
                    break;
                }
                if (!_trackingMouse)
                {
                    var tm = new UnmanagedMethods.TRACKMOUSEEVENT
                    {
                        cbSize      = Marshal.SizeOf <UnmanagedMethods.TRACKMOUSEEVENT>(),
                        dwFlags     = 2,
                        hwndTrack   = _hwnd,
                        dwHoverTime = 0,
                    };

                    UnmanagedMethods.TrackMouseEvent(ref tm);
                }

                e = new RawPointerEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    RawPointerEventType.Move,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));

                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEWHEEL:
                e = new RawMouseWheelEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    PointToClient(PointFromLParam(lParam)),
                    new Vector(0, (ToInt32(wParam) >> 16) / wheelDelta), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEHWHEEL:
                e = new RawMouseWheelEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    PointToClient(PointFromLParam(lParam)),
                    new Vector(-(ToInt32(wParam) >> 16) / wheelDelta, 0), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE:
                _trackingMouse = false;
                e = new RawPointerEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    RawPointerEventType.LeaveWindow,
                    new Point(), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_NCMBUTTONDOWN:
                e = new RawPointerEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN
                            ? RawPointerEventType.NonClientLeftButtonDown
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN
                                ? RawPointerEventType.RightButtonDown
                                : RawPointerEventType.MiddleButtonDown,
                    new Point(0, 0), GetMouseModifiers(wParam));
                break;

            case WindowsMessage.WM_TOUCH:
                var touchInputs = new TOUCHINPUT[wParam.ToInt32()];
                if (GetTouchInputInfo(lParam, (uint)wParam.ToInt32(), touchInputs, Marshal.SizeOf <TOUCHINPUT>()))
                {
                    foreach (var touchInput in touchInputs)
                    {
                        var pt = new POINT {
                            X = touchInput.X / 100, Y = touchInput.Y / 100
                        };
                        UnmanagedMethods.ScreenToClient(_hwnd, ref pt);
                        Input?.Invoke(new RawTouchEventArgs(_touchDevice, touchInput.Time,
                                                            _owner,
                                                            touchInput.Flags.HasFlag(TouchInputFlags.TOUCHEVENTF_UP) ?
                                                            RawPointerEventType.TouchEnd :
                                                            touchInput.Flags.HasFlag(TouchInputFlags.TOUCHEVENTF_DOWN) ?
                                                            RawPointerEventType.TouchBegin :
                                                            RawPointerEventType.TouchUpdate,
                                                            new Point(pt.X, pt.Y),
                                                            WindowsKeyboardDevice.Instance.Modifiers,
                                                            touchInput.Id));
                    }
                    CloseTouchInputHandle(lParam);
                    return(IntPtr.Zero);
                }

                break;

            case WindowsMessage.WM_NCPAINT:
                if (!_decorated)
                {
                    return(IntPtr.Zero);
                }
                break;

            case WindowsMessage.WM_NCACTIVATE:
                if (!_decorated)
                {
                    return(new IntPtr(1));
                }
                break;

            case UnmanagedMethods.WindowsMessage.WM_PAINT:
                UnmanagedMethods.PAINTSTRUCT ps;
                if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero)
                {
                    var f = Scaling;
                    var r = ps.rcPaint;
                    Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f));
                    UnmanagedMethods.EndPaint(_hwnd, ref ps);
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_SIZE:
                var size = (UnmanagedMethods.SizeCommand)wParam;

                if (Resized != null &&
                    (size == UnmanagedMethods.SizeCommand.Restored ||
                     size == UnmanagedMethods.SizeCommand.Maximized))
                {
                    var clientSize = new Size(ToInt32(lParam) & 0xffff, ToInt32(lParam) >> 16);
                    Resized(clientSize / Scaling);
                }

                var windowState = size == SizeCommand.Maximized ? WindowState.Maximized
                        : (size == SizeCommand.Minimized ? WindowState.Minimized : WindowState.Normal);

                if (windowState != _lastWindowState)
                {
                    _lastWindowState = windowState;
                    WindowStateChanged?.Invoke(windowState);
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_MOVE:
                PositionChanged?.Invoke(new PixelPoint((short)(ToInt32(lParam) & 0xffff), (short)(ToInt32(lParam) >> 16)));
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_GETMINMAXINFO:

                MINMAXINFO mmi = Marshal.PtrToStructure <UnmanagedMethods.MINMAXINFO>(lParam);

                if (_minSize.Width > 0)
                {
                    mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
                }

                if (_minSize.Height > 0)
                {
                    mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
                }

                if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0)
                {
                    mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
                }

                if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0)
                {
                    mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
                }

                Marshal.StructureToPtr(mmi, lParam, true);
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_DISPLAYCHANGE:
                (Screen as ScreenImpl)?.InvalidateScreensCache();
                return(IntPtr.Zero);
            }

#if USE_MANAGED_DRAG
            if (_managedDrag.PreprocessInputEvent(ref e))
            {
                return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam));
            }
#endif

            if (e != null && Input != null)
            {
                Input(e);

                if (e.Handled)
                {
                    return(IntPtr.Zero);
                }
            }

            return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam));
        }
        private void ProcessMouseEvents(RawPointerEventArgs e)
        {
            if (!_initialInputModifiers.HasValue)
            {
                _initialInputModifiers = e.InputModifiers & MOUSE_INPUTMODIFIERS;
            }


            void CheckDraggingAccepted(RawInputModifiers changedMouseButton)
            {
                if (_initialInputModifiers.Value.HasFlag(changedMouseButton))
                {
                    var result = RaiseEventAndUpdateCursor(RawDragEventType.Drop, e.Root, e.Position, e.InputModifiers);
                    UpdateCursor(null, DragDropEffects.None);
                    _result.OnNext(result);
                }
                else
                {
                    CancelDragging();
                }
                e.Handled = true;
            }

            switch (e.Type)
            {
            case RawPointerEventType.LeftButtonDown:
            case RawPointerEventType.RightButtonDown:
            case RawPointerEventType.MiddleButtonDown:
            case RawPointerEventType.NonClientLeftButtonDown:
                CancelDragging();
                e.Handled = true;
                return;

            case RawPointerEventType.LeaveWindow:
                RaiseEventAndUpdateCursor(RawDragEventType.DragLeave, e.Root, e.Position, e.InputModifiers); break;

            case RawPointerEventType.LeftButtonUp:
                CheckDraggingAccepted(RawInputModifiers.LeftMouseButton); break;

            case RawPointerEventType.MiddleButtonUp:
                CheckDraggingAccepted(RawInputModifiers.MiddleMouseButton); break;

            case RawPointerEventType.RightButtonUp:
                CheckDraggingAccepted(RawInputModifiers.RightMouseButton); break;

            case RawPointerEventType.Move:
                var mods = e.InputModifiers & MOUSE_INPUTMODIFIERS;
                if (_initialInputModifiers.Value != mods)
                {
                    CancelDragging();
                    e.Handled = true;
                    return;
                }

                if (e.Root != _lastRoot)
                {
                    if (_lastRoot != null)
                    {
                        RaiseEventAndUpdateCursor(RawDragEventType.DragLeave, _lastRoot, _lastRoot.PointToClient(e.Root.PointToScreen(e.Position)), e.InputModifiers);
                    }
                    RaiseEventAndUpdateCursor(RawDragEventType.DragEnter, e.Root, e.Position, e.InputModifiers);
                }
                else
                {
                    RaiseEventAndUpdateCursor(RawDragEventType.DragOver, e.Root, e.Position, e.InputModifiers);
                }
                break;
            }
        }
        public bool?DispatchTouchEvent(MotionEvent e, out bool callBase)
        {
            if (!HandleEvents)
            {
                callBase = true;
                return(null);
            }

            RawPointerEventType?mouseEventType = null;
            var eventTime = DateTime.Now;

            //Basic touch support
            switch (e.Action)
            {
            case MotionEventActions.Move:
                //may be bot flood the evnt system with too many event especially on not so powerfull mobile devices
                if ((eventTime - _lastTouchMoveEventTime).TotalMilliseconds > 10)
                {
                    mouseEventType = RawPointerEventType.Move;
                }
                break;

            case MotionEventActions.Down:
                mouseEventType = RawPointerEventType.LeftButtonDown;

                break;

            case MotionEventActions.Up:
                mouseEventType = RawPointerEventType.LeftButtonUp;
                break;
            }

            if (mouseEventType != null)
            {
                //if point is in view otherwise it's possible avalonia not to find the proper window to dispatch the event
                _point = _getPointFunc(e);

                double x = _view.View.GetX();
                double y = _view.View.GetY();
                double r = x + _view.View.Width;
                double b = y + _view.View.Height;

                if (x <= _point.X && r >= _point.X && y <= _point.Y && b >= _point.Y)
                {
                    var inputRoot   = _getInputRoot();
                    var mouseDevice = Avalonia.Android.Platform.Input.AndroidMouseDevice.Instance;

                    //in order the controls to work in a predictable way
                    //we need to generate mouse move before first mouse down event
                    //as this is the way buttons are working every time
                    //otherwise there is a problem sometimes
                    if (mouseEventType == RawPointerEventType.LeftButtonDown)
                    {
                        var me = new RawPointerEventArgs(mouseDevice, (uint)eventTime.Ticks, inputRoot,
                                                         RawPointerEventType.Move, _point, RawInputModifiers.None);
                        _view.Input(me);
                    }

                    var mouseEvent = new RawPointerEventArgs(mouseDevice, (uint)eventTime.Ticks, inputRoot,
                                                             mouseEventType.Value, _point, RawInputModifiers.LeftMouseButton);
                    _view.Input(mouseEvent);

                    if (e.Action == MotionEventActions.Move && mouseDevice.Captured == null)
                    {
                        if (_lastTouchMovePoint != null)
                        {
                            //raise mouse scroll event so the scrollers
                            //are moving with the cursor
                            double vectorX = _point.X - _lastTouchMovePoint.Value.X;
                            double vectorY = _point.Y - _lastTouchMovePoint.Value.Y;
                            //based on test correction of 0.02 is working perfect
                            double correction      = 0.02;
                            var    ps              = AndroidPlatform.Instance.LayoutScalingFactor;
                            var    mouseWheelEvent = new RawMouseWheelEventArgs(
                                mouseDevice,
                                (uint)eventTime.Ticks,
                                inputRoot,
                                _point,
                                new Vector(vectorX * correction / ps, vectorY * correction / ps), RawInputModifiers.LeftMouseButton);
                            _view.Input(mouseWheelEvent);
                        }
                        _lastTouchMovePoint     = _point;
                        _lastTouchMoveEventTime = eventTime;
                    }
                    else if (e.Action == MotionEventActions.Down)
                    {
                        _lastTouchMovePoint = _point;
                    }
                    else
                    {
                        _lastTouchMovePoint = null;
                    }
                }
            }

            callBase = true;
            //if return false events for move and up are not received!!!
            return(e.Action != MotionEventActions.Up);
        }
Beispiel #13
0
        private void ProcessRawEvent(RawPointerEventArgs e)
        {
            e = e ?? throw new ArgumentNullException(nameof(e));

            var mouse = (MouseDevice)e.Device;

            if (mouse._disposed)
            {
                return;
            }

            var props        = CreateProperties(e);
            var keyModifiers = e.InputModifiers.ToKeyModifiers();

            switch (e.Type)
            {
            case RawPointerEventType.LeaveWindow:
            case RawPointerEventType.NonClientLeftButtonDown:
                LeaveWindow();
                break;

            case RawPointerEventType.LeftButtonDown:
            case RawPointerEventType.RightButtonDown:
            case RawPointerEventType.MiddleButtonDown:
            case RawPointerEventType.XButton1Down:
            case RawPointerEventType.XButton2Down:
                if (ButtonCount(props) > 1)
                {
                    e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.IntermediatePoints, e.InputHitTestResult);
                }
                else
                {
                    e.Handled = MouseDown(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult);
                }
                break;

            case RawPointerEventType.LeftButtonUp:
            case RawPointerEventType.RightButtonUp:
            case RawPointerEventType.MiddleButtonUp:
            case RawPointerEventType.XButton1Up:
            case RawPointerEventType.XButton2Up:
                if (ButtonCount(props) != 0)
                {
                    e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.IntermediatePoints, e.InputHitTestResult);
                }
                else
                {
                    e.Handled = MouseUp(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult);
                }
                break;

            case RawPointerEventType.Move:
                e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.IntermediatePoints, e.InputHitTestResult);
                break;

            case RawPointerEventType.Wheel:
                e.Handled = MouseWheel(mouse, e.Timestamp, e.Root, e.Position, props, ((RawMouseWheelEventArgs)e).Delta, keyModifiers, e.InputHitTestResult);
                break;

            case RawPointerEventType.Magnify:
                e.Handled = GestureMagnify(mouse, e.Timestamp, e.Root, e.Position, props, ((RawPointerGestureEventArgs)e).Delta, keyModifiers, e.InputHitTestResult);
                break;

            case RawPointerEventType.Rotate:
                e.Handled = GestureRotate(mouse, e.Timestamp, e.Root, e.Position, props, ((RawPointerGestureEventArgs)e).Delta, keyModifiers, e.InputHitTestResult);
                break;

            case RawPointerEventType.Swipe:
                e.Handled = GestureSwipe(mouse, e.Timestamp, e.Root, e.Position, props, ((RawPointerGestureEventArgs)e).Delta, keyModifiers, e.InputHitTestResult);
                break;
            }
        }
Beispiel #14
0
 public IPointer?TryGetPointer(RawPointerEventArgs ev)
 {
     return(_pointer);
 }
Beispiel #15
0
 PointerPointProperties CreateProperties(RawPointerEventArgs args)
 {
     return(new PointerPointProperties(args.InputModifiers, args.Type.ToUpdateKind()));
 }
Beispiel #16
0
 public IPointer?TryGetPointer(RawPointerEventArgs ev)
 {
     return(_pointers.TryGetValue(ev.RawPointerId, out var pointer)
         ? pointer
         : null);
 }
 public IPointer?TryGetPointer(RawPointerEventArgs ev) => _ev.Pointer;