示例#1
0
        /// <summary>
        /// Returns the mouse cursor position from cached values
        /// </summary>
        protected override Vector2 GetLocationInternal()
        {
            var p = control.PointToClient(Cursor.Position);

            var clientSize = control.ClientSize;
            var position = new Vector2((float)p.X / clientSize.Width, (float)p.Y / clientSize.Height);
            position.Saturate();
            return position;
        }
        protected override Vector2 GetLocationInternal()
        {
            System.Drawing.Point p = System.Drawing.Point.Empty;
            if (control.InvokeRequired)
            {
                control.Invoke(new Action(delegate { p = control.PointToClient(Cursor.Position); }));
            }
            else
            {
                p = control.PointToClient(Cursor.Position);
            }

            var clientSize = control.ClientSize;
            var position = new Vector2((float)p.X / clientSize.Width, (float)p.Y / clientSize.Height);
            position.Saturate();
            return position;
        }
        /// <summary>
        /// Creates a <see cref="PointerPoint"/> instance from current mouse state.
        /// </summary>
        /// <param name="eventType">The type of pointer event.</param>
        /// <param name="pointerUpdateKind">The kind of pointer event.</param>
        /// <param name="wheelDelta">The current mouse wheel delta.</param>
        private void CreateAndAddPoint(PointerEventType eventType, PointerUpdateKind pointerUpdateKind, int wheelDelta)
        {
            var p = control.PointToClient(Control.MousePosition);

            var mouseButtons = Control.MouseButtons;

            var clientSize = control.ClientSize;
            var position = new Vector2((float)p.X / clientSize.Width, (float)p.Y / clientSize.Height);
            position.Saturate();

            var point = new PointerPoint
                   {
                       EventType = eventType,
                       DeviceType = PointerDeviceType.Mouse,
                       KeyModifiers = GetCurrentKeyModifiers(),
                       PointerId = 0,
                       Position = position,
                       Timestamp = (ulong)DateTime.Now.Ticks,
                       ContactRect = new RectangleF(position.X, position.Y, 0f, 0f),
                       IsBarrelButtonPressed = false,
                       IsCanceled = false,
                       IsEraser = false,
                       IsHorizontalMouseWheel = false,
                       IsInRange = false,
                       IsInverted = false,
                       IsLeftButtonPressed = (mouseButtons & MouseButtons.Left) != 0,
                       IsMiddleButtonPressed = (mouseButtons & MouseButtons.Middle) != 0,
                       IsPrimary = true,
                       IsRightButtonPressed = (mouseButtons & MouseButtons.Right) != 0,
                       IsXButton1Pressed = (mouseButtons & MouseButtons.XButton1) != 0,
                       IsXButton2Pressed = (mouseButtons & MouseButtons.XButton2) != 0,
                       MouseWheelDelta = wheelDelta,
                       Orientation = 0f,
                       TouchConfidence = false, // ?
                       Twist = 0f,
                       XTilt = 0f,
                       YTilt = 0f,
                       PointerUpdateKind = pointerUpdateKind
                   };

            manager.AddPointerEvent(ref point);
        }
示例#4
0
 /// <inheritdoc />
 internal override void SetLocation(Vector2 point)
 {
     point.Saturate();
     var clientSize = control.ClientSize;
     Cursor.Position = control.PointToScreen(new System.Drawing.Point((int)(point.X * clientSize.Width), (int)(point.Y * clientSize.Height)));
 }
示例#5
0
        /// <summary>
        /// Creates a platform-independent instance of <see cref="PointerPoint"/> class from WP8-specific objects.
        /// </summary>
        /// <param name="type">The pointer event type.</param>
        /// <param name="point">The WP8-specific instance of pointer point.</param>
        /// <returns>An instance of <see cref="PointerPoint"/> class.</returns>
        private void CreateAndAddPoint(PointerEventType type, global::Windows.UI.Input.PointerPoint point)
        {
            if (point == null) throw new ArgumentNullException("point");

            // If we can't access the uiElement (this can happen here), then run this code on the UI thread
            if (!uiElement.Dispatcher.CheckAccess())
            {
                uiElement.Dispatcher.BeginInvoke(() => CreateAndAddPoint(type, point));
                return;
            }

            var p = point.Position;
            var properties = point.Properties;
            var contactRect = properties.ContactRect;
            var width = (float)uiElement.ActualWidth;
            var height = (float)uiElement.ActualHeight;

            var position = new Vector2((float)p.X / width, (float)p.Y / height);
            position.Saturate();

            var result = new PointerPoint
                         {
                             EventType = type,
                             DeviceType = PointerDeviceType.Touch,
                             KeyModifiers = KeyModifiers.None,
                             PointerId = point.PointerId,
                             Position = position,
                             Timestamp = point.Timestamp,
                             ContactRect = new RectangleF((float)contactRect.X / width, (float)contactRect.Y / height, (float)contactRect.Width / width, (float)contactRect.Height / height),
                             IsBarrelButtonPressed = properties.IsBarrelButtonPressed,
                             IsCanceled = properties.IsCanceled,
                             IsEraser = properties.IsEraser,
                             IsHorizontalMouseWheel = properties.IsHorizontalMouseWheel,
                             IsInRange = properties.IsInRange,
                             IsInverted = properties.IsInverted,
                             IsLeftButtonPressed = properties.IsLeftButtonPressed,
                             IsMiddleButtonPressed = properties.IsMiddleButtonPressed,
                             IsPrimary = properties.IsPrimary,
                             IsRightButtonPressed = properties.IsRightButtonPressed,
                             IsXButton1Pressed = properties.IsXButton1Pressed,
                             IsXButton2Pressed = properties.IsXButton2Pressed,
                             MouseWheelDelta = properties.MouseWheelDelta,
                             Orientation = properties.Orientation,
                             TouchConfidence = properties.TouchConfidence,
                             Twist = properties.Twist,
                             XTilt = properties.XTilt,
                             YTilt = properties.YTilt,
                             PointerUpdateKind = PointerUpdateKind.Other
                         };

            manager.AddPointerEvent(ref result);
        }
        /// <summary>
        /// Returns the mouse cursor position from cached values
        /// </summary>
        protected override Vector2 GetLocationInternal()
        {
            Point p;
            GetCursorPos(out p);
            ScreenToClient(control.Handle, ref p);

            var clientSize = control.ClientSize;
            var position = new Vector2((float)p.X / clientSize.Width, (float)p.Y / clientSize.Height);
            position.Saturate();
            return position;
        }
        private void FillPointInformation(ref PointerPoint point,
                                          PointerEventType eventType,
                                          PointerDeviceType deviceType,
                                          PointerUpdateKind updateKind,
                                          System.Windows.Point positionPoint)
        {
            var position = new Vector2((float)(positionPoint.X / element.ActualWidth), (float)(positionPoint.Y / element.ActualHeight));
            position.Saturate();

            point.EventType = eventType;
            point.DeviceType = deviceType;
            point.KeyModifiers = GetPressedKeyModifiers();
            point.PointerId = 0;
            point.Position = position;
            point.Timestamp = (ulong)DateTime.Now.Ticks;
            point.ContactRect = new RectangleF(position.X, position.Y, 0f, 0f);
            point.IsBarrelButtonPressed = false;
            point.IsCanceled = false;
            point.IsEraser = false;
            point.IsHorizontalMouseWheel = false;
            point.IsInRange = false;
            point.IsInverted = false;
            point.IsPrimary = true;
            point.MouseWheelDelta = 0;
            point.Orientation = 0f;
            point.TouchConfidence = false;
            point.Twist = 0f;
            point.XTilt = 0f;
            point.YTilt = 0f;
            point.PointerUpdateKind = updateKind;
        }
        /// <summary>
        /// Decodes a single touch point and creates from it the <see cref="PointerPoint"/> class.
        /// </summary>
        /// <param name="input">The touch point input structure.</param>
        private void DecodeAndDispatchTouchPoint(TOUCHINPUT input)
        {
            var p = control.PointToClient(new System.Drawing.Point(AdjustX(input.x), AdjustY(input.y)));

            var mask = input.dwMask;
            var flags = input.dwFlags;

            var isPrimary = (flags & User32.TOUCHEVENTF_PRIMARY) != 0;

            PointerUpdateKind pointerUpdateKind;
            PointerEventType eventType;
            if ((flags & User32.TOUCHEVENTF_DOWN) != 0)
            {
                pointerUpdateKind = PointerUpdateKind.LeftButtonPressed;
                eventType = PointerEventType.Pressed;
            }
            else if ((flags & User32.TOUCHEVENTF_DOWN) != 0)
            {
                pointerUpdateKind = PointerUpdateKind.LeftButtonReleased;
                eventType = PointerEventType.Released;
            }
            else
            {
                pointerUpdateKind = PointerUpdateKind.Other;
                eventType = PointerEventType.Moved;
            }

            var clientSize = control.ClientSize;
            var position = new Vector2((float)p.X / clientSize.Width, (float)p.Y / clientSize.Height);
            position.Saturate();

            var point = new PointerPoint
                        {
                            EventType = eventType,
                            DeviceType = ((flags & User32.TOUCHEVENTF_PEN) != 0) ? PointerDeviceType.Pen : PointerDeviceType.Touch,
                            PointerId = (uint)input.dwID,
                            Timestamp = (ulong)input.dwTime,
                            Position = position,
                            KeyModifiers = GetCurrentKeyModifiers(),
                            IsPrimary = isPrimary,
                            IsInRange = (flags & User32.TOUCHEVENTF_INRANGE) != 0,
                            TouchConfidence = (flags & User32.TOUCHEVENTF_PALM) != 0,
                            PointerUpdateKind = pointerUpdateKind,
                        };

            if ((mask & User32.TOUCHINPUTMASKF_CONTACTAREA) != 0)
                point.ContactRect = new RectangleF(position.X, position.Y, (float)AdjustX(input.cxContact) / clientSize.Width, (float)AdjustY(input.cyContact) / clientSize.Height);

            manager.AddPointerEvent(ref point);
        }
        /// <inheritdoc />
        protected override Vector2 GetLocationInternal()
        {
            var p = Mouse.GetPosition(element);

            var position = new Vector2((float)(p.X / element.ActualWidth), (float)(p.Y / element.ActualHeight));
            position.Saturate();
            return position;
        }