Exemple #1
0
        private void OnMouseInputEvent(Vector2 pixelPosition, MouseButton button, InputEventType type, float value = 0)
        {
            // The mouse wheel event are still received even when the mouse cursor is out of the control boundaries. Discard the event in this case.
            if (type == InputEventType.Wheel && !uiControl.ClientRectangle.Contains(uiControl.PointToClient(Control.MousePosition)))
            {
                return;
            }

            // the mouse events series has been interrupted because out of the window.
            if (type == InputEventType.Up && !MouseButtonCurrentlyDown[(int)button])
            {
                return;
            }

            CurrentMousePosition = NormalizeScreenPosition(pixelPosition);

            var mouseInputEvent = new MouseInputEvent {
                Type = type, MouseButton = button, Value = value
            };

            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            if (type != InputEventType.Wheel)
            {
                var buttonId = (int)button;
                MouseButtonCurrentlyDown[buttonId] = type == InputEventType.Down;
                HandlePointerEvents(buttonId, CurrentMousePosition, InputEventTypeToPointerState(type), PointerType.Mouse);
            }
        }
Exemple #2
0
        public void OnMouseClick(MouseInputEvent evt)
        {
            bool hadFocus = hasFocus;

            if (evt.IsConsumed || (!hasFocus && !Input.RequestFocus(this)))
            {
                return;
            }

            if (!hadFocus && selectAllOnFocus)
            {
                return;
            }

            blinkStartTime = Time.unscaledTime;
            Vector2 mouse = evt.MousePosition - layoutResult.screenPosition - layoutResult.ContentRect.position;

            mouse += textScroll;

            if (evt.IsDoubleClick)
            {
                selectionRange = textElement.textInfo.SelectWordAtPoint(mouse);
            }
            else if (evt.IsTripleClick)
            {
                selectionRange = textElement.textInfo.SelectLineAtPoint(mouse);
            }
            else
            {
                selectionRange = new SelectionRange(textElement.textInfo.GetIndexAtPoint(mouse));
                ScrollToCursor();
            }

            evt.StopPropagation();
        }
Exemple #3
0
        public void OnClickHorizontal(MouseInputEvent evt)
        {
            float x = evt.MousePosition.x - layoutResult.screenPosition.x;

            float contentAreaWidth = layoutResult.ContentAreaWidth;
            float contentWidth     = children[0].layoutResult.actualSize.width;

            if (contentWidth == 0)
            {
                return;
            }

            float handleWidth = (contentAreaWidth / contentWidth) * contentAreaWidth;

            float handlePosition = (contentAreaWidth - handleWidth) * scrollPercentageX;

            float pageSize = evt.element.layoutResult.allocatedSize.width / contentWidth;

            if (x < handlePosition)
            {
                pageSize = -pageSize;
            }

            ScrollToHorizontalPercent(scrollPercentageX + pageSize);

            evt.StopPropagation();
        }
Exemple #4
0
        public void OnClickVertical(MouseInputEvent evt)
        {
            float contentAreaHeight  = layoutResult.ContentAreaHeight;
            float contentHeight      = children[0].layoutResult.actualSize.height;
            float paddingBorderStart = layoutResult.VerticalPaddingBorderStart;
            float y = evt.MousePosition.y - layoutResult.screenPosition.y - paddingBorderStart;

            if (contentHeight == 0)
            {
                return;
            }

            float handleHeight = (contentAreaHeight / contentHeight) * contentAreaHeight;

            float handlePosition = (paddingBorderStart + contentAreaHeight - handleHeight) * scrollPercentageY;

            float pageSize = evt.element.layoutResult.allocatedSize.height / contentHeight;

            if (y < handlePosition)
            {
                pageSize = -pageSize;
            }

            ScrollToVerticalPercent(scrollPercentageY + pageSize);

            evt.StopPropagation();
        }
        private void OnMouseInputEvent(Vector2 pixelPosition, H1MouseButton button, InputEventType type, float value = 0.0f)
        {
            // the mouse wheel event are still received when the mouse cursor is out of the control boundaries. discard the event in this case
            if (type == InputEventType.Wheel && !Control.IsMouseOver)
            {
                return;
            }

            // the mouse event series has been interrupted because out of the window
            if (type == InputEventType.Up && !m_MouseButtonCurrentlyDown[(int)button])
            {
                return;
            }

            m_CurrentMousePosition = NormalizeScreenPosition(pixelPosition);

            var mouseInputEvent = new MouseInputEvent {
                Type = type, MouseButton = button, Value = value
            };

            m_MouseInputEvents.Add(mouseInputEvent);

            if (type != InputEventType.Wheel)
            {
                var buttonId = (int)button;
                m_MouseButtonCurrentlyDown[buttonId] = type == InputEventType.Down;
                HandleMouseMovingEvents(buttonId, m_CurrentMousePosition, InputEventTypeToMouseState(type));
            }
        }
        private AppInterface.TouchData CreateTouchEventData(MouseInputEvent inputEvent)
        {
            var result = new AppInterface.TouchData();

            result.point.Set(inputEvent.x, inputEvent.y);
            return(result);
        }
Exemple #7
0
 public MouseInput(MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods, int multiTapCount)
 {
     Event         = ev;
     Button        = button;
     Location      = location;
     Modifiers     = mods;
     MultiTapCount = multiTapCount;
 }
Exemple #8
0
 public void SelectElement(MouseInputEvent evt, int index)
 {
     selectedIndex = index;
     selectedValue = options[selectedIndex].Value;
     selecting     = false;
     evt.StopPropagation();
     evt.Consume();
 }
Exemple #9
0
 public MouseInput(MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods, int multiTapCount)
 {
     this.Event         = ev;
     this.Button        = button;
     this.Location      = location;
     this.Modifiers     = mods;
     this.MultiTapCount = multiTapCount;
 }
Exemple #10
0
		public MouseInput(MouseInputEvent ev, MouseButton button, int scrollDelta, int2 location, Modifiers mods, int multiTapCount)
		{
			Event = ev;
			Button = button;
			ScrollDelta = scrollDelta;
			Location = location;
			Modifiers = mods;
			MultiTapCount = multiTapCount;
		}
Exemple #11
0
            public void HandleMouseUpChild(MouseInputEvent evt, int index)
            {
                clickedChildIndex = index;
                if (shouldStopPropagation)
                {
                    evt.StopPropagation();
                }

                clickList.Add("up:child" + index);
            }
Exemple #12
0
            public void OnAnyMouseDown(MouseInputEvent evt)
            {
                if (shouldStopPropagation)
                {
                    evt.StopPropagation();
                }

                clickList.Add("down:root");
                wasMouseDown = true;
            }
Exemple #13
0
 public InventoryItemDragEvent(MouseInputEvent evt, InventoryItem item)
 {
     this.item   = item;
     itemElement = evt.element;
     offset      = evt.MousePosition - itemElement.layoutResult.screenPosition;
     itemElement.style.SetAlignmentTargetX(AlignmentTarget.Mouse, StyleState.Normal);
     itemElement.style.SetAlignmentTargetY(AlignmentTarget.Mouse, StyleState.Normal);
     itemElement.style.SetAlignmentOffsetX(-offset.x, StyleState.Normal);
     itemElement.style.SetAlignmentOffsetY(-offset.y, StyleState.Normal);
 }
Exemple #14
0
        public virtual DragEvent OnCreateVerticalDrag(MouseInputEvent evt)
        {
            if (evt.IsMouseRightDown)
            {
                return(null);
            }
            float baseOffset = evt.MousePosition.y - (evt.element.layoutResult.screenPosition.y);

            return(new ScrollbarDragEvent(ScrollbarOrientation.Vertical, new Vector2(0, baseOffset), this));
        }
Exemple #15
0
        public virtual DragEvent OnCreateHorizontalDrag(MouseInputEvent evt)
        {
            if (evt.IsMouseRightDown)
            {
                return(null);
            }
            float baseOffset = evt.MousePosition.x - evt.element.layoutResult.screenPosition.x;

            return(new ScrollbarDragEvent(ScrollbarOrientation.Horizontal, new Vector2(baseOffset, 0), this));
        }
Exemple #16
0
        public void OnMouseWheel(MouseInputEvent evt)
        {
            if (verticalScrollingEnabled)
            {
                float actualContentHeight  = children[0].layoutResult.actualSize.height;
                float visibleContentHeight = layoutResult.ActualHeight;
                if (!isScrollingY || (int)Mathf.Sign(evt.ScrollDelta.y) != (int)Mathf.Sign(fromScrollY - toScrollY))
                {
                    accumulatedScrollSpeedY = scrollSpeedY;
                }
                else
                {
                    accumulatedScrollSpeedY *= 1.2f;
                }
                scrollDeltaY = -evt.ScrollDelta.y * accumulatedScrollSpeedY / (actualContentHeight - visibleContentHeight);
                fromScrollY  = scrollPercentageY;
                if (scrollDeltaY != 0)
                {
                    toScrollY = Mathf.Clamp01(fromScrollY + scrollDeltaY);
                    if (fromScrollY != toScrollY)
                    {
                        evt.StopPropagation();
                        elapsedTotalTime = 0;
                        isScrollingY     = true;
                    }
                }
            }

            if (horizontalScrollingEnabled)
            {
                float actualContentWidth  = children[0].layoutResult.actualSize.width;
                float visibleContentWidth = layoutResult.ActualWidth;
                if (!isScrollingX || (int)Mathf.Sign(-evt.ScrollDelta.x) != (int)Mathf.Sign(fromScrollX - toScrollX))
                {
                    accumulatedScrollSpeedX = scrollSpeedX;
                }
                else
                {
                    accumulatedScrollSpeedX *= 1.2f;
                }
                scrollDeltaX = evt.ScrollDelta.x * accumulatedScrollSpeedX / (actualContentWidth - visibleContentWidth);
                if (scrollDeltaX != 0)
                {
                    fromScrollX = scrollPercentageX;
                    toScrollX   = Mathf.Clamp01(fromScrollX + scrollDeltaX);
                    if (fromScrollX != toScrollX)
                    {
                        evt.StopPropagation();
                        elapsedTotalTime = 0;
                        isScrollingX     = true;
                    }
                }
            }
        }
Exemple #17
0
        public void Decrement(MouseInputEvent evt)
        {
            evt.StopPropagation();
            keyLockTimestamp = Time.unscaledTime;
            if (inputElement.HasDisabledAttr())
            {
                return;
            }

            Decrement();
        }
Exemple #18
0
//        public readonly DragEventCreator[] creators;
//
//        public DragCreatorGroup(DragEventCreator[] creators) {
//            this.creators = creators;
//        }

        public DragEvent TryCreateEvent(object target, MouseInputEvent mouseEvent)
        {
//            for (int i = 0; i < creators.Length; i++) {
//                DragEvent evt = creators[i].Invoke(target, mouseEvent);
//                if (evt != null) {
//                    return evt;
//                }
//            }

            return(null);
        }
Exemple #19
0
        void HandleMouseInput()
        {
            MouseInputEvent mouseEvent = new MouseInputEvent();

            mouseEvent.x = TranslateGlobalXToLocalX(m_inputFrame.MousePosition.x);
            mouseEvent.y = TranslateGlobalYToLocalY(m_inputFrame.MousePosition.y);
            mouseEvent.z = m_inputFrame.MouseWheelDelta;

            const int mousePointerId     = -1;
            bool      shouldConsumeTouch = ShouldConsumeTouch(mousePointerId);

            //Left Button
            if (m_inputFrame.IsLeftDown && shouldConsumeTouch)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MousePrimaryDown);
            }
            if (m_inputFrame.IsLeftUp)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MousePrimaryUp);
            }

            //Right Button
            if (m_inputFrame.IsRightDown && shouldConsumeTouch)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MouseSecondaryDown);
            }
            if (m_inputFrame.IsRightUp)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MouseSecondaryUp);
            }

            //Middle Button
            if (m_inputFrame.IsMiddleDown && shouldConsumeTouch)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MouseMiddleDown);
            }
            if (m_inputFrame.IsMiddleUp)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MouseMiddleUp);
            }

            //Mouse Wheel
            if (m_inputFrame.MouseWheelDelta != 0 && shouldConsumeTouch)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MouseWheel);
            }

            if (m_inputFrame.HasMouseMoved)
            {
                SendActionToHandler(mouseEvent, MouseInputAction.MouseMove);
            }
        }
Exemple #20
0
            public void OnMouseHover(MouseInputEvent evt)
            {
                if (ignoreHover)
                {
                    return;
                }
                if (shouldStopPropagation)
                {
                    evt.StopPropagation();
                }

                clickList.Add("hover:root");
            }
Exemple #21
0
            public void OnMouseMove(MouseInputEvent evt)
            {
                if (ignoreMove)
                {
                    return;
                }
                if (shouldStopPropagation)
                {
                    evt.StopPropagation();
                }

                clickList.Add("move:root");
            }
        void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
        {
            var button = ConvertMouseButtonFromOpenTK(e.Button);
            var buttonId = (int)button;

            CurrentMousePosition = new Vector2(e.X / ControlWidth, e.Y / ControlHeight);
            var mouseInputEvent = new MouseInputEvent { Type = InputEventType.Down, MouseButton = button };
            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            MouseButtonCurrentlyDown[buttonId] = true;
            HandlePointerEvents(buttonId, CurrentMousePosition, PointerState.Down, PointerType.Mouse);
        }
Exemple #23
0
        void HandleMouseInput()
        {
            MouseInputEvent mouseEvent = new MouseInputEvent();

            mouseEvent.x = TranslateGlobalXToLocalX(m_inputFrame.MousePosition.x);
            mouseEvent.y = TranslateGlobalYToLocalY(m_inputFrame.MousePosition.y);
            mouseEvent.z = m_inputFrame.MouseWheelDelta;

            SendActionDelegate HandleMouseAction = _action => SendActionToHandler(mouseEvent, _action);

            //Left Button
            if (m_inputFrame.IsLeftDown && m_inputFrame.ShouldHandleEventsThisFrame)
            {
                HandleMouseAction(MouseInputAction.MousePrimaryDown);
            }
            if (m_inputFrame.IsLeftUp)
            {
                HandleMouseAction(MouseInputAction.MousePrimaryUp);
            }

            //Right Button
            if (m_inputFrame.IsRightDown && m_inputFrame.ShouldHandleEventsThisFrame)
            {
                HandleMouseAction(MouseInputAction.MouseSecondaryDown);
            }
            if (m_inputFrame.IsRightUp)
            {
                HandleMouseAction(MouseInputAction.MouseSecondaryUp);
            }

            //Middle Button
            if (m_inputFrame.IsMiddleDown && m_inputFrame.ShouldHandleEventsThisFrame)
            {
                HandleMouseAction(MouseInputAction.MouseMiddleDown);
            }
            if (m_inputFrame.IsMiddleUp)
            {
                HandleMouseAction(MouseInputAction.MouseMiddleUp);
            }

            //Mouse Wheel
            if (m_inputFrame.MouseWheelDelta != 0 && m_inputFrame.ShouldHandleEventsThisFrame)
            {
                HandleMouseAction(MouseInputAction.MouseWheel);
            }

            if (m_inputFrame.HasMouseMoved)
            {
                HandleMouseAction(MouseInputAction.MouseMove);
            }
        }
Exemple #24
0
        void HandleMouseInput()
        {
            MouseInputEvent mouseEvent = new MouseInputEvent();

            mouseEvent.x = m_inputFrame.MousePosition.x;
            mouseEvent.y = m_inputFrame.MousePosition.y;
            mouseEvent.z = m_inputFrame.MouseWheelDelta;

            SendActionDelegate HandleMouseAction = _action => SendActionToHandler(mouseEvent, _action);

            //Left Button
            if (m_inputFrame.IsLeftDown)
            {
                HandleMouseAction(MouseInputAction.MousePrimaryDown);
            }
            if (m_inputFrame.IsLeftUp)
            {
                HandleMouseAction(MouseInputAction.MousePrimaryUp);
            }

            //Right Button
            if (m_inputFrame.IsRightDown)
            {
                HandleMouseAction(MouseInputAction.MouseSecondaryDown);
            }
            if (m_inputFrame.IsRightUp)
            {
                HandleMouseAction(MouseInputAction.MouseSecondaryUp);
            }

            //Middle Button
            if (m_inputFrame.IsMiddleDown)
            {
                HandleMouseAction(MouseInputAction.MouseMiddleDown);
            }
            if (m_inputFrame.IsMiddleUp)
            {
                HandleMouseAction(MouseInputAction.MouseMiddleUp);
            }

            //Mouse Wheel
            if (m_inputFrame.MouseWheelDelta != 0)
            {
                HandleMouseAction(MouseInputAction.MouseWheel);
            }

            if (m_inputFrame.HasMouseMoved)
            {
                HandleMouseAction(MouseInputAction.MouseMove);
            }
        }
Exemple #25
0
            public void HandleMouseEnterChild(MouseInputEvent evt, int index)
            {
                if (ignoreEnter)
                {
                    return;
                }
                clickedChildIndex = index;
                if (shouldStopPropagation)
                {
                    evt.StopPropagation();
                }

                clickList.Add("enter:child" + index);
            }
Exemple #26
0
            public void MouseExit(MouseInputEvent evt)
            {
                if (ignoreExit)
                {
                    return;
                }
                if (shouldStopPropagation)
                {
                    evt.StopPropagation();
                }

                clickList.Add("exit:root");
                wasMouseDown = true;
            }
Exemple #27
0
        void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
        {
            var button   = ConvertMouseButtonFromOpenTK(e.Button);
            var buttonId = (int)button;

            CurrentMousePosition = new Vector2(e.X / ControlWidth, e.Y / ControlHeight);
            var mouseInputEvent = new MouseInputEvent {
                Type = InputEventType.Down, MouseButton = button
            };

            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            MouseButtonCurrentlyDown[buttonId] = true;
            HandlePointerEvents(buttonId, CurrentMousePosition, PointerState.Down, PointerType.Mouse);
        }
        void Mouse_ButtonUp(object sender, MouseButtonEventArgs e)
        {
            var button = ConvertMouseButtonFromOpenTK(e.Button);
            var buttonId = (int)button;

            // the mouse events series has been interrupted because out of the window.
            if (!MouseButtonCurrentlyDown[buttonId])
                return;
            
            CurrentMousePosition = new Vector2(e.X / ControlWidth, e.Y / ControlHeight);
            var mouseInputEvent = new MouseInputEvent { Type = InputEventType.Up, MouseButton = button };
            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            MouseButtonCurrentlyDown[buttonId] = false;
            HandlePointerEvents(buttonId, CurrentMousePosition, PointerState.Up, PointerType.Mouse);
        }
Exemple #29
0
        public void BeginSelecting(MouseInputEvent evt)
        {
            if (disabled)
            {
                return;
            }

            if (selecting)
            {
                InputSystem.ReleaseFocus(this);
                selecting = false;
            }
            else
            {
                selecting = InputSystem.RequestFocus(this);
            }

            AdjustOptionPosition();

            evt.StopPropagation();
            evt.Consume();
        }
Exemple #30
0
        void Mouse_ButtonUp(object sender, MouseButtonEventArgs e)
        {
            var button   = ConvertMouseButtonFromOpenTK(e.Button);
            var buttonId = (int)button;

            // the mouse events series has been interrupted because out of the window.
            if (!MouseButtonCurrentlyDown[buttonId])
            {
                return;
            }

            CurrentMousePosition = new Vector2(e.X / ControlWidth, e.Y / ControlHeight);
            var mouseInputEvent = new MouseInputEvent {
                Type = InputEventType.Up, MouseButton = button
            };

            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            MouseButtonCurrentlyDown[buttonId] = false;
            HandlePointerEvents(buttonId, CurrentMousePosition, PointerState.Up, PointerType.Mouse);
        }
Exemple #31
0
        public DragEvent OnMiddleMouseDrag(MouseInputEvent evt)
        {
            if (!evt.IsMouseMiddleDown)
            {
                return(null);
            }

            Vector2 baseOffset = new Vector2();
            ScrollbarOrientation orientation = 0;

            if (horizontalScrollingEnabled)
            {
                baseOffset.x = evt.MousePosition.x - horizontalHandle.layoutResult.screenPosition.x;
                orientation |= ScrollbarOrientation.Horizontal;
            }

            if (verticalScrollingEnabled)
            {
                baseOffset.y = evt.MousePosition.y - verticalHandle.layoutResult.screenPosition.y;
                orientation |= ScrollbarOrientation.Vertical;
            }

            return(new ScrollbarDragEvent(orientation, baseOffset, this));
        }
        void HandlePointerEvent(WinRTPointerPoint p, PointerState ptrState)
        {
            var pointerType = ConvertPointerDeviceType(p.PointerDevice.PointerDeviceType);
            var isMouse     = pointerType == PointerType.Mouse;
            var position    = NormalizeScreenPosition(PointToVector2(p.Position));

            if (isMouse)
            {
                if (ptrState == PointerState.Cancel || ptrState == PointerState.Out)
                {
                    // invalidate mouse and current pointers
                    LostFocus = true;

                    for (int i = 0; i < MouseButtonCurrentlyDown.Length; i++)
                    {
                        if (MouseButtonCurrentlyDown[i])
                        {
                            HandlePointerEvents(i, position, PointerState.Out, pointerType);
                            MouseButtonCurrentlyDown[i] = false;
                        }
                    }
                }
                else // down/up/move
                {
                    // Note: The problem here is that the PointerPressed event is not triggered twice when two button are pressed together.
                    // That is why we are forced to continuously keep the state of all buttons of the mouse.

                    MouseInputEvent mouseEvent;

                    // Trigger mouse button and pointer Down events for newly pressed buttons.
                    foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
                    {
                        var buttonId = (int)button;
                        if (!MouseButtonCurrentlyDown[buttonId] && MouseButtonIsPressed(p.Properties, button))
                        {
                            lock (MouseInputEvents)
                            {
                                mouseEvent = new MouseInputEvent {
                                    Type = InputEventType.Down, MouseButton = button
                                };
                                MouseInputEvents.Add(mouseEvent);
                            }

                            HandlePointerEvents(buttonId, position, PointerState.Down, pointerType);

                            MouseButtonCurrentlyDown[buttonId] = true;
                        }
                    }

                    // Trigger Move events to pointer that have changed position
                    if (CurrentMousePosition != position)
                    {
                        foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
                        {
                            var buttonId = (int)button;
                            if (MouseButtonCurrentlyDown[buttonId])
                            {
                                HandlePointerEvents(buttonId, position, PointerState.Move, pointerType);
                            }
                        }
                    }

                    // Trigger mouse button and pointer Up events for newly released buttons.
                    foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
                    {
                        var buttonId = (int)button;
                        if (MouseButtonCurrentlyDown[buttonId] && !MouseButtonIsPressed(p.Properties, button))
                        {
                            lock (MouseInputEvents)
                            {
                                mouseEvent = new MouseInputEvent {
                                    Type = InputEventType.Up, MouseButton = button
                                };
                                MouseInputEvents.Add(mouseEvent);
                            }

                            HandlePointerEvents(buttonId, position, PointerState.Up, pointerType);

                            MouseButtonCurrentlyDown[buttonId] = false;
                        }
                    }

                    // Trigger mouse wheel events
                    if (Math.Abs(p.Properties.MouseWheelDelta) > MathUtil.ZeroTolerance)
                    {
                        lock (MouseInputEvents)
                        {
                            mouseEvent = new MouseInputEvent {
                                Type = InputEventType.Wheel, MouseButton = MouseButton.Middle, Value = p.Properties.MouseWheelDelta
                            };
                            MouseInputEvents.Add(mouseEvent);
                        }
                    }
                }

                // Update mouse cursor position
                CurrentMousePosition = position;
            }
            else
            {
                HandlePointerEvents((int)p.PointerId, position, ptrState, pointerType);
            }
        }
        void HandlePointerEvent(WinRTPointerPoint p, PointerState ptrState)
        {
            var pointerType = ConvertPointerDeviceType(p.PointerDevice.PointerDeviceType);
            var isMouse = pointerType == PointerType.Mouse;
            var position = NormalizeScreenPosition(PointToVector2(p.Position));

            if (isMouse)
            {
                if (ptrState == PointerState.Cancel || ptrState == PointerState.Out)
                {
                    // invalidate mouse and current pointers
                    LostFocus = true;

                    for (int i = 0; i < MouseButtonCurrentlyDown.Length; i++)
                    {
                        if (MouseButtonCurrentlyDown[i])
                        {
                            HandlePointerEvents(i, position, PointerState.Out, pointerType);
                            MouseButtonCurrentlyDown[i] = false;
                        }
                    }
                }
                else // down/up/move
                {
                    // Note: The problem here is that the PointerPressed event is not triggered twice when two button are pressed together.
                    // That is why we are forced to continuously keep the state of all buttons of the mouse.

                    MouseInputEvent mouseEvent;

                    // Trigger mouse button and pointer Down events for newly pressed buttons.
                    foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
                    {
                        var buttonId = (int)button;
                        if (!MouseButtonCurrentlyDown[buttonId] && MouseButtonIsPressed(p.Properties, button))
                        {
                            lock (MouseInputEvents)
                            {
                                mouseEvent = new MouseInputEvent { Type = InputEventType.Down, MouseButton = button };
                                MouseInputEvents.Add(mouseEvent);
                            }

                            HandlePointerEvents(buttonId, position, PointerState.Down, pointerType);

                            MouseButtonCurrentlyDown[buttonId] = true;
                        }
                    }

                    // Trigger Move events to pointer that have changed position
                    if (CurrentMousePosition != position)
                    {
                        foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
                        {
                            var buttonId = (int)button;
                            if (MouseButtonCurrentlyDown[buttonId])
                                HandlePointerEvents(buttonId, position, PointerState.Move, pointerType);
                        } 
                    }

                    // Trigger mouse button and pointer Up events for newly released buttons.
                    foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
                    {
                        var buttonId = (int)button;
                        if (MouseButtonCurrentlyDown[buttonId] && !MouseButtonIsPressed(p.Properties, button))
                        {
                            lock (MouseInputEvents)
                            {
                                mouseEvent = new MouseInputEvent { Type = InputEventType.Up, MouseButton = button };
                                MouseInputEvents.Add(mouseEvent);
                            }

                            HandlePointerEvents(buttonId, position, PointerState.Up, pointerType);

                            MouseButtonCurrentlyDown[buttonId] = false;
                        }
                    }

                    // Trigger mouse wheel events
                    if (Math.Abs(p.Properties.MouseWheelDelta) > MathUtil.ZeroTolerance)
                    {
                        lock (MouseInputEvents)
                        {
                            mouseEvent = new MouseInputEvent { Type = InputEventType.Wheel, MouseButton = MouseButton.Middle, Value = p.Properties.MouseWheelDelta };
                            MouseInputEvents.Add(mouseEvent);
                        }
                    }
                }

                // Update mouse cursor position
                CurrentMousePosition = position;
            }
            else
            {
                HandlePointerEvents((int)p.PointerId, position, ptrState, pointerType);
            }
        }
        private void OnMouseInputEvent(Vector2 pixelPosition, MouseButton button, InputEventType type, float value = 0)
        {
            // The mouse wheel event are still received even when the mouse cursor is out of the control boundaries. Discard the event in this case.
            if (type == InputEventType.Wheel && !uiControl.ClientRectangle.Contains(uiControl.PointToClient(Control.MousePosition)))
                return;

            // the mouse events series has been interrupted because out of the window.
            if (type == InputEventType.Up && !MouseButtonCurrentlyDown[(int)button])
                return;

            CurrentMousePosition = NormalizeScreenPosition(pixelPosition);

            var mouseInputEvent = new MouseInputEvent { Type = type, MouseButton = button, Value = value};
            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            if (type != InputEventType.Wheel)
            {
                var buttonId = (int)button;
                MouseButtonCurrentlyDown[buttonId] = type == InputEventType.Down;
                HandlePointerEvents(buttonId, CurrentMousePosition, InputEventTypeToPointerState(type), PointerType.Mouse);
            }
        }
Exemple #35
0
 public MouseInput( MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods )
 {
     this.Event = ev;
     this.Button = button;
     this.Location = location;
     this.Modifiers = mods;
 }
 public MouseInput( MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods, int multiTapCount )
 {
     this.Event = ev;
     this.Button = button;
     this.Location = location;
     this.Modifiers = mods;
     this.MultiTapCount = multiTapCount;
 }
Exemple #37
0
 void SendActionToHandler(MouseInputEvent mouseEvent, MouseInputAction action)
 {
     mouseEvent.Action = action;
     m_mouseInputProcessor.HandleInput(mouseEvent);
 }