diff -r 2fa541edd9646af44c28b3eaef617e35805ca642 -r f8c25203909abded0db473f5f868982c98104e09 axios/Engine/AxiosEvents.cs --- a/axios/Engine/AxiosEvents.cs Sun Apr 15 19:17:34 2012 -0500 +++ b/axios/Engine/AxiosEvents.cs Tue Apr 17 22:07:51 2012 -0500 @@ -1,5 +1,6 @@ using System; using FarseerPhysics.SamplesFramework; +using GameStateManagement; namespace Axios.Engine { @@ -19,45 +20,45 @@ } } - public delegate void AxiosHandler(object sender, AxiosGameScreen gameScreen, InputHelper input); + public delegate void AxiosHandler(object sender, AxiosGameScreen gameScreen, InputState input); public delegate void AxiosGameObjectHandler(AxiosGameObject sender); #region GameObjectEventMethods - public virtual void OnFocusEnter(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnFocusEnter(AxiosGameScreen gameScreen, InputState input) { this.HasFocus = true; this.OnEvent(FocusEnter, gameScreen, input); } - public virtual void OnFocusLeave(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnFocusLeave(AxiosGameScreen gameScreen, InputState input) { this.HasFocus = false; this.OnEvent(FocusLeave, gameScreen, input); } - public virtual void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnMouseHover(AxiosGameScreen gameScreen, InputState input) { this.OnEvent(MouseHover, gameScreen, input); } - public virtual void OnMouseLeave(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnMouseLeave(AxiosGameScreen gameScreen, InputState input) { this.OnEvent(MouseLeave, gameScreen, input); } - public virtual void OnValueChange(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnValueChange(AxiosGameScreen gameScreen, InputState input) { this.OnEvent(ValueChange, gameScreen, input); } - public virtual void OnMouseDown(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnMouseDown(AxiosGameScreen gameScreen, InputState input) { this.OnEvent(MouseDown, gameScreen, input); } - public virtual void OnMouseUp(AxiosGameScreen gameScreen, InputHelper input) + public virtual void OnMouseUp(AxiosGameScreen gameScreen, InputState input) { this.OnEvent(MouseUp, gameScreen, input); } diff -r 2fa541edd9646af44c28b3eaef617e35805ca642 -r f8c25203909abded0db473f5f868982c98104e09 axios/Engine/AxiosGameScreen.cs --- a/axios/Engine/AxiosGameScreen.cs Sun Apr 15 19:17:34 2012 -0500 +++ b/axios/Engine/AxiosGameScreen.cs Tue Apr 17 22:07:51 2012 -0500 @@ -334,7 +334,7 @@ } } - public override void HandleInput(InputHelper input, GameTime gameTime) + public override void HandleInput(InputState input, GameTime gameTime) { base.HandleInput(input, gameTime); diff -r 2fa541edd9646af44c28b3eaef617e35805ca642 -r f8c25203909abded0db473f5f868982c98104e09 axios/Engine/AxiosTimer.cs --- a/axios/Engine/AxiosTimer.cs Sun Apr 15 19:17:34 2012 -0500 +++ b/axios/Engine/AxiosTimer.cs Tue Apr 17 22:07:51 2012 -0500 @@ -2,6 +2,7 @@ using Axios.Engine.Interfaces; using Microsoft.Xna.Framework; +using GameStateManagement; namespace Axios.Engine { @@ -65,12 +66,12 @@ } - public override void HandleInput(AxiosGameScreen gameScreen, FarseerPhysics.SamplesFramework.InputHelper input, Microsoft.Xna.Framework.GameTime gameTime) + public override void HandleInput(AxiosGameScreen gameScreen, InputState input, Microsoft.Xna.Framework.GameTime gameTime) { } - public override void HandleCursor(AxiosGameScreen gameScreen, FarseerPhysics.SamplesFramework.InputHelper input) + public override void HandleCursor(AxiosGameScreen gameScreen, InputState input) { } diff -r 2fa541edd9646af44c28b3eaef617e35805ca642 -r f8c25203909abded0db473f5f868982c98104e09 axios/Engine/Interfaces/IAxiosGameObject.cs --- a/axios/Engine/Interfaces/IAxiosGameObject.cs Sun Apr 15 19:17:34 2012 -0500 +++ b/axios/Engine/Interfaces/IAxiosGameObject.cs Tue Apr 17 22:07:51 2012 -0500 @@ -1,5 +1,6 @@ using FarseerPhysics.SamplesFramework; using Microsoft.Xna.Framework; +using GameStateManagement; namespace Axios.Engine.Interfaces @@ -8,8 +9,8 @@ { void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen); void LoadContent(AxiosGameScreen gameScreen); - void HandleInput(AxiosGameScreen gameScreen, InputHelper input, GameTime gameTime); - void HandleCursor(AxiosGameScreen gameScreen, InputHelper input); + void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime); + void HandleCursor(AxiosGameScreen gameScreen, InputState input); void UnloadContent(AxiosGameScreen gameScreen); } } diff -r 2fa541edd9646af44c28b3eaef617e35805ca642 -r f8c25203909abded0db473f5f868982c98104e09 axios/Engine/UI/AxiosButton.cs --- a/axios/Engine/UI/AxiosButton.cs Sun Apr 15 19:17:34 2012 -0500 +++ b/axios/Engine/UI/AxiosButton.cs Tue Apr 17 22:07:51 2012 -0500 @@ -1,6 +1,7 @@  using FarseerPhysics.SamplesFramework; using Microsoft.Xna.Framework.Graphics; +using GameStateManagement; namespace Axios.Engine.UI { @@ -48,7 +49,7 @@ } - public override void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input) + public override void OnMouseHover(AxiosGameScreen gameScreen, InputState input) { base.OnMouseHover(gameScreen, input); @@ -56,21 +57,21 @@ } - public override void OnMouseLeave(AxiosGameScreen gameScreen, InputHelper input) + public override void OnMouseLeave(AxiosGameScreen gameScreen, InputState input) { base.OnMouseLeave(gameScreen, input); this.Texture = _normaltexture; } - public override void OnMouseDown(AxiosGameScreen gameScreen, InputHelper input) + public override void OnMouseDown(AxiosGameScreen gameScreen, InputState input) { base.OnMouseDown(gameScreen, input); this.Texture = _clicktexture; } - public override void OnMouseUp(AxiosGameScreen gameScreen, InputHelper input) + public override void OnMouseUp(AxiosGameScreen gameScreen, InputState input) { base.OnMouseUp(gameScreen, input); @@ -79,9 +80,9 @@ } - - public override void HandleCursor(AxiosGameScreen gameScreen, InputHelper input) + + public override void HandleCursor(AxiosGameScreen gameScreen, InputState input) { base.HandleCursor(gameScreen, input); diff -r 2fa541edd9646af44c28b3eaef617e35805ca642 -r f8c25203909abded0db473f5f868982c98104e09 axios/ScreenSystem/InputState.cs --- a/axios/ScreenSystem/InputState.cs Sun Apr 15 19:17:34 2012 -0500 +++ b/axios/ScreenSystem/InputState.cs Tue Apr 17 22:07:51 2012 -0500 @@ -247,7 +247,7 @@ /// /// Reads the latest state user input. /// - public void Update() + public void Update(GameTime gameTime) { _lastMouseState = _currentMouseState; if (_handleVirtualStick) @@ -299,6 +299,52 @@ { Gestures.Add(TouchPanel.ReadGesture()); } + + // Update cursor + Vector2 oldCursor = _cursor; + + if (CurrentGamePadStates[0].IsConnected && CurrentGamePadStates[0].ThumbSticks.Left != Vector2.Zero) + { + Vector2 temp = CurrentGamePadStates[0].ThumbSticks.Left; + _cursor += temp * new Vector2(300f, -300f) * (float)gameTime.ElapsedGameTime.TotalSeconds; + Mouse.SetPosition((int)_cursor.X, (int)_cursor.Y); + } + else + { + _cursor.X = _currentMouseState.X; + _cursor.Y = _currentMouseState.Y; + } + _cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width); + _cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height); + + if (_cursorIsValid && oldCursor != _cursor) + { + _cursorMoved = true; + } + else + { + _cursorMoved = false; + } + +#if WINDOWS + if (_viewport.Bounds.Contains(_currentMouseState.X, _currentMouseState.Y)) + { + _cursorIsValid = true; + } + else + { + _cursorIsValid = false; + } +#elif WINDOWS_PHONE + if (_currentMouseState.LeftButton == ButtonState.Pressed) + { + _cursorIsValid = true; + } + else + { + _cursorIsValid = false; + } +#endif } @@ -426,5 +472,60 @@ return (_lastVirtualState.IsButtonDown(button) && _currentVirtualState.IsButtonUp(button)); } + + /// + /// Helper for checking if a mouse button was newly pressed during this update. + /// + public bool IsNewMouseButtonPress(MouseButtons button) + { + switch (button) + { + case MouseButtons.LeftButton: + return (_currentMouseState.LeftButton == ButtonState.Pressed && + _lastMouseState.LeftButton == ButtonState.Released); + case MouseButtons.RightButton: + return (_currentMouseState.RightButton == ButtonState.Pressed && + _lastMouseState.RightButton == ButtonState.Released); + case MouseButtons.MiddleButton: + return (_currentMouseState.MiddleButton == ButtonState.Pressed && + _lastMouseState.MiddleButton == ButtonState.Released); + case MouseButtons.ExtraButton1: + return (_currentMouseState.XButton1 == ButtonState.Pressed && + _lastMouseState.XButton1 == ButtonState.Released); + case MouseButtons.ExtraButton2: + return (_currentMouseState.XButton2 == ButtonState.Pressed && + _lastMouseState.XButton2 == ButtonState.Released); + default: + return false; + } + } + + /// + /// Checks if the requested mouse button is released. + /// + /// The button. + public bool IsNewMouseButtonRelease(MouseButtons button) + { + switch (button) + { + case MouseButtons.LeftButton: + return (_lastMouseState.LeftButton == ButtonState.Pressed && + _currentMouseState.LeftButton == ButtonState.Released); + case MouseButtons.RightButton: + return (_lastMouseState.RightButton == ButtonState.Pressed && + _currentMouseState.RightButton == ButtonState.Released); + case MouseButtons.MiddleButton: + return (_lastMouseState.MiddleButton == ButtonState.Pressed && + _currentMouseState.MiddleButton == ButtonState.Released); + case MouseButtons.ExtraButton1: + return (_lastMouseState.XButton1 == ButtonState.Pressed && + _currentMouseState.XButton1 == ButtonState.Released); + case MouseButtons.ExtraButton2: + return (_lastMouseState.XButton2 == ButtonState.Pressed && + _currentMouseState.XButton2 == ButtonState.Released); + default: + return false; + } + } } }