/// <summary> /// Validates the mouse position and sends a <see cref="Message<Vector2>"/> if changed /// </summary> /// <param name="state">Current <see cref="MouseState"/></param> private void ValidatePosition(MouseState state) { // If the mouse hasn't moved and hasn't switched visibility states then just return if (state.X == lastPositionX && state.Y == lastPositionY) { return; } int newPosX = state.X; int newPosY = state.Y; lastPositionX = newPosX; lastPositionY = newPosY; if (!this.Game.IsMouseVisible) { // Keep the mouse position at 100, 100 while it is not visible lastPositionX = lastPositionY = 100; Mouse.SetPosition(lastPositionX, lastPositionY); } MsgMouseMove moveMessage = ObjectPool.Aquire <MsgMouseMove>(); moveMessage.Time = this.gameTime; moveMessage.PositionDelta = new Vector2((float)(newPosX - lastPositionX) / QSConstants.MouseSensitivity, (float)(newPosY - lastPositionY) / QSConstants.MouseSensitivity); this.Game.SendMessage(moveMessage); }
/// <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) { switch (message.Type) { 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); } }
/// <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 }