コード例 #1
0
        /// <summary>
        /// Gets mouse position.
        /// </summary>
        /// <param name="isCurrent">Whether or not to return the current or previous mouse position.</param>
        /// <returns></returns>
        public static Vector2 GetMousePosition(bool isCurrent = true)
        {
            var mouseState = isCurrent ? Mouse.GetState() : _previousMouseState;
            var position   = mouseState.Position;

            return(new Vector2(position.X, position.Y));
        }
コード例 #2
0
        public void Update()
        {
            var mouse = Mouse.GetState();

            if (mouse.RightButton == ButtonState.Pressed)
            {
                if (_mouseClickEventHandler != null)
                {
                    _mouseClickEventHandler(this, new MouseClickEventArgs(new Vector2(mouse.X, mouse.Y)));
                }
            }

            if (mouse.LeftButton == ButtonState.Pressed && !_mouseDown)
            {
                _mouseDown       = true;
                _position        = new Vector2(mouse.X, mouse.Y);
                _selectCorner    = _position;
                _selectRectangle = new Rectangle((int)_position.X, (int)_position.Y, 0, 0);
            }
            else if (mouse.LeftButton == ButtonState.Pressed)
            {
                _selectCorner = new Vector2(mouse.X, mouse.Y);
                if (_selectCorner.X > _position.X)
                {
                    _selectRectangle.X = (int)_position.X;
                }
                else
                {
                    _selectRectangle.X = (int)_selectCorner.X;
                }


                if (_selectCorner.Y > _position.Y)
                {
                    _selectRectangle.Y = (int)_position.Y;
                }
                else
                {
                    _selectRectangle.Y = (int)_selectCorner.Y;
                }

                _selectRectangle.Width  = (int)Math.Abs(_position.X - _selectCorner.X);
                _selectRectangle.Height = (int)Math.Abs(_position.Y - _selectCorner.Y);
            }
            else
            {
                if (_mouseEventHandler != null)
                {
                    _mouseEventHandler(this, new MouseEventArgs(_selectRectangle));
                }
                _mouseDown = false;
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates current and previous input states across all input devices.
        /// </summary>
        internal static void Update()
        {
            _previousMouseState    = _mouseState;
            _previousKeyboardState = _keyboardState;
            _keyboardState         = Keyboard.GetState();
            _mouseState            = Mouse.GetState();

            for (int i = 0; i < 4; i++)
            {
                var playerIndex = GetPlayerIndex(i);

                _previousGamePadStates[i] = _gamePadStates[i];
                _gamePadStates[i]         = GamePad.GetState(playerIndex);
            }
        }
コード例 #4
0
 /// <summary>
 /// Sets the mouse position to the given coordinates.
 /// </summary>
 /// <param name="x">New X position for the mouse.</param>
 /// <param name="y">New Y position for the mouse.</param>
 public static void SetMousePosition(int x, int y)
 {
     Mouse.SetPosition(x, y);
 }