Beispiel #1
0
        private void OnTargetPanel_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (m_painter == null)
            {
                return;
            }

            // Set focus on target
            if (m_dummyButtonForFocus != null)
            {
                m_dummyButtonForFocus.Focus(FocusState.Programmatic);
            }

            // Track mouse/pointer state
            PointerPoint           currentPoint    = e.GetCurrentPoint(m_painter.TargetPanel);
            PointerPointProperties pointProperties = currentPoint.Properties;

            if (pointProperties.IsPrimary)
            {
                m_stateMouseOrPointer.NotifyButtonStates(
                    pointProperties.IsLeftButtonPressed,
                    pointProperties.IsMiddleButtonPressed,
                    pointProperties.IsRightButtonPressed,
                    pointProperties.IsXButton1Pressed,
                    pointProperties.IsXButton2Pressed);
            }
            m_lastDragPoint = currentPoint;

            // Needed here because we loose focus again by default on left mouse button
            e.Handled = true;
        }
Beispiel #2
0
        internal PointerRoutedEventArgs(MotionEvent nativeEvent, int pointerIndex, UIElement originalSource, UIElement receiver) : this()
        {
            _nativeEvent  = nativeEvent;
            _pointerIndex = pointerIndex;
            _receiver     = receiver;

            // Here we assume that usually pointerId is 'PointerIndexShift' bits long (8 bits / 255 ids),
            // and that usually the deviceId is [0, something_not_too_big_hopefully_less_than_0x00ffffff].
            // If deviceId is greater than 0x00ffffff, we might have a conflict but only in case of multi touch
            // and with a high variation of deviceId. We assume that's safe enough.
            // Note: Make sure to use the GetPointerId in order to make sure to keep the same id while: down_1 / down_2 / up_1 / up_2
            //		 otherwise up_2 will be with the id of 1
            var pointerId            = ((uint)nativeEvent.GetPointerId(pointerIndex) & _pointerIdsCount) << _pointerIdsShift | (uint)nativeEvent.DeviceId;
            var nativePointerAction  = nativeEvent.Action;
            var nativePointerButtons = nativeEvent.ButtonState;
            var nativePointerType    = nativeEvent.GetToolType(_pointerIndex);
            var pointerType          = nativePointerType.ToPointerDeviceType();
            var isInContact          = IsInContact(nativeEvent, (PointerDeviceType)pointerType, nativePointerAction, nativePointerButtons);
            var keys = nativeEvent.MetaState.ToVirtualKeyModifiers();

            FrameId        = (uint)_nativeEvent.EventTime;
            Pointer        = new Pointer(pointerId, (PointerDeviceType)pointerType, isInContact, isInRange: true);
            KeyModifiers   = keys;
            OriginalSource = originalSource;

            _properties = GetProperties(nativePointerType, nativePointerAction, nativePointerButtons);             // Last: we need the Pointer property to be set!
        }
Beispiel #3
0
        private void Sandbox_OnMouseDown(object sender, MouseDown3DEventArgs e)
        {
            if (e.OriginalInputEventArgs.Pointer.PointerDeviceType != PointerDeviceType.Mouse)
            {
                return;
            }
            PointerPointProperties properties = e.OriginalInputEventArgs.GetCurrentPoint(this).Properties;

            if (properties.IsLeftButtonPressed)
            {
                // Left button pressed
                // Ignore
            }
            else if (properties.IsRightButtonPressed)
            {
                // Right button pressed
                if (e.HitTestResult is null)
                {
                    return;
                }

                CallFlyout(
                    targetElement: sender as UIElement,
                    position: e.Position,
                    position3D: e.HitTestResult.PointHit);
            }
        }
Beispiel #4
0
 private Noesis.MouseButton MouseButton(PointerPointProperties props)
 {
     if (props.PointerUpdateKind == PointerUpdateKind.LeftButtonPressed ||
         props.PointerUpdateKind == PointerUpdateKind.LeftButtonReleased)
     {
         return(Noesis.MouseButton.Left);
     }
     if (props.PointerUpdateKind == PointerUpdateKind.MiddleButtonPressed ||
         props.PointerUpdateKind == PointerUpdateKind.MiddleButtonReleased)
     {
         return(Noesis.MouseButton.Middle);
     }
     if (props.PointerUpdateKind == PointerUpdateKind.RightButtonPressed ||
         props.PointerUpdateKind == PointerUpdateKind.RightButtonReleased)
     {
         return(Noesis.MouseButton.Right);
     }
     if (props.PointerUpdateKind == PointerUpdateKind.XButton1Pressed ||
         props.PointerUpdateKind == PointerUpdateKind.XButton1Released)
     {
         return(Noesis.MouseButton.XButton1);
     }
     if (props.PointerUpdateKind == PointerUpdateKind.XButton2Pressed ||
         props.PointerUpdateKind == PointerUpdateKind.XButton2Released)
     {
         return(Noesis.MouseButton.XButton2);
     }
     return(Noesis.MouseButton.Left);
 }
Beispiel #5
0
        private void OnTargetPanel_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
        {
            if (m_painter == null)
            {
                return;
            }
            if (!m_hasFocus)
            {
                return;
            }

            // Track mouse/pointer state
            PointerPoint           currentPoint    = e.GetCurrentPoint(m_painter.TargetPanel);
            PointerPointProperties pointProperties = currentPoint.Properties;
            int wheelDelta = pointProperties.MouseWheelDelta;

            if (pointProperties.IsPrimary)
            {
                m_stateMouseOrPointer.NotifyButtonStates(
                    pointProperties.IsLeftButtonPressed,
                    pointProperties.IsMiddleButtonPressed,
                    pointProperties.IsRightButtonPressed,
                    pointProperties.IsXButton1Pressed,
                    pointProperties.IsXButton2Pressed);
                m_stateMouseOrPointer.NotifyMouseWheel(wheelDelta);
            }
        }
Beispiel #6
0
        private PointerPointProperties GetProperties()
        {
            var props = new PointerPointProperties()
            {
                IsPrimary = true,
                IsInRange = Pointer.IsInRange,
            };

            props.IsLeftButtonPressed   = _buttons.HasFlag(WindowManagerInterop.HtmlPointerButtonsState.Left);
            props.IsMiddleButtonPressed = _buttons.HasFlag(WindowManagerInterop.HtmlPointerButtonsState.Middle);
            if (_buttons.HasFlag(WindowManagerInterop.HtmlPointerButtonsState.Right))
            {
                switch (Pointer.PointerDeviceType)
                {
                case PointerDeviceType.Mouse:
                    props.IsMiddleButtonPressed = true;
                    break;

                case PointerDeviceType.Pen:
                    props.IsBarrelButtonPressed = true;
                    break;
                }
            }
            props.IsXButton1Pressed = _buttons.HasFlag(WindowManagerInterop.HtmlPointerButtonsState.X1);
            props.IsXButton2Pressed = _buttons.HasFlag(WindowManagerInterop.HtmlPointerButtonsState.X2);
            props.IsEraser          = _buttons.HasFlag(WindowManagerInterop.HtmlPointerButtonsState.Eraser);

            props.PointerUpdateKind = ToUpdateKind(_buttonUpdate, props);

            return(props);
        }
Beispiel #7
0
        /// <summary>
        /// Handles pointer events on the window. This allows mouse navigation (forward/back).
        /// </summary>
        /// <param name="sender">The CoreWindow handling the event.</param>
        /// <param name="args">EventArgs for the pointer event.</param>
        private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
        {
            PointerPointProperties props = args.CurrentPoint.Properties;

            // Ignore chords with standard mouse buttons
            if (props.IsLeftButtonPressed || props.IsRightButtonPressed || props.IsMiddleButtonPressed)
            {
                return;
            }

            // If either MB4 or MB5 is pressed (but not both), navigate as appropriate
            bool backPressed    = props.IsXButton1Pressed;
            bool forwardPressed = props.IsXButton2Pressed;

            if (backPressed ^ forwardPressed)
            {
                // TODO: Forward navigation is not supported
                // Issue #124
                if (backPressed && CanGoBack())
                {
                    DebugHelper.Trace("Navigating back due to mouse button");
                    GoBack();
                }
                else if (forwardPressed) /* && CanGoForward */
                {
                    // Dbg.Trace("Navigating forward due to mouse button");
                    // GoForward();
                }
            }
        }
        public PointerPoint GetCurrentPoint(UIElement relativeTo)
        {
            int wheelDelta = PointerPointProperties.GetPointerWheelDelta(INTERNAL_OriginalJSEventArg);

            if (relativeTo == null)
            {
                //-----------------------------------
                // Return the absolute pointer coordinates:
                //-----------------------------------
                PointerPoint pointerPoint = new PointerPoint()
                {
                    Position = new Point(_pointerAbsoluteX, _pointerAbsoluteY)
                };
                pointerPoint.Properties.MouseWheelDelta = wheelDelta;
                return(pointerPoint);
            }
            else
            {
                //-----------------------------------
                // Returns the pointer coordinates relative to the "relativeTo" element:
                //-----------------------------------

                // Get the opposite of the absolute position of the "relativeTo" element:
                GeneralTransform generalTransform = Window.Current.TransformToVisual(relativeTo);

                // Get the pointer coordinates relative to "relativeTo" element:
                PointerPoint pointerPoint = new PointerPoint()
                {
                    Position = generalTransform.TransformPoint(new Point(_pointerAbsoluteX, _pointerAbsoluteY))
                };
                pointerPoint.Properties.MouseWheelDelta = wheelDelta;
                return(pointerPoint);
            }
        }
Beispiel #9
0
        private static PointerPointProperties GetPointerProperties(NSEvent nativeEvent, PointerDeviceType pointerType)
        {
            var properties = new PointerPointProperties()
            {
                IsInRange            = true,
                IsPrimary            = true,
                IsLeftButtonPressed  = ((int)NSEvent.CurrentPressedMouseButtons & LeftMouseButtonMask) == LeftMouseButtonMask,
                IsRightButtonPressed = ((int)NSEvent.CurrentPressedMouseButtons & RightMouseButtonMask) == RightMouseButtonMask,
            };

            if (pointerType == PointerDeviceType.Pen)
            {
                properties.XTilt    = (float)nativeEvent.Tilt.X;
                properties.YTilt    = (float)nativeEvent.Tilt.Y;
                properties.Pressure = (float)nativeEvent.Pressure;
            }

            if (nativeEvent.Type == NSEventType.ScrollWheel)
            {
                var y = (int)nativeEvent.ScrollingDeltaY;
                if (y == 0)
                {
                    // Note: if X and Y are != 0, we should raise 2 events!
                    properties.IsHorizontalMouseWheel = true;
                    properties.MouseWheelDelta        = (int)nativeEvent.ScrollingDeltaX;
                }
                else
                {
                    properties.MouseWheelDelta = -y;
                }
            }

            return(properties);
        }
Beispiel #10
0
        /// <summary>
        /// Gets the pressed mouse button from the specified <see cref="PointerPointProperties" />.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <returns>The pressed mouse button.</returns>
        public static OxyMouseButton GetPressedMouseButton(this PointerPointProperties properties)
        {
            if (properties.IsLeftButtonPressed)
            {
                return(OxyMouseButton.Left);
            }

            if (properties.IsMiddleButtonPressed)
            {
                return(OxyMouseButton.Middle);
            }

            if (properties.IsRightButtonPressed)
            {
                return(OxyMouseButton.Right);
            }

            if (properties.IsXButton1Pressed)
            {
                return(OxyMouseButton.XButton1);
            }

            if (properties.IsXButton2Pressed)
            {
                return(OxyMouseButton.XButton2);
            }

            return(OxyMouseButton.None);
        }
Beispiel #11
0
        /// <summary>
        ///     当此页处于活动状态并占用整个窗口时,在每次鼠标单击、触摸屏点击
        ///     或执行等效交互时调用。    用于检测浏览器样式下一页和
        ///     上一步鼠标按钮单击以在页之间导航。
        /// </summary>
        /// <param name="sender">触发事件的实例。</param>
        /// <param name="e">描述导致事件的条件的事件数据。</param>
        private void CoreWindow_PointerPressed(Windows.UI.Core.CoreWindow sender,
                                               PointerEventArgs e)
        {
            PointerPointProperties properties = e.CurrentPoint.Properties;

            // 忽略与鼠标左键、右键和中键的键关联
            if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed ||
                properties.IsMiddleButtonPressed)
            {
                return;
            }

            // 如果按下后退或前进(但不是同时),则进行相应导航
            bool backPressed    = properties.IsXButton1Pressed;
            bool forwardPressed = properties.IsXButton2Pressed;

            if (backPressed ^ forwardPressed)
            {
                e.Handled = true;
                if (backPressed)
                {
                    GoBackCommand.Execute(null);
                }
                if (forwardPressed)
                {
                    GoForwardCommand.Execute(null);
                }
            }
        }
        public PointerPoint GetCurrentPoint(UIElement relativeTo)
        {
            var device      = PointerDevice.For(PointerDeviceType.Mouse);
            var rawPosition = _nativeEvent.LocationInWindow;
            var position    = relativeTo != null?
                              relativeTo.ConvertPointFromView(_nativeEvent.LocationInWindow, null) :
                                  rawPosition;

            var properties = new PointerPointProperties()
            {
                IsInRange            = true,
                IsPrimary            = true,
                IsLeftButtonPressed  = ((int)NSEvent.CurrentPressedMouseButtons & LeftMouseButtonMask) == LeftMouseButtonMask,
                IsRightButtonPressed = ((int)NSEvent.CurrentPressedMouseButtons & RightMouseButtonMask) == RightMouseButtonMask,
            };

            if (Pointer.PointerDeviceType == PointerDeviceType.Pen)
            {
                properties.XTilt    = (float)_nativeEvent.Tilt.X;
                properties.YTilt    = (float)_nativeEvent.Tilt.Y;
                properties.Pressure = (float)_nativeEvent.Pressure;
            }

            return(new PointerPoint(
                       FrameId,
                       ToTimeStamp(_nativeEvent.Timestamp),
                       device,
                       Pointer.PointerId,
                       rawPosition,
                       position,
                       Pointer.IsInContact,
                       properties));
        }
Beispiel #13
0
        /// <summary>
        /// Invoked on every mouse click, touch screen tap, or equivalent interaction when this
        /// page is active and occupies the entire window.  Used to detect browser-style next and
        /// previous mouse button clicks to navigate between pages.
        /// </summary>
        /// <param name="sender">Instance that triggered the event.</param>
        /// <param name="e">Event data describing the conditions that led to the event.</param>
        private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs e)
        {
            PointerPointProperties properties = e.CurrentPoint.Properties;

            // Ignore button chords with the left, right, and middle buttons
            if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed ||
                properties.IsMiddleButtonPressed)
            {
                return;
            }

            // If back or foward are pressed (but not both) navigate appropriately
            bool backPressed    = properties.IsXButton1Pressed;
            bool forwardPressed = properties.IsXButton2Pressed;

            if (backPressed ^ forwardPressed)
            {
                e.Handled = true;
                if (backPressed)
                {
                    GoBackCommand.Execute(null);
                }
                if (forwardPressed)
                {
                    GoForwardCommand.Execute(null);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Invoked on every mouse click, touch screen tap, or equivalent interaction when this
        /// page is active and occupies the entire window.  Used to detect browser-style next and
        /// previous mouse button clicks to navigate between pages.
        /// </summary>
        /// <param name="sender">
        /// Instance that triggered the event.
        /// </param>
        /// <param name="args">
        /// Event data describing the conditions that led to the event.
        /// </param>
        private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
        {
            PointerPointProperties properties = args.CurrentPoint.Properties;

            // Ignore button chords with the left, right, and middle buttons
            if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed || properties.IsMiddleButtonPressed)
            {
                return;
            }

            // If back or foward are pressed (but not both) navigate appropriately
            bool backPressed    = properties.IsXButton1Pressed;
            bool forwardPressed = properties.IsXButton2Pressed;

            if (backPressed ^ forwardPressed)
            {
                args.Handled = true;
                if (backPressed)
                {
                    this.GoBack(this, new RoutedEventArgs());
                }

                if (forwardPressed)
                {
                    this.GoForward(this, new RoutedEventArgs());
                }
            }
        }
Beispiel #15
0
        void rectangle_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            lblMsg.Text += "PointerPressed " + e.Pointer.PointerId;
            lblMsg.Text += Environment.NewLine;

            bool hasCapture = ((Rectangle)sender).CapturePointer(e.Pointer);

            lblMsg.Text += "Got Capture: " + hasCapture;
            lblMsg.Text += Environment.NewLine;

            PointerPointProperties props = e.GetCurrentPoint(null).Properties;

            lblMsg.Text += "接触区域的边框: " + props.ContactRect.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "原始输入的边框: " + props.ContactRectRaw.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "触笔设备的筒状按钮是否按下: " + props.IsBarrelButtonPressed.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否已由指针设备取消: " + props.IsCanceled.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否来自橡皮擦: " + props.IsEraser.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否来自滚轮: " + props.IsHorizontalMouseWheel.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针是否在触摸屏的范围内: " + props.IsInRange.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "是否是反转的值: " + props.IsInverted.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否来自鼠标左键: " + props.IsLeftButtonPressed.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否来自鼠标中键: " + props.IsMiddleButtonPressed.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否来自鼠标右键: " + props.IsRightButtonPressed.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "输入是否来自主要指针: " + props.IsPrimary.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "第一个扩展按钮的按下状态: " + props.IsXButton1Pressed.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "第二个扩展按钮的按下状态: " + props.IsXButton2Pressed.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针施加到触摸屏上的力度(0.0-1.0): " + props.Pressure.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "触摸是否被拒绝了: " + props.TouchConfidence.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针状态的更改类型: " + props.PointerUpdateKind.ToString(); // PointerUpdateKind 枚举:LeftButtonPressed, LeftButtonReleased 等(详见文档)
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针设备相关的 Orientation: " + props.Orientation.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针设备相关的 Twist: " + props.Twist.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针设备相关的 XTilt: " + props.XTilt.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "指针设备相关的 YTiltYTilt: " + props.YTilt.ToString();
            lblMsg.Text += Environment.NewLine;

            // 输入设备相关
            // props.HasUsage(uint usagePage, uint usageId)
            // props.GetUsageValue(uint usagePage, uint usageId)
        }
 public static void ProcessUpEvent(
     this GestureRecognizer sut,
     double x,
     double y,
     uint?id  = null,
     ulong?ts = null,
     PointerDeviceType?device          = null,
     bool?isInContact                  = true,
     PointerPointProperties properties = null)
 => sut.ProcessUpEvent(GetPoint(x, y, id, ts, device, isInContact, properties));
        public PointerPoint GetCurrentPoint(UIElement relativeTo)
        {
            var device     = PointerDevice.For(PointerDeviceType.Mouse);
            var point      = relativeTo.ConvertPointFromView(_nativeEvent.LocationInWindow, null);
            var properties = new PointerPointProperties()
            {
                IsInRange = true, IsPrimary = true
            };

            return(new PointerPoint(FrameId, _pseudoTimestamp, device, 0, point, point, true, properties));
        }
Beispiel #18
0
        /// <summary>
        /// Creates an hybrid event args which reports the <paramref name="current"/> position, time and original source,
        /// while reporting the state of the <paramref name="previous"/> args (pressed buttons, key modifiers, etc.).
        /// </summary>
        /// <remarks>
        /// This has a very specific usage and should be used cautiously!
        /// </remarks>
        internal PointerRoutedEventArgs(PointerRoutedEventArgs previous, PointerRoutedEventArgs current)
        {
            _nativeTouch = current._nativeTouch;
            _nativeEvent = current._nativeEvent;

            FrameId        = current.FrameId;
            Pointer        = previous.Pointer;
            KeyModifiers   = previous.KeyModifiers;
            OriginalSource = current.OriginalSource;

            _properties = previous._properties;
        }
        public PointerPoint GetCurrentPoint(UIElement relativeTo)
        {
            var device      = PointerDevice.For(PointerDeviceType.Mouse);
            var translation = relativeTo.TransformToVisual(null) as TranslateTransform;
            var offset      = new Point(_point.X - translation.X, _point.Y - translation.Y);
            var properties  = new PointerPointProperties()
            {
                IsInRange = true, IsPrimary = true
            };

            return(new PointerPoint(FrameId, _pseudoTimestamp, device, 0, offset, offset, true, properties));
        }
        private PointerPointProperties GetProperties()
        {
            var props = new PointerPointProperties
            {
                IsPrimary = true,
                IsInRange = Pointer.IsInRange
            };

            var type    = _nativeEvent.GetToolType(_pointerIndex);
            var action  = _nativeEvent.Action;
            var isDown  = action.HasFlag(MotionEventActions.Down) || action.HasFlag(MotionEventActions.PointerDown);
            var isUp    = action.HasFlag(MotionEventActions.Up) || action.HasFlag(MotionEventActions.PointerUp);
            var updates = _none;

            switch (type)
            {
            case MotionEventToolType.Finger:
                props.IsLeftButtonPressed = Pointer.IsInContact;
                updates = isDown ? _fingerDownUpdates : isUp ? _fingerUpUpdates : _none;
                break;

            case MotionEventToolType.Mouse:
                props.IsLeftButtonPressed   = _nativeEvent.IsButtonPressed(MotionEventButtonState.Primary);
                props.IsMiddleButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.Tertiary);
                props.IsRightButtonPressed  = _nativeEvent.IsButtonPressed(MotionEventButtonState.Secondary);
                updates = isDown ? _mouseDownUpdates : isUp ? _mouseUpUpdates : _none;
                break;

            case MotionEventToolType.Stylus:
                props.IsBarrelButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.StylusPrimary);
                props.IsLeftButtonPressed   = Pointer.IsInContact && !props.IsBarrelButtonPressed;
                break;

            case MotionEventToolType.Eraser:
                props.IsEraser = true;
                break;

            case MotionEventToolType.Unknown:                     // used by Xamarin.UITest
                props.IsLeftButtonPressed = true;
                break;

            default:
                break;
            }

            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M &&          // ActionButton was introduced with API 23 (https://developer.android.com/reference/android/view/MotionEvent.html#getActionButton())
                updates.TryGetValue(_nativeEvent.ActionButton, out var update))
            {
                props.PointerUpdateKind = update;
            }

            return(props);
        }
Beispiel #21
0
        /// <summary>
        /// Send mouse wheel event to the streaming PC
        /// </summary>
        private void MouseWheel(object sender, PointerRoutedEventArgs e)
        {
            Pointer                ptr   = e.Pointer;
            PointerPoint           ptrPt = e.GetCurrentPoint(StreamDisplay);
            PointerPointProperties props = ptrPt.Properties;

            // GameStream only supports vertical scrolling for now
            if (!props.IsHorizontalMouseWheel)
            {
                MoonlightCommonRuntimeComponent.SendScrollEvent((short)(props.MouseWheelDelta / 120));
            }
        }
Beispiel #22
0
        private PointerPointProperties GetProperties()
        {
            var props = new PointerPointProperties
            {
                IsPrimary = true,
                IsInRange = Pointer.IsInRange
            };

            var type    = _nativeEvent.GetToolType(_nativeEvent.ActionIndex);
            var action  = _nativeEvent.Action;
            var isDown  = action.HasFlag(MotionEventActions.Down) || action.HasFlag(MotionEventActions.PointerDown);
            var isUp    = action.HasFlag(MotionEventActions.Up) || action.HasFlag(MotionEventActions.PointerUp);
            var updates = _none;

            switch (type)
            {
            case MotionEventToolType.Finger:
                props.IsLeftButtonPressed = Pointer.IsInContact;
                updates = isDown ? _fingerDownUpdates : isUp ? _fingerUpUpdates : _none;
                break;

            case MotionEventToolType.Mouse:
                props.IsLeftButtonPressed   = _nativeEvent.IsButtonPressed(MotionEventButtonState.Primary);
                props.IsMiddleButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.Tertiary);
                props.IsRightButtonPressed  = _nativeEvent.IsButtonPressed(MotionEventButtonState.Secondary);
                updates = isDown ? _mouseDownUpdates : isUp ? _mouseUpUpdates : _none;
                break;

            case MotionEventToolType.Stylus:
                props.IsBarrelButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.StylusPrimary);
                props.IsLeftButtonPressed   = Pointer.IsInContact && !props.IsBarrelButtonPressed;
                break;

            case MotionEventToolType.Eraser:
                props.IsEraser = true;
                break;

            case MotionEventToolType.Unknown:                     // used by Xamarin.UITest
                props.IsLeftButtonPressed = true;
                break;

            default:
                break;
            }

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

            return(props);
        }
Beispiel #23
0
        public PointerPoint(Windows.UI.Input.PointerPoint point)
        {
            FrameId           = point.FrameId;
            Timestamp         = point.Timestamp;
            PointerDevice     = point.PointerDevice;
            PointerId         = point.PointerId;
            RawPosition       = point.RawPosition;
            Position          = point.Position;
            IsInContact       = point.IsInContact;
            PointerDeviceType = (PointerDeviceType)point.PointerDevice.PointerDeviceType;

            Properties = new PointerPointProperties(point.Properties);
        }
Beispiel #24
0
        public static bool IsPointerGoBackGesture(PointerPointProperties properties)
        {
            // Ignore button chords with the left, right, and middle buttons
            if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed ||
                properties.IsMiddleButtonPressed)
            {
                return(false);
            }

            // If back or foward are pressed (but not both) navigate appropriately
            bool backPressed = properties.IsXButton1Pressed;

            return(backPressed);
        }
Beispiel #25
0
        private void PreviewMouseMoveResize(object sender, PointerEventArgs e)
        {
            PointerPointProperties properties = e.GetCurrentPoint(this).Properties;

            if (properties.IsLeftButtonPressed == true)
            {
                if (DockPosition == HorizontalAlignment.Left)
                {
                    ResizeFromRight(e);
                }
                else
                {
                    ResizeFromLeft(e);
                }
            }
        }
Beispiel #26
0
 private void Page_PointerReleased(object sender, PointerRoutedEventArgs e)
 {
     try
     {
         if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
         {
             PointerPointProperties PointerProperties = e.GetCurrentPoint(this).Properties;
             if (PointerProperties.IsXButton1Pressed)
             {
                 System.Diagnostics.Debug.WriteLine("Released pointer: Back");
                 try { ClosePopup(); } catch { }
             }
         }
     }
     catch { }
 }
Beispiel #27
0
        internal PointerRoutedEventArgs(uint pointerId, UITouch nativeTouch, UIEvent nativeEvent, UIElement receiver) : this()
        {
            _nativeTouch = nativeTouch;
            _nativeEvent = nativeEvent;

            var deviceType  = GetPointerDeviceType(nativeTouch.Type);
            var isInContact = _nativeTouch.Phase == UITouchPhase.Began ||
                              _nativeTouch.Phase == UITouchPhase.Moved ||
                              _nativeTouch.Phase == UITouchPhase.Stationary;

            FrameId        = ToFrameId(_nativeTouch.Timestamp);
            Pointer        = new Pointer(pointerId, deviceType, isInContact, isInRange: true);
            KeyModifiers   = VirtualKeyModifiers.None;
            OriginalSource = FindOriginalSource(_nativeTouch) ?? receiver;

            _properties = GetProperties();             // Make sure to capture the properties state so we can re-use them in "mixed" ctor
        }
        private PointerPointProperties GetProperties()
        {
            var props = new PointerPointProperties()
            {
                IsPrimary         = true,
                IsInRange         = Pointer.IsInRange,
                PointerUpdateKind = _updateKind
            };

            if (Pointer.IsInContact)
            {
                props.IsLeftButtonPressed   = _button == VirtualKey.LeftButton;
                props.IsMiddleButtonPressed = _button == VirtualKey.MiddleButton;
                props.IsRightButtonPressed  = _button == VirtualKey.RightButton;
            }

            return(props);
        }
Beispiel #29
0
        int ButtonCount(PointerPointProperties props)
        {
            var rv = 0;

            if (props.IsLeftButtonPressed)
            {
                rv++;
            }
            if (props.IsMiddleButtonPressed)
            {
                rv++;
            }
            if (props.IsRightButtonPressed)
            {
                rv++;
            }
            return(rv);
        }
Beispiel #30
0
        public void Down(IInteractive target, IInteractive source, MouseButton mouseButton = MouseButton.Left,
                         Point position = default, InputModifiers modifiers = default, int clickCount = 1)
        {
            _pressedButtons |= Convert(mouseButton);
            var props = new PointerPointProperties(_pressedButtons);

            if (ButtonCount(props) > 1)
            {
                Move(target, source, position);
            }
            else
            {
                _pressedButton = mouseButton;
                _pointer.Capture((IInputElement)target);
                target.RaiseEvent(new PointerPressedEventArgs(source, _pointer, (IVisual)source, position, Timestamp(), props,
                                                              GetModifiers(modifiers), clickCount));
            }
        }