Пример #1
0
        void UpdateMouseStates()
        {
            currentMousePosition.X = CurrentMouseState.X;
            currentMousePosition.Y = CurrentMouseState.Y;

            prevMousePosition.X = LastMouseState.X;
            prevMousePosition.Y = LastMouseState.Y;

            if (mouseGestureType.HasFlag(MouseGestureType.LeftClick))
            {
                mouseGestureType = mouseGestureType ^ MouseGestureType.LeftClick;
            }

            if (mouseGestureType.HasFlag(MouseGestureType.Move))
            {
                mouseGestureType = mouseGestureType ^ MouseGestureType.Move;
            }

            if (MouseDelta.Length() != 0)
            {
                mouseGestureType = mouseGestureType | MouseGestureType.Move;
            }

            // If we were dragging and the left mouse button was released
            // then we are no longer dragging and need to throw the banana.
            if (CurrentMouseState.LeftButton == ButtonState.Released &&
                dragging)
            {
                leftMouseDown     = false;
                dragging          = false;
                dragComplete      = true;
                dragMouseEnd      = currentMousePosition;
                mouseGestureType |= MouseGestureType.DragComplete;
                mouseGestureType  = mouseGestureType ^ MouseGestureType.FreeDrag;
                //Console.WriteLine ("Dragging: " + mouseGestureType);
            }

            // Let's set the left mouse down and the mouse origin
            if (!leftMouseDown && CurrentMouseState.LeftButton == ButtonState.Pressed &&
                !CurrentMouseState.Equals(LastMouseState))
            {
                //Console.WriteLine ("left down");
                leftMouseDown  = true;
                dragComplete   = false;
                dragMouseStart = currentMousePosition;
            }

            if (leftMouseDown && CurrentMouseState.LeftButton == ButtonState.Released &&
                !CurrentMouseState.Equals(LastMouseState))
            {
                leftMouseDown     = false;
                mouseGestureType |= MouseGestureType.LeftClick;
            }

            // Here we test the distance and if over the threshold then we set the dragging to true
            //  Current threshold is 5 pixels.
            if (leftMouseDown && !dragging)
            {
                Vector2 delta = dragMouseStart - currentMousePosition;

                if (delta.Length() > dragThreshold)
                {
                    dragging         = true;
                    dragMouseStart   = currentMousePosition;
                    mouseGestureType = mouseGestureType | MouseGestureType.FreeDrag;
                    //Console.WriteLine ("Dragging: " + mouseGestureType);
                }
            }

            //Console.WriteLine(mouseGestureType);
        }
Пример #2
0
        void UpdateMouseStates()
        {
            currentMousePosition.X = CurrentMouseState.X;
            currentMousePosition.Y = CurrentMouseState.Y;

            prevMousePosition.X = LastMouseState.X;
            prevMousePosition.Y = LastMouseState.Y;

            if (mouseGestureType.HasFlag(MouseGestureType.LeftClick))
            {
                mouseGestureType = mouseGestureType ^ MouseGestureType.LeftClick;
            }

            if (mouseGestureType.HasFlag(MouseGestureType.Move))
            {
                mouseGestureType = mouseGestureType ^ MouseGestureType.Move;
            }

            if (MouseDelta.Length() != 0)
            {
                mouseGestureType = mouseGestureType | MouseGestureType.Move;
            }


            if (CurrentMouseState.LeftButton == ButtonState.Released &&
                dragging)
            {
                leftMouseDown     = false;
                dragging          = false;
                dragComplete      = true;
                dragMouseEnd      = currentMousePosition;
                mouseGestureType |= MouseGestureType.DragComplete;
                mouseGestureType  = mouseGestureType ^ MouseGestureType.FreeDrag;
            }


            if (!leftMouseDown && CurrentMouseState.LeftButton == ButtonState.Pressed &&
                !CurrentMouseState.Equals(LastMouseState))
            {
                leftMouseDown  = true;
                dragComplete   = false;
                dragMouseStart = currentMousePosition;
            }

            if (leftMouseDown && CurrentMouseState.LeftButton == ButtonState.Released &&
                !CurrentMouseState.Equals(LastMouseState))
            {
                leftMouseDown     = false;
                mouseGestureType |= MouseGestureType.LeftClick;
            }


            if (leftMouseDown && !dragging)
            {
                Vector2 delta = dragMouseStart - currentMousePosition;

                if (delta.Length() > dragThreshold)
                {
                    dragging         = true;
                    dragMouseStart   = currentMousePosition;
                    mouseGestureType = mouseGestureType | MouseGestureType.FreeDrag;
                }
            }
        }