コード例 #1
0
        public static void InvokeEvents()
        {
            if (OnLeftButtonDown != null && IsButtonDown(MouseButton.Left))
            {
                OnLeftButtonDown.Invoke(currentState);
            }
            if (OnLeftButtonPressed != null && IsButtonPressed(MouseButton.Left))
            {
                OnLeftButtonPressed.Invoke(currentState);
            }
            if (OnLeftButtonReleased != null && IsButtonReleased(MouseButton.Left))
            {
                OnLeftButtonReleased.Invoke(currentState);
            }

            if (OnRightButtonDown != null && IsButtonDown(MouseButton.Right))
            {
                OnRightButtonDown.Invoke(currentState);
            }
            if (OnRightButtonPressed != null && IsButtonPressed(MouseButton.Right))
            {
                OnRightButtonPressed.Invoke(currentState);
            }
            if (OnRightButtonReleased != null && IsButtonReleased(MouseButton.Right))
            {
                OnRightButtonReleased.Invoke(currentState);
            }

            if (OnMiddleButtonDown != null && IsButtonDown(MouseButton.Middle))
            {
                OnMiddleButtonDown.Invoke(currentState);
            }
            if (OnMiddleButtonPressed != null && IsButtonPressed(MouseButton.Middle))
            {
                OnMiddleButtonPressed.Invoke(currentState);
            }
            if (OnMiddleButtonReleased != null && IsButtonReleased(MouseButton.Middle))
            {
                OnMiddleButtonReleased.Invoke(currentState);
            }

            if (OnXButton1Down != null && IsButtonDown(MouseButton.XButton1))
            {
                OnXButton1Down.Invoke(currentState);
            }
            if (OnXButton1Pressed != null && IsButtonPressed(MouseButton.XButton1))
            {
                OnXButton1Pressed.Invoke(currentState);
            }
            if (OnXButton1Released != null && IsButtonReleased(MouseButton.XButton1))
            {
                OnXButton1Released.Invoke(currentState);
            }

            if (OnXButton2Down != null && IsButtonDown(MouseButton.XButton2))
            {
                OnXButton2Down.Invoke(currentState);
            }
            if (OnXButton2Pressed != null && IsButtonPressed(MouseButton.XButton2))
            {
                OnXButton2Pressed.Invoke(currentState);
            }
            if (OnXButton2Released != null && IsButtonReleased(MouseButton.XButton2))
            {
                OnXButton2Released.Invoke(currentState);
            }

            if (OnButtonDown != null && IsButtonDown(MouseButton.Any))
            {
                OnButtonDown.Invoke(currentState, GetDownButtons());
            }
            if (OnButtonPressed != null && IsButtonPressed(MouseButton.Any))
            {
                OnButtonPressed.Invoke(currentState, GetPressedButtons());
            }
            if (OnButtonReleased != null && IsButtonReleased(MouseButton.Any))
            {
                OnButtonReleased.Invoke(currentState, GetReleasedButtons());
            }

            if (OnMouseWheelUp != null && IsMouseWheelUp())
            {
                OnMouseWheelUp.Invoke(currentState);
            }
            if (OnMouseWheelDown != null && IsMouseWheelDown())
            {
                OnMouseWheelDown.Invoke(currentState);
            }

            if (OnMouseMove != null && IsMouseMoving())
            {
                OnMouseMove.Invoke(currentState, GetMoveDirection());
            }
        }
コード例 #2
0
        public void Update()
        {
            #region Keybaord
            KeyboardState      keyboardState  = Keyboard.GetState();
            Keys[]             keyPressed     = keyboardState.GetPressedKeys();
            IEnumerable <Keys> keyJustPressed = keyPressed.Where(key => !_pressedKeys.Any(k => k == key));

            foreach (Keys key in keyJustPressed)
            {
                OnKeyDown(null, key);
            }

            IEnumerable <Keys> keyJustUpped = _pressedKeys.Where(key => !keyPressed.Any(k => k == key));

            foreach (Keys key in keyJustUpped)
            {
                OnKeyUp(null, key);
            }
            _pressedKeys = keyPressed;
            #endregion Keybaord

            #region Mouse
            MouseState mouseState = Mouse.GetState();
            if (mouseState.LeftButton != _previousLeftButtonState)
            {
                _previousLeftButtonState = mouseState.LeftButton;
                if (_previousLeftButtonState == ButtonState.Pressed)
                {
                    OnMouseLeftButtonDown(this, mouseState);
                }
                else
                {
                    OnMouseLeftButtonUp(this, mouseState);
                }
            }

            if (mouseState.RightButton != _previousRightButtonState)
            {
                _previousRightButtonState = mouseState.RightButton;
                if (_previousRightButtonState == ButtonState.Pressed)
                {
                    OnMouseRightButtonDown(this, mouseState);
                }
                else
                {
                    OnMouseRightButtonUp(this, mouseState);
                }
            }

            if (mouseState.ScrollWheelValue != _previousScrollValue)
            {
                if (mouseState.ScrollWheelValue < _previousScrollValue)
                {
                    OnMouseWheelUp?.Invoke(this, mouseState);
                }
                else
                {
                    OnMouseWheelDown?.Invoke(this, mouseState);
                }
                _previousScrollValue = mouseState.ScrollWheelValue;
            }
            #endregion Mouse
        }