示例#1
0
        // TODO Code from PointeriOS with slight modifications, consider creating and referencing a utility class
        private int GetFingerId(long touchId, PointerEventType type)
        {
            // Assign finger index (starting at 0) to touch ID
            int touchFingerIndex = 0;

            if (type == PointerEventType.Pressed)
            {
                touchFingerIndex = touchCounter++;
                touchFingerIndexMap.Add(touchId, touchFingerIndex);
            }
            else
            {
                touchFingerIndex = touchFingerIndexMap[touchId];
            }

            // Remove index
            if (type == PointerEventType.Released)
            {
                touchFingerIndexMap.Remove(touchId);
                touchCounter = 0; // Reset touch counter

                // Recalculate next finger index
                if (touchFingerIndexMap.Count > 0)
                {
                    touchFingerIndexMap.ForEach(pair => touchCounter = Math.Max(touchCounter, pair.Value));
                    touchCounter++; // next
                }
            }

            return(touchFingerIndex);
        }
        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;
        }
 protected PlayerPointerEventData GetLastPointerEventData(
     int playerId,
     int pointerIndex,
     int pointerTypeId,
     bool ignorePointerTypeId,
     PointerEventType pointerEventType)
 {
     if (!ignorePointerTypeId)
     {
         PlayerPointerEventData data;
         this.GetPointerData(playerId, pointerIndex, pointerTypeId, out data, false, pointerEventType);
         return(data);
     }
     Dictionary <int, PlayerPointerEventData>[] dictionaryArray;
     if (!this.m_PlayerPointerData.TryGetValue(playerId, out dictionaryArray))
     {
         return((PlayerPointerEventData)null);
     }
     if ((uint)pointerIndex >= (uint)dictionaryArray.Length)
     {
         return((PlayerPointerEventData)null);
     }
     using (Dictionary <int, PlayerPointerEventData> .Enumerator enumerator = dictionaryArray[pointerIndex].GetEnumerator())
     {
         if (enumerator.MoveNext())
         {
             return(enumerator.Current.Value);
         }
     }
     return((PlayerPointerEventData)null);
 }
    private void sendRayCast(PointerEventData eventData, PointerEventType evType)
    {
        //Loop over the RaycastResult and simulate the pointer event
        for (int i = 0; i < rayCast3DResult.Count; i++)
        {
            GameObject       target = rayCast3DResult[i].gameObject;
            PointerEventData evData = createEventData(rayCast3DResult[i]);

            if (evType == PointerEventType.Drag)
            {
                ExecuteEvents.Execute <IDragHandler>(target,
                                                     evData,
                                                     ExecuteEvents.dragHandler);
            }

            if (evType == PointerEventType.Down)
            {
                ExecuteEvents.Execute <IPointerDownHandler>(target,
                                                            evData,
                                                            ExecuteEvents.pointerDownHandler);
            }

            if (evType == PointerEventType.Up)
            {
                ExecuteEvents.Execute <IPointerUpHandler>(target,
                                                          evData,
                                                          ExecuteEvents.pointerUpHandler);
            }
        }
    }
        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);
        }
示例#6
0
        private void CreateEvent(Entity target, PointerEventType type, bool propagateParent, PointerButton button)
        {
            if (ReceiverFromEntity.Exists(target) && (ReceiverFromEntity[target].ListenerTypes & type) == type)
            {
                PointerEventData eventData = new PointerEventData()
                {
                    Button           = button,
                    ClickCount       = -1,
                    ClickTime        = 0.0f,
                    Delta            = PointerFrameData[0].Delta,
                    PointerId        = -1,
                    Position         = PointerFrameData[0].Position,
                    ScrollDelta      = float2.zero,
                    UseDragThreshold = false,
                };
                if (button != PointerButton.Invalid)
                {
                    eventData.IsDragging    = ButtonStates[(int)button].IsDragging;
                    eventData.PressPosition = ButtonStates[(int)button].PressPosition;
                    eventData.PressEntity   = ButtonStates[(int)button].PressEntity;
                }
                TargetToEvent.Add(target, new PointerInputBuffer()
                {
                    EventId   = m_EventIdCounter++,
                    EventType = type,
                    EventData = eventData
                });
            }

            if (!propagateParent || IsConsumableType(type))
            {
                return;
            }
            Entity parent = GetParent(target);

            while (parent != default)
            {
                if (!ReceiverFromEntity.Exists(parent))
                {
                    parent = GetParent(parent);
                }
                else
                {
                    if (IsConsumableType(type))
                    {
                        var receiver = ReceiverFromEntity[parent];
                        if ((receiver.ListenerTypes & type) == type)
                        {
                            propagateParent = false;
                        }
                    }

                    CreateEvent(parent, type, propagateParent, button);
                    break;
                }
            }
        }
示例#7
0
        public PointerInput(PointerPoint pointerPoint, PointerEventType eventType)
        {
            _progress = new Dictionary <CustomGestureSettings, GestureProgress>();

            var currentEvent = new PointerEvent(pointerPoint, eventType);

            Initial    = Current = Previous = currentEvent;
            Identifier = currentEvent.Pointer.PointerId;
        }
示例#8
0
        private void HandleFingerEvent(SDL.SDL_TouchFingerEvent e, PointerEventType type)
        {
            var newPosition = new Vector2(e.x, e.y);
            var id          = GetFingerId(e.fingerId, type);

            PointerState.PointerInputEvents.Add(new PointerDeviceState.InputEvent {
                Type = type, Position = newPosition, Id = id
            });
        }
示例#9
0
        private OnPointerEvent <T> Get(PointerEventType eventType)
        {
            if (!events.ContainsKey(eventType))
            {
                events[eventType] = new OnPointerEvent <T>();
            }

            return(events[eventType]);
        }
示例#10
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);
        }
示例#11
0
        private void DispatchPointerEvent(PointerEventType type, double ex,
                                          double ey, ModifierType mods)
        {
            GtkPointerEvent outEvent = pointerEvent;

            if (outEvent.Update(type, ex, ey, mods))
            {
                CanvasModel.HandlePointerEvent(outEvent);
            }
        }
示例#12
0
 private void HandlePointer(PointerEventType type, PointerPointUWP point)
 {
     if (point.PointerDevice.PointerDeviceType == PointerDeviceType.Touch || point.PointerDevice.PointerDeviceType == PointerDeviceType.Pen)
     {
         PointerState.PointerInputEvents.Add(new PointerDeviceState.InputEvent
         {
             Id       = (int)point.PointerId,
             Position = Normalize(PointToVector2(point.Position)),
             Type     = type
         });
     }
 }
示例#13
0
 private void Execute <T>(PointerEventType id, T eventData) where T : PointerEventData
 {
     if (delegates != null)
     {
         for (int i = 0, imax = delegates.Count; i < imax; ++i)
         {
             Entry ent = delegates[i];
             if (ent.eventID == id && ent.callback != null)
             {
                 ent.callback.Invoke(eventData);
             }
         }
     }
 }
示例#14
0
        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 findColliders(PointerEventData eventData, PointerEventType evType)
    {
        UpdateRaycaster();

        //Loop Through All Normal Collider(3D/Mesh Renderer) and throw Raycast to each one
        for (int i = 0; i < rayCast3D.Count; i++)
        {
            //Send Raycast to all GameObject with 3D Collider
            rayCast3D[i].Raycast(eventData, rayCast3DResult);
            sendRayCast(eventData, evType);
        }
        //Reset Result
        rayCast3DResult.Clear();
    }
        private PlayerPointerEventData CreatePointerEventData(
            int playerId,
            int pointerIndex,
            int pointerTypeId,
            PointerEventType pointerEventType)
        {
            PlayerPointerEventData pointerEventData1 = new PlayerPointerEventData(this.get_eventSystem());

            pointerEventData1.playerId         = playerId;
            pointerEventData1.inputSourceIndex = pointerIndex;
            pointerEventData1.set_pointerId(pointerTypeId);
            pointerEventData1.sourceType = pointerEventType;
            PlayerPointerEventData pointerEventData2 = pointerEventData1;

            switch (pointerEventType)
            {
            case PointerEventType.Mouse:
                pointerEventData2.mouseSource = this.GetMouseInputSource(playerId, pointerIndex);
                break;

            case PointerEventType.Touch:
                pointerEventData2.touchSource = this.GetTouchInputSource(playerId, pointerIndex);
                break;
            }
            switch (pointerTypeId)
            {
            case -3:
                pointerEventData2.buttonIndex = 2;
                break;

            case -2:
                pointerEventData2.buttonIndex = 1;
                break;

            case -1:
                pointerEventData2.buttonIndex = 0;
                break;

            default:
                if (pointerTypeId >= -2147483520 && pointerTypeId <= -2147483392)
                {
                    pointerEventData2.buttonIndex = pointerTypeId - -2147483520;
                    break;
                }
                break;
            }
            return(pointerEventData2);
        }
示例#17
0
 public bool Update(PointerEventType type,
                    double rx, double ry, ModifierType state)
 {
     if (type == Type && rx == RawX && ry == RawY && mods == state)
     {
         return(false);
     }
     else
     {
         Type = type;
         RawX = rx;
         RawY = ry;
         mods = state;
         return(true);
     }
 }
示例#18
0
    public void Subscribe(PointerEventType type, UnityAction <PointerEventData> handler)
    {
        var trigger = delegates.Find(x => x.eventID == type);

        if (trigger == null)
        {
            var entry = new Entry();
            entry.eventID = type;
            entry.callback.AddListener(handler);
            delegates.Add(entry);
        }
        else
        {
            trigger.callback.AddListener(handler);
        }
    }
示例#19
0
    /// <summary>
    /// Update the target image's color depending on which of the PointerEventSettings' conditions is met first.
    /// </summary>
    private void UpdateColor()
    {
        Color color = DefaultColor;

        foreach (PointerEventSetting setting in EventPriorities)
        {
            PointerEventType eventType = setting.eventType;
            if (eventType == PointerEventType.Hover && hovered ||
                eventType == PointerEventType.ToggleSelect && selected ||
                eventType == PointerEventType.Pressed && pressed)
            {
                color = setting.color;
                break;
            }
        }
        EaseColor(color);
    }
示例#20
0
        public int SendEvent(PointerEventType eventType, PointerPoint ptrPt)
        {
            int rc;
            var total = 0;

            if ((rc = SendEventType(EventType.Pointer)) < 0)
            {
                return(-1);
            }
            total += rc;
            if ((rc = SendPointerEvent(eventType, ptrPt)) < 0)
            {
                return(-1);
            }
            total += rc;
            return(total);
        }
示例#21
0
        private int SendPointerEvent(PointerEventType eventType, PointerPoint ptrPt)
        {
            int rc;
            var total = 0;

            if ((rc = SendPointerEventType(eventType)) < 0)
            {
                return(-1);
            }
            total += rc;
            if ((rc = SendPointerPoint(ptrPt)) < 0)
            {
                return(-1);
            }
            total += rc;
            return(total);
        }
示例#22
0
        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);
        }
示例#23
0
        public void TargetMouseUp(object sender, MouseEventArgs e)
        {
            PointerEventType type = GetPointerType(e.Button);

            if (_responder == null || type == PointerEventType.None)
            {
                return;
            }

            Point            position = TranslatePosition(e.Location);
            PointerEventInfo info     = new PointerEventInfo(type, position.X, position.Y);

            if (_sequenceOpen[info.Type])
            {
                _sequenceOpen[info.Type] = false;
                _responder.HandleEndPointerSequence(info);
            }
        }
        /// <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 normalizedPosition = new Vector2((float)p.X / clientSize.Width, (float)p.Y / clientSize.Height);

            normalizedPosition.Saturate();

            var point = new PointerPoint
            {
                EventType              = eventType,
                DeviceType             = PointerDeviceType.Mouse,
                KeyModifiers           = GetCurrentKeyModifiers(),
                PointerId              = 0,
                Position               = new Vector2(p.X, p.Y),
                NormalizedPosition     = normalizedPosition,
                Timestamp              = (ulong)DateTime.Now.Ticks,
                ContactRect            = new RectangleF(normalizedPosition.X, normalizedPosition.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>
        /// Creates a platform-independent instance of <see cref="PointerPoint"/> class from WinRT-specific objects.
        /// </summary>
        /// <param name="type">The pointer event type.</param>
        /// <param name="modifiers">The pressed modifier keys.</param>
        /// <param name="point">The WinRT-specific instance of pointer point.</param>
        /// <returns>An instance of <see cref="PointerPoint"/> class.</returns>
        private void CreateAndAddPoint(PointerEventType type, VirtualKeyModifiers modifiers, 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             = GetDeviceType(point.PointerDevice.PointerDeviceType),
                KeyModifiers           = GetKeyModifiers(modifiers),
                PointerId              = point.PointerId,
                Position               = new Vector2((float)position.X / windowSize.Width, (float)position.Y / windowSize.Height),
                Timestamp              = point.Timestamp,
                ContactRect            = new RectangleF((float)contactRect.X / windowSize.Width, (float)contactRect.Y / windowSize.Height, (float)contactRect.Width / windowSize.Width, (float)contactRect.Height / windowSize.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 = GetPointerUpdateKind(properties.PointerUpdateKind)
            };

            manager.AddPointerEvent(ref result);
        }
    public static PointerEventType GetPointerEventType(Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
    {
        PointerEventType type = PointerEventType.None;

        if (EventIsErase(e))
        {
            type = PointerEventType.Erase;
        }
        else if (EventIsInk(e))
        {
            type = PointerEventType.Ink;
        }
        else if (EventIsSelect(e))
        {
            type = PointerEventType.Select;
        }

        return(type);
    }
示例#27
0
        public void TargetMouseDown(object sender, MouseEventArgs e)
        {
            PointerEventType type = GetPointerType(e.Button);

            if (_responder == null || type == PointerEventType.None)
            {
                return;
            }

            Point            position = TranslatePosition(e.Location);
            PointerEventInfo info     = new PointerEventInfo(type, position.X, position.Y);

            // Ignore event if a sequence is active
            if (_sequenceOpen.Count(kv => { return(kv.Value); }) == 0)
            {
                _sequenceOpen[info.Type] = true;
                _responder.HandleStartPointerSequence(info);
            }
        }
示例#28
0
        private bool IsConsumableType(PointerEventType type)
        {
            switch (type)
            {
            case PointerEventType.Down:
            case PointerEventType.Up:
            case PointerEventType.Click:
            case PointerEventType.Selected:
            case PointerEventType.Deselected:
            case PointerEventType.BeginDrag:
            case PointerEventType.EndDrag:
            case PointerEventType.Drag:
            case PointerEventType.Drop:
                return(true);

            default:
                return(false);
            }
        }
    void routeOption(PointerEventData eventData, PointerEventType evType)
    {
        UpdateRaycaster();
        if (WholeScreenPointer.Instance.simulateUIEvent)
        {
            //Loop Through All GraphicRaycaster(UI) and throw Raycast to each one
            for (int i = 0; i < grRayCast.Count; i++)
            {
                //Throw Raycast to all UI elements in the position(eventData)
                grRayCast[i].Raycast(eventData, resultList);
                sendArtificialUIEvent(grRayCast[i], eventData, evType);
            }
            //Reset Result
            resultList.Clear();
        }

        if (WholeScreenPointer.Instance.simulateCollider2DEvent)
        {
            //Loop Through All Collider 2D (Sprite Renderer) and throw Raycast to each one
            for (int i = 0; i < phy2dRayCast.Count; i++)
            {
                //Throw Raycast to all UI elements in the position(eventData)
                phy2dRayCast[i].Raycast(eventData, resultList);
                sendArtificialUIEvent(phy2dRayCast[i], eventData, evType);
            }
            //Reset Result
            resultList.Clear();
        }

        if (WholeScreenPointer.Instance.simulateColliderEvent)
        {
            //Loop Through All Normal Collider(3D/Mesh Renderer) and throw Raycast to each one
            for (int i = 0; i < phyRayCast.Count; i++)
            {
                //Throw Raycast to all UI elements in the position(eventData)
                phyRayCast[i].Raycast(eventData, resultList);
                sendArtificialUIEvent(phyRayCast[i], eventData, evType);
            }
            //Reset Result
            resultList.Clear();
        }
    }
        static CefTouchEventType ToCefTouchEventType(PointerEventType pointerEventType)
        {
            switch (pointerEventType)
            {
            case PointerEventType.Pressed:
                return(CefTouchEventType.Pressed);

            case PointerEventType.Moved:
                return(CefTouchEventType.Moved);

            case PointerEventType.Released:
                return(CefTouchEventType.Released);

            case PointerEventType.Canceled:
                return(CefTouchEventType.Cancelled);

            default:
                return(default);
            }
        }
        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);
        }
        /// <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);
        }
示例#33
0
 public PointerEventInfo(PointerEventType type, double x, double y)
 {
     Type = type;
     X = x;
     Y = y;
 }
示例#34
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>
        /// 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);
        }
        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);
        }
        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 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);
        }