Exemplo n.º 1
0
        /// <summary>
        /// Handles a message sent to this component.
        /// </summary>
        /// <param name="message">Message to be handled</param>
        /// <returns>True, if handled, otherwise false</returns>
        /// <exception cref="ArgumentException">Thrown if a <see cref="MessageType"/> is not handled properly."/></exception>
        public override bool ExecuteMessage(IMessage message)
        {
#if WINDOWS
            switch (message.Type)
            {
            case MessageType.MouseDown:
            {
                MsgMouseButtonPressed mouseDownMessage = message as MsgMouseButtonPressed;
                message.TypeCheck(mouseDownMessage);

                if (mouseDownMessage.Button == MouseButton.Left)
                {
                    this.speed *= this.turboSpeedModifier;
                }
            }
                return(true);

            case MessageType.MouseUp:
            {
                MsgMouseButtonReleased mouseUpMessage = message as MsgMouseButtonReleased;
                message.TypeCheck(mouseUpMessage);

                if (mouseUpMessage.Button == MouseButton.Left)
                {
                    this.speed *= (1.0f / this.turboSpeedModifier);
                }
            }
                return(true);

            case MessageType.MouseScroll:
            {
                MsgMouseScroll scrollWheelMessage = message as MsgMouseScroll;
                message.TypeCheck(scrollWheelMessage);

                HandleMouseScroll(scrollWheelMessage.ScrollWheelDelta);
            }
                return(true);

            case MessageType.MouseMove:
            {
                MsgMouseMove moveMessage = message as MsgMouseMove;
                message.TypeCheck(moveMessage);

                HandleMouseMove(moveMessage.PositionDelta);
            }
                return(true);

            default:
                return(false);
            }
#else //!WINDOWS
            return(false);
#endif //!WINDOWS
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validates the state of a specific mouse button
        /// </summary>
        /// <param name="currentButton">The <see cref="MouseButton"/> which should be tested</param>
        /// <param name="currentState">The current <see cref="ButtonState"/> of the button</param>
        private void ValidateButtonState(MouseButton currentButton, ButtonState currentState)
        {
            // If there is a change in the state the button has just been pressed or released
            if (currentState != this.lastState[currentButton])
            {
                // Determine the state of the button
                switch (currentState)
                {
                case ButtonState.Pressed:
                {
                    MsgMouseButtonPressed buttonMessage = ObjectPool.Aquire <MsgMouseButtonPressed>();
                    buttonMessage.Time   = this.gameTime;
                    buttonMessage.Button = currentButton;
                    this.Game.SendMessage(buttonMessage);
                }
                break;

                case ButtonState.Released:
                {
                    MsgMouseButtonReleased buttonMessage = ObjectPool.Aquire <MsgMouseButtonReleased>();
                    buttonMessage.Time   = this.gameTime;
                    buttonMessage.Button = currentButton;
                    this.Game.SendMessage(buttonMessage);
                }
                break;
                }

                this.lastState[currentButton] = currentState;

                previousButtonsHeld[currentButton] = false;
            }
            else
            {
                // If the state here is pressed then send the MouseHeld message
                if (currentState == ButtonState.Pressed)
                {
                    bool wasHeld = false;

                    previousButtonsHeld.TryGetValue(currentButton, out wasHeld);

                    if (wasHeld == false)
                    {
                        previousButtonsHeld[currentButton] = true;

                        MsgMouseButtonHeld buttonMessage = ObjectPool.Aquire <MsgMouseButtonHeld>();
                        buttonMessage.Time   = this.gameTime;
                        buttonMessage.Button = currentButton;
                        this.Game.SendMessage(buttonMessage);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Message handler for the input polling handler.
        /// </summary>
        /// <param name="message">Incoming message</param>
        private void Game_GameMessage(IMessage message)
        {
            switch (message.Type)
            {
            case MessageType.KeyDown:
                MsgKeyPressed keyDownMessage = message as MsgKeyPressed;
                message.TypeCheck(keyDownMessage);

                Press(keyDownMessage.Key);
                break;

            case MessageType.KeyUp:
                MsgKeyReleased keyUpMessage = message as MsgKeyReleased;
                message.TypeCheck(keyUpMessage);

                Release(keyUpMessage.Key);
                break;

            case MessageType.KeyHeld:
                MsgKeyHeld keyPressMessage = message as MsgKeyHeld;
                message.TypeCheck(keyPressMessage);

                SetHeld(keyPressMessage.Key, true);
                break;

            case MessageType.MouseDown:
                MsgMouseButtonPressed mouseDownMessage = message as MsgMouseButtonPressed;
                message.TypeCheck(mouseDownMessage);

                Press(mouseDownMessage.Button);
                break;

            case MessageType.MouseUp:
                MsgMouseButtonReleased mouseUpMessage = message as MsgMouseButtonReleased;
                message.TypeCheck(mouseUpMessage);

                Release(mouseUpMessage.Button);
                break;

            case MessageType.MouseHeld:
                MsgMouseButtonHeld mousePressMessage = message as MsgMouseButtonHeld;
                message.TypeCheck(mousePressMessage);

                SetHeld(mousePressMessage.Button, true);
                break;

            case MessageType.Thumbstick:
                MsgGamePadThumbstick thumbstickMessage = message as MsgGamePadThumbstick;
                message.TypeCheck(thumbstickMessage);

                // Store previous state
                this.previousThumbsticks[(int)thumbstickMessage.PlayerIndex, (int)thumbstickMessage.StickType] =
                    this.thumbsticks[(int)thumbstickMessage.PlayerIndex, (int)thumbstickMessage.StickType];

                this.thumbsticks[(int)thumbstickMessage.PlayerIndex, (int)thumbstickMessage.StickType] =
                    thumbstickMessage.StickValues;
                break;

            case MessageType.ThumbstickRelease:
                MsgGamePadThumbstickReleased thumbstickReleaseMessage = message as MsgGamePadThumbstickReleased;
                message.TypeCheck(thumbstickReleaseMessage);

                // Store previous state
                this.previousThumbsticks[(int)thumbstickReleaseMessage.PlayerIndex, (int)thumbstickReleaseMessage.StickType] =
                    this.thumbsticks[(int)thumbstickReleaseMessage.PlayerIndex, (int)thumbstickReleaseMessage.StickType];

                ReleaseThumbstick(thumbstickReleaseMessage.Data);
                break;

            case MessageType.Trigger:
                MsgGamePadTrigger triggerMessage = message as MsgGamePadTrigger;
                message.TypeCheck(triggerMessage);

                // Store previous state
                this.previousTriggers[(int)triggerMessage.PlayerIndex, (int)triggerMessage.GamePadInputSide] =
                    this.triggers[(int)triggerMessage.PlayerIndex, (int)triggerMessage.GamePadInputSide];

                this.triggers[(int)triggerMessage.PlayerIndex, (int)triggerMessage.GamePadInputSide] =
                    triggerMessage.TriggerValue;
                break;

            case MessageType.TriggerRelease:
                MsgGamePadTriggerReleased triggerReleaseMessage = message as MsgGamePadTriggerReleased;
                message.TypeCheck(triggerReleaseMessage);

                // Store previous state
                previousTriggers[(int)triggerReleaseMessage.PlayerIndex, (int)triggerReleaseMessage.GamePadInputSide] =
                    triggers[(int)triggerReleaseMessage.PlayerIndex, (int)triggerReleaseMessage.GamePadInputSide];

                ReleaseTrigger(triggerReleaseMessage.Data);
                break;

            case MessageType.ButtonDown:
                MsgGamePadButtonPressed buttonDownMessage = message as MsgGamePadButtonPressed;
                message.TypeCheck(buttonDownMessage);

                Press(buttonDownMessage.Button, buttonDownMessage.PlayerIndex);
                break;

            case MessageType.ButtonUp:
                MsgGamePadButtonReleased buttonUpMessage = message as MsgGamePadButtonReleased;
                message.TypeCheck(buttonUpMessage);

                Release(buttonUpMessage.Button, buttonUpMessage.PlayerIndex);
                break;

            case MessageType.ButtonHeld:
                MsgGamePadButtonHeld buttonHeldMessage = message as MsgGamePadButtonHeld;
                message.TypeCheck(buttonHeldMessage);

                SetHeld(buttonHeldMessage.Button, buttonHeldMessage.PlayerIndex, true);
                break;
            }
        }