2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
2012-10-16 20:41:17 +00:00
|
|
|
using ANX.Framework.NonXNA;
|
2012-09-01 16:20:44 +00:00
|
|
|
using ANX.Framework.NonXNA.Development;
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
namespace ANX.Framework.Input
|
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
[PercentageComplete(100)]
|
|
|
|
[Developer("AstrorEnales")]
|
|
|
|
[TestState(TestStateAttribute.TestState.Tested)]
|
2011-10-31 05:36:24 +00:00
|
|
|
public struct GamePadDPad
|
2012-10-16 20:41:17 +00:00
|
|
|
{
|
|
|
|
private readonly ButtonState up;
|
|
|
|
private readonly ButtonState right;
|
|
|
|
private readonly ButtonState down;
|
|
|
|
private readonly ButtonState left;
|
|
|
|
|
|
|
|
public ButtonState Down
|
|
|
|
{
|
|
|
|
get { return down; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public ButtonState Left
|
|
|
|
{
|
|
|
|
get { return left; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public ButtonState Right
|
|
|
|
{
|
|
|
|
get { return right; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public ButtonState Up
|
|
|
|
{
|
|
|
|
get { return up; }
|
|
|
|
}
|
2011-11-11 12:50:46 +00:00
|
|
|
|
|
|
|
public GamePadDPad(ButtonState upValue, ButtonState downValue, ButtonState leftValue, ButtonState rightValue)
|
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
up = upValue;
|
|
|
|
down = downValue;
|
|
|
|
left = leftValue;
|
|
|
|
right = rightValue;
|
2011-11-11 12:50:46 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 16:20:44 +00:00
|
|
|
internal GamePadDPad(Buttons buttons)
|
2012-10-16 20:41:17 +00:00
|
|
|
: this()
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
up = GetButtonStateFrom(buttons, Buttons.DPadUp);
|
|
|
|
left = GetButtonStateFrom(buttons, Buttons.DPadLeft);
|
|
|
|
down = GetButtonStateFrom(buttons, Buttons.DPadDown);
|
|
|
|
right = GetButtonStateFrom(buttons, Buttons.DPadRight);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 20:41:17 +00:00
|
|
|
private ButtonState GetButtonStateFrom(Buttons buttons, Buttons button)
|
2012-09-01 16:20:44 +00:00
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
return (buttons & button) == button ? ButtonState.Pressed : ButtonState.Released;
|
2012-09-01 16:20:44 +00:00
|
|
|
}
|
2011-11-11 12:50:46 +00:00
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
return HashHelper.GetGCHandleHashCode(this);
|
2011-11-11 12:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
string buttons = up == ButtonState.Pressed ? "Up" : "";
|
|
|
|
buttons += down == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Down" : "";
|
|
|
|
buttons += left == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Left" : "";
|
|
|
|
buttons += right == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Right" : "";
|
2011-11-11 12:50:46 +00:00
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(buttons))
|
|
|
|
buttons = "None";
|
|
|
|
|
|
|
|
return String.Format("{{DPad:{0}}}", buttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
return obj is GamePadDPad && this == (GamePadDPad)obj;
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 20:41:17 +00:00
|
|
|
public static bool operator ==(GamePadDPad lhs, GamePadDPad rhs)
|
2011-11-11 12:50:46 +00:00
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
return lhs.up == rhs.up && lhs.down == rhs.down && lhs.left == rhs.left && lhs.right == rhs.right;
|
2011-11-11 12:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator !=(GamePadDPad lhs, GamePadDPad rhs)
|
|
|
|
{
|
2012-10-16 20:41:17 +00:00
|
|
|
return lhs.up != rhs.up || lhs.down != rhs.down || lhs.left != rhs.left || lhs.right != rhs.right;
|
2011-11-11 12:50:46 +00:00
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
}
|