Exemplo n.º 1
0
        private void updateMouseEvents(InputState state)
        {
            MouseState mouse = (MouseState)state.Mouse;

            var last = state.Last?.Mouse as MouseState;

            if (last == null)
            {
                return;
            }

            if (mouse.Position != last.Position)
            {
                handleMouseMove(state);
                if (isDragging)
                {
                    handleMouseDrag(state);
                }
            }

            for (MouseButton b = 0; b < MouseButton.LastButton; b++)
            {
                var lastPressed = last.IsPressed(b);

                if (lastPressed != mouse.IsPressed(b))
                {
                    if (lastPressed)
                    {
                        handleMouseUp(state, b);
                    }
                    else
                    {
                        handleMouseDown(state, b);
                    }
                }
            }

            if (mouse.WheelDelta != 0)
            {
                handleWheel(state);
            }

            if (mouse.HasAnyButtonPressed)
            {
                if (!last.HasAnyButtonPressed)
                {
                    //stuff which only happens once after the mousedown state
                    mouse.PositionMouseDown = state.Mouse.Position;
                    LastActionTime          = Time.Current;

                    if (mouse.IsPressed(MouseButton.Left))
                    {
                        isValidClick = true;

                        if (Time.Current - lastClickTime < double_click_time)
                        {
                            if (handleMouseDoubleClick(state))
                            {
                                //when we handle a double-click we want to block a normal click from firing.
                                isValidClick = false;
                            }

                            lastClickTime = 0;
                        }

                        lastClickTime = Time.Current;
                    }
                }

                if (!isDragging && Vector2.Distance(mouse.PositionMouseDown ?? mouse.Position, mouse.Position) > drag_start_distance)
                {
                    isDragging = true;
                    handleMouseDragStart(state);
                }
            }
            else if (last.HasAnyButtonPressed)
            {
                if (isValidClick && (draggingDrawable == null || Vector2.Distance(mouse.PositionMouseDown ?? mouse.Position, mouse.Position) < click_drag_distance))
                {
                    handleMouseClick(state);
                }

                mouseDownInputQueue     = null;
                mouse.PositionMouseDown = null;
                isValidClick            = false;

                if (isDragging)
                {
                    isDragging = false;
                    handleMouseDragEnd(state);
                }
            }
        }
Exemplo n.º 2
0
        private void updateMouseEvents(InputState state)
        {
            MouseState mouse = (MouseState)state.Mouse;

            if (!(state.Last.Mouse is MouseState last))
            {
                return;
            }

            mouse.LastPosition      = last.Position;
            mouse.LastScroll        = last.Scroll;
            mouse.PositionMouseDown = last.PositionMouseDown;

            if (mouse.Position != last.Position)
            {
                handleMouseMove(state);
                if (isDragging)
                {
                    handleMouseDrag(state);
                }
            }

            for (MouseButton b = 0; b < MouseButton.LastButton; b++)
            {
                var lastPressed = last.IsPressed(b);

                if (lastPressed != mouse.IsPressed(b))
                {
                    if (lastPressed)
                    {
                        handleMouseUp(state, b);
                    }
                    else
                    {
                        handleMouseDown(state, b);
                    }
                }
            }

            if (mouse.ScrollDelta != Vector2.Zero && (Host.Window?.CursorInWindow ?? true))
            {
                handleScroll(state);
            }

            if (mouse.HasAnyButtonPressed)
            {
                if (!last.HasAnyButtonPressed)
                {
                    //stuff which only happens once after the mousedown state
                    mouse.PositionMouseDown = mouse.Position;
                    LastActionTime          = Time.Current;

                    if (mouse.IsPressed(MouseButton.Left))
                    {
                        isValidClick = true;

                        if (Time.Current - lastClickTime < double_click_time)
                        {
                            if (handleMouseDoubleClick(state))
                            {
                                //when we handle a double-click we want to block a normal click from firing.
                                isValidClick = false;
                            }

                            lastClickTime = 0;
                        }
                        else
                        {
                            lastClickTime = Time.Current;
                        }
                    }
                }

                if (!isDragging && Vector2Extensions.Distance(mouse.PositionMouseDown ?? mouse.Position, mouse.Position) > click_drag_distance)
                {
                    isDragging = true;
                    handleMouseDragStart(state);
                }
            }
            else if (last.HasAnyButtonPressed)
            {
                if (isValidClick && (DraggedDrawable == null || Vector2Extensions.Distance(last.PositionMouseDown ?? last.Position, mouse.Position) <= click_drag_distance))
                {
                    handleMouseClick(state);
                }

                mouseDownInputQueue     = null;
                mouse.PositionMouseDown = null;
                isValidClick            = false;

                if (isDragging)
                {
                    isDragging = false;
                    handleMouseDragEnd(state);
                }
            }
        }