private static void FillPressedButtons(MouseEventArgs e, ref PointerPoint point)
 {
     point.IsLeftButtonPressed = e.LeftButton == MouseButtonState.Pressed;
     point.IsMiddleButtonPressed = e.MiddleButton == MouseButtonState.Pressed;
     point.IsRightButtonPressed = e.RightButton == MouseButtonState.Pressed;
     point.IsXButton1Pressed = e.XButton1 == MouseButtonState.Pressed;
     point.IsXButton2Pressed = e.XButton2 == MouseButtonState.Pressed;
 }
Esempio n. 2
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);
        }
        private void AddTouchEvent(PointerEventType eventType, TouchEventArgs e)
        {
            var p = e.GetTouchPoint(element);

            var point = new PointerPoint();

            FillPointInformation(ref point,
                                 eventType,
                                 PointerDeviceType.Touch,
                                 GetTouchUpdateKind(p.Action),
                                 p.Position);

            manager.AddPointerEvent(ref point);
        }
        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;
        }
        private void AddMousePointerEvent(PointerEventType eventType, PointerUpdateKind updateKind, int wheelDelta, MouseEventArgs e)
        {
            var p = Mouse.GetPosition(element);

            var point = new PointerPoint();

            FillPointInformation(ref point,
                                 eventType,
                                 PointerDeviceType.Mouse,
                                 updateKind,
                                 p);

            FillPressedButtons(e, ref point);

            point.MouseWheelDelta = wheelDelta;

            manager.AddPointerEvent(ref point);
        }
        private void AddPenPointerEvent(PointerEventType eventType, PointerUpdateKind updateKind, bool isPress, StylusEventArgs e)
        {
            var p = e.GetPosition(element);

            var point = new PointerPoint();

            FillPointInformation(ref point,
                                 eventType,
                                 PointerDeviceType.Pen,
                                 updateKind,
                                 p);

            // if this was a press - try to determine which button was pressed
            if (isPress)
            {
                if (e.Inverted)
                    point.IsRightButtonPressed = true;
                else
                    point.IsLeftButtonPressed = true;
            }

            manager.AddPointerEvent(ref point);
        }
Esempio n. 7
0
 /// <summary>
 /// Adds a pointer point to the raised events collection. It will be copied to pointer state at next update.
 /// </summary>
 /// <param name="point">The raised pointer event</param>
 internal void AddPointerEvent(ref PointerPoint point)
 {
     // use a simple lock at this time, to avoid excessive code complexity
     lock(pointerPointLock)
         pointerPoints.Add(point);
 }
Esempio n. 8
0
 private void AppendPenProperties(StringBuilder sb, PointerPoint p)
 {
     sb.AppendFormat("Er:{0}; Rng:{1}; Inv:{2}; Or:{3}; Tw:{4}; Tx:{5}; Ty:{6}", p.IsEraser, p.IsInRange, p.IsInverted, p.Orientation, p.Twist, p.XTilt, p.YTilt);
 }
Esempio n. 9
0
 private void AppendMouseProperties(StringBuilder sb, PointerPoint p)
 {
     sb.AppendFormat("L:{0}; R:{1}; M:{2}; d:{3}", p.IsLeftButtonPressed, p.IsRightButtonPressed, p.IsMiddleButtonPressed, p.MouseWheelDelta);
 }
Esempio n. 10
0
 /// <summary>
 /// Adds a pointer point to the raised events collection. It will be copied to pointer state at next update.
 /// </summary>
 /// <param name="point">The raised pointer event</param>
 internal void AddPointerEvent(ref PointerPoint point)
 {
     // use a simple lock at this time, to avoid excessive code complexity
     lock (pointerPointLock)
         pointerPoints.Add(point);
 }
Esempio n. 11
0
 public PointerEventDescrption(int index, PointerPoint point)
 {
     this.index = index;
     this.point = point;
     this.description = point.EventType.ToString();
 }
Esempio n. 12
0
        private void AddEvent(PointerPoint point)
        {
            // uncomment and edit these lines to filter-out the unneeded events
            //if (recentEvents.Count > 0)
            //{
            //    var e = recentEvents.Last();
            //    var skipEvent = e.Point.DeviceType == point.DeviceType
            //                    && e.Point.PointerId == point.PointerId
            //                    && e.Point.Properties.PointerUpdateKind == point.Properties.PointerUpdateKind;

            //    if (skipEvent) return;
            //}


            if (recentEvents.Count == maxEvents)
                recentEvents.Dequeue();

            recentEvents.Enqueue(new PointerEventDescrption(eventIndex++, point));
        }
Esempio n. 13
0
 private void AppendTouchProperties(StringBuilder sb, PointerPoint p)
 {
     sb.AppendFormat("L:{0}; C:{1}; T:{2}; R:{3}", p.IsLeftButtonPressed, p.IsCanceled, p.TouchConfidence, p.IsInRange);
 }
        /// <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);
        }
        /// <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);
        }
        /// <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");

            var position = point.Position;
            var properties = point.Properties;
            var contactRect = properties.ContactRect;

            var result = new PointerPoint
                         {
                             EventType = type,
                             DeviceType = PointerDeviceType.Touch,
                             KeyModifiers = KeyModifiers.None,
                             PointerId = point.PointerId,
                             Position = new DrawingPointF((float)position.X, (float)position.Y),
                             Timestamp = point.Timestamp,
                             ContactRect = new DrawingRectangleF((float)contactRect.X, (float)contactRect.Y, (float)contactRect.Width, (float)contactRect.Height),
                             IsBarrelButtonPresset = 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);
        }
        private void AddEvent(PointerPoint point)
        {
            if (recentEvents.Count == maxEvents)
                recentEvents.Dequeue();

            recentEvents.Enqueue(new PointerEventDescrption(eventIndex++, point));
        }