예제 #1
0
 private void CheckButton(int buttonId)
 {
     _bOldState = (_oldState & buttonId) == buttonId;
     _bNewState = (_state & buttonId) == buttonId;
     if (!_bOldState && _bNewState)
     {
         OnButtonPressed?.Invoke(this, buttonId);
     }
     if (_bOldState && !_bNewState)
     {
         OnButtonReleased?.Invoke(this, buttonId);
     }
 }
        internal void InitGamePadHandlers()
        {
            _gamePadHandlers = new GamePadHandler[MaxGamePads];
            for (int i = 0; i < MaxGamePads; i++)
            {
                var handle = _gamePadHandlers[i] = new GamePadHandler(i);

                // Redirect Events.
                handle.OnConnection += () => OnConnection?.Invoke(handle);
                handle.OnDisconnect += () => OnDisconnected?.Invoke(handle);

                handle.OnButtonDown     += (button, value) => OnButtonDown?.Invoke(handle, button, value);
                handle.OnButtonUp       += (button, value) => OnButtonUp?.Invoke(handle, button, value);
                handle.OnButtonPressed  += (button, value) => OnButtonPressed?.Invoke(handle, button, value);
                handle.OnButtonClicked  += (button, value) => OnButtonClicked?.Invoke(handle, button, value);
                handle.OnButtonReleased += (button, value) => OnButtonReleased?.Invoke(handle, button, value);
            }
        }
예제 #3
0
 private void OnDestroy()
 {
     OnButtonReleased?.Invoke();
 }
예제 #4
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());
            }
        }
예제 #5
0
        /// <summary>
        ///     Dispatches Button.OnReleased event for all buttons.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnButtonReleasedInternal(object sender, EventArgs args)
        {
            var button = (Button)sender;

            OnButtonReleased?.Invoke(this, new ButtonReleasedEventArgs(button));
        }