Adding code for mouse handling
--HG-- branch : axios-newgsm
This commit is contained in:
parent
2277056e6b
commit
494a128094
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using GameStateManagement;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
@ -19,45 +20,45 @@ namespace Axios.Engine
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ namespace Axios.Engine
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleInput(InputHelper input, GameTime gameTime)
|
||||
public override void HandleInput(InputState input, GameTime gameTime)
|
||||
{
|
||||
base.HandleInput(input, gameTime);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
using Axios.Engine.Interfaces;
|
||||
using Microsoft.Xna.Framework;
|
||||
using GameStateManagement;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
@ -65,12 +66,12 @@ namespace Axios.Engine
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using GameStateManagement;
|
||||
|
||||
|
||||
namespace Axios.Engine.Interfaces
|
||||
@ -8,8 +9,8 @@ namespace Axios.Engine.Interfaces
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using GameStateManagement;
|
||||
|
||||
namespace Axios.Engine.UI
|
||||
{
|
||||
@ -48,7 +49,7 @@ namespace Axios.Engine.UI
|
||||
|
||||
}
|
||||
|
||||
public override void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input)
|
||||
public override void OnMouseHover(AxiosGameScreen gameScreen, InputState input)
|
||||
{
|
||||
base.OnMouseHover(gameScreen, input);
|
||||
|
||||
@ -56,21 +57,21 @@ namespace Axios.Engine.UI
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -81,7 +82,7 @@ namespace Axios.Engine.UI
|
||||
|
||||
|
||||
|
||||
public override void HandleCursor(AxiosGameScreen gameScreen, InputHelper input)
|
||||
public override void HandleCursor(AxiosGameScreen gameScreen, InputState input)
|
||||
{
|
||||
base.HandleCursor(gameScreen, input);
|
||||
|
||||
|
@ -247,7 +247,7 @@ namespace GameStateManagement
|
||||
/// <summary>
|
||||
/// Reads the latest state user input.
|
||||
/// </summary>
|
||||
public void Update()
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
_lastMouseState = _currentMouseState;
|
||||
if (_handleVirtualStick)
|
||||
@ -299,6 +299,52 @@ namespace GameStateManagement
|
||||
{
|
||||
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 @@ namespace GameStateManagement
|
||||
return (_lastVirtualState.IsButtonDown(button) &&
|
||||
_currentVirtualState.IsButtonUp(button));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper for checking if a mouse button was newly pressed during this update.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the requested mouse button is released.
|
||||
/// </summary>
|
||||
/// <param name="button">The button.</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user