Some refactorings in the Input namespace and added PercentageComplete and TestState attributes to most classes

This commit is contained in:
SND\AstrorEnales_cp 2012-09-01 16:20:44 +00:00
parent 0ad3ca056b
commit 379a1bc50e
31 changed files with 594 additions and 865 deletions

View File

@ -1,8 +1,3 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license

View File

@ -1,15 +1,12 @@
#region Using Statements
using System; using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[FlagsAttribute] [Flags]
public enum Buttons public enum Buttons
{ {
DPadUp = 1, DPadUp = 1,

View File

@ -1,4 +1,5 @@
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.Development;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -6,6 +7,8 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public static class GamePad public static class GamePad
{ {
private static IGamePad gamePad; private static IGamePad gamePad;
@ -22,22 +25,12 @@ namespace ANX.Framework.Input
public static GamePadState GetState(PlayerIndex playerIndex) public static GamePadState GetState(PlayerIndex playerIndex)
{ {
bool isConnected; return gamePad.GetState(playerIndex);
int packetNumber;
GamePadState ret = gamePad.GetState(playerIndex, out isConnected, out packetNumber);
ret.IsConnected = isConnected;
ret.PacketNumber = packetNumber;
return ret;
} }
public static GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode) public static GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
{ {
bool isConnected; return gamePad.GetState(playerIndex, deadZoneMode);
int packetNumber;
GamePadState ret = gamePad.GetState(playerIndex, deadZoneMode, out isConnected, out packetNumber);
ret.IsConnected = isConnected;
ret.PacketNumber = packetNumber;
return ret;
} }
public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor) public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)

View File

@ -1,9 +1,5 @@
#region Using Statements
using System; using System;
using System.IO; using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -11,60 +7,59 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct GamePadButtons public struct GamePadButtons
{ {
#region Private Members #region Public
internal Buttons buttonValue; public ButtonState A { get; private set; }
public ButtonState B { get; private set; }
internal ButtonState button_a; public ButtonState Back { get; private set; }
internal ButtonState button_b; public ButtonState BigButton { get; private set; }
internal ButtonState button_x; public ButtonState LeftShoulder { get; private set; }
internal ButtonState button_y; public ButtonState LeftStick { get; private set; }
internal ButtonState stick_left; public ButtonState RightShoulder { get; private set; }
internal ButtonState stick_right; public ButtonState RightStick { get; private set; }
internal ButtonState shoulder_left; public ButtonState Start { get; private set; }
internal ButtonState shoulder_right; public ButtonState X { get; private set; }
internal ButtonState button_back; public ButtonState Y { get; private set; }
internal ButtonState button_start; internal Buttons Buttons { get; private set; }
internal ButtonState button_big; #endregion
#endregion // Private Members
public GamePadButtons(Buttons buttons) public GamePadButtons(Buttons buttons)
: this()
{ {
this.button_a = GetButtonState(buttons, Buttons.A); A = GetButtonState(buttons, Buttons.A);
this.button_b = GetButtonState(buttons, Buttons.B); B = GetButtonState(buttons, Buttons.B);
this.button_x = GetButtonState(buttons, Buttons.X); X = GetButtonState(buttons, Buttons.X);
this.button_y = GetButtonState(buttons, Buttons.Y); Y = GetButtonState(buttons, Buttons.Y);
this.stick_left = GetButtonState(buttons, Buttons.LeftStick); LeftStick = GetButtonState(buttons, Buttons.LeftStick);
this.stick_right = GetButtonState(buttons, Buttons.RightStick); RightStick = GetButtonState(buttons, Buttons.RightStick);
this.shoulder_left = GetButtonState(buttons, Buttons.LeftShoulder); LeftShoulder = GetButtonState(buttons, Buttons.LeftShoulder);
this.shoulder_right = GetButtonState(buttons, Buttons.RightShoulder); RightShoulder = GetButtonState(buttons, Buttons.RightShoulder);
this.button_back = GetButtonState(buttons, Buttons.Back); Back = GetButtonState(buttons, Buttons.Back);
this.button_start = GetButtonState(buttons, Buttons.Start); Start = GetButtonState(buttons, Buttons.Start);
this.button_big = GetButtonState(buttons, Buttons.BigButton); BigButton = GetButtonState(buttons, Buttons.BigButton);
this.buttonValue = buttons; Buttons = buttons;
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj != null && obj.GetType() == typeof(GamePadButtons)) if (obj != null && obj.GetType() == typeof(GamePadButtons))
{
return this == (GamePadButtons)obj; return this == (GamePadButtons)obj;
}
return false; return false;
} }
public static bool operator ==(GamePadButtons lhs, GamePadButtons rhs) public static bool operator ==(GamePadButtons lhs, GamePadButtons rhs)
{ {
return lhs.buttonValue == rhs.buttonValue; return lhs.Buttons == rhs.Buttons;
} }
public static bool operator !=(GamePadButtons lhs, GamePadButtons rhs) public static bool operator !=(GamePadButtons lhs, GamePadButtons rhs)
{ {
return lhs.buttonValue != rhs.buttonValue; return lhs.Buttons != rhs.Buttons;
} }
private static ButtonState GetButtonState(Buttons buttons, Buttons button) private static ButtonState GetButtonState(Buttons buttons, Buttons button)
@ -72,129 +67,29 @@ namespace ANX.Framework.Input
return (buttons & button) == button ? ButtonState.Pressed : ButtonState.Released; return (buttons & button) == button ? ButtonState.Pressed : ButtonState.Released;
} }
public ButtonState A
{
get
{
return this.button_a;
}
}
public ButtonState B
{
get
{
return this.button_b;
}
}
public ButtonState Back
{
get
{
return this.button_back;
}
}
public ButtonState BigButton
{
get
{
return this.button_big;
}
}
public ButtonState LeftShoulder
{
get
{
return this.shoulder_left;
}
}
public ButtonState LeftStick
{
get
{
return stick_left;
}
}
public ButtonState RightShoulder
{
get
{
return this.shoulder_right;
}
}
public ButtonState RightStick
{
get
{
return this.stick_right;
}
}
public ButtonState Start
{
get
{
return this.button_start;
}
}
public ButtonState X
{
get
{
return this.button_x;
}
}
public ButtonState Y
{
get
{
return this.button_y;
}
}
public override int GetHashCode() public override int GetHashCode()
{ {
return (int)this.buttonValue; return (int)Buttons;
} }
public override string ToString() public override string ToString()
{ {
String buttons = String.Empty; string buttons = A == ButtonState.Pressed ? "A" : "";
buttons += B == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "B" : "";
buttons += X == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "X" : "";
buttons += Y == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Y" : "";
buttons += LeftShoulder == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "LeftShoulder" : "";
buttons += RightShoulder == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "RightShoulder" : "";
buttons += LeftStick == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "LeftStick" : "";
buttons += RightStick == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "RightStick" : "";
buttons += Start == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Start" : "";
buttons += Back == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Back" : "";
buttons += BigButton == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "BigButton" : "";
buttons += this.button_a == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "A" : ""; if (String.IsNullOrEmpty(buttons))
buttons += this.button_b == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "B" : "";
buttons += this.button_x == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "X" : "";
buttons += this.button_y == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Y" : "";
buttons += this.shoulder_left == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "LeftShoulder" : "";
buttons += this.shoulder_right == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "RightShoulder" : "";
buttons += this.stick_left == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "LeftStick" : "";
buttons += this.stick_right == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "RightStick" : "";
buttons += this.button_start == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Start" : "";
buttons += this.button_back == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Back" : "";
buttons += this.button_big == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "BigButton" : "";
if (string.IsNullOrEmpty(buttons))
{
buttons = "None"; buttons = "None";
}
return String.Format("{{Buttons:{0}}}", buttons); return String.Format("{{Buttons:{0}}}", buttons);
} }
internal Buttons Buttons
{
get
{
return this.buttonValue;
}
}
} }
} }

View File

@ -1,9 +1,13 @@
using ANX.Framework.NonXNA.Development;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public struct GamePadCapabilities public struct GamePadCapabilities
{ {
public GamePadType GamePadType public GamePadType GamePadType

View File

@ -1,9 +1,5 @@
#region Using Statements
using System; using System;
using System.IO; using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -11,92 +7,63 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct GamePadDPad public struct GamePadDPad
{ {
#region Private Members public ButtonState Down { get; private set; }
private Buttons buttons; public ButtonState Left { get; private set; }
public ButtonState Right { get; private set; }
private ButtonState up; public ButtonState Up { get; private set; }
private ButtonState down; internal Buttons Buttons { get; private set; }
private ButtonState left;
private ButtonState right;
#endregion // Private Members
public GamePadDPad(ButtonState upValue, ButtonState downValue, ButtonState leftValue, ButtonState rightValue) public GamePadDPad(ButtonState upValue, ButtonState downValue, ButtonState leftValue, ButtonState rightValue)
: this()
{ {
this.up = upValue; Up = upValue;
this.down = downValue; Down = downValue;
this.left = leftValue; Left = leftValue;
this.right = rightValue; Right = rightValue;
AddToButtonsIfPressed(upValue, Buttons.DPadUp);
buttons = 0; AddToButtonsIfPressed(downValue, Buttons.DPadDown);
buttons |= (upValue == ButtonState.Pressed ? Buttons.DPadUp : 0); AddToButtonsIfPressed(leftValue, Buttons.DPadLeft);
buttons |= (downValue == ButtonState.Pressed ? Buttons.DPadDown : 0); AddToButtonsIfPressed(rightValue, Buttons.DPadRight);
buttons |= (leftValue == ButtonState.Pressed ? Buttons.DPadLeft : 0);
buttons |= (rightValue == ButtonState.Pressed ? Buttons.DPadRight : 0);
} }
internal GamePadDPad(Buttons buttons) internal GamePadDPad(Buttons buttons)
: this()
{ {
this.buttons = buttons; Buttons = buttons;
Up = GetButtonStateFrom(Buttons.DPadUp);
this.up = (buttons & Buttons.DPadUp) == Buttons.DPadUp ? ButtonState.Pressed : ButtonState.Released; Left = GetButtonStateFrom(Buttons.DPadLeft);
this.left = (buttons & Buttons.DPadLeft) == Buttons.DPadLeft ? ButtonState.Pressed : ButtonState.Released; Down = GetButtonStateFrom(Buttons.DPadDown);
this.down = (buttons & Buttons.DPadDown) == Buttons.DPadDown ? ButtonState.Pressed : ButtonState.Released; Right = GetButtonStateFrom(Buttons.DPadRight);
this.right = (buttons & Buttons.DPadRight) == Buttons.DPadRight ? ButtonState.Pressed : ButtonState.Released;
} }
public ButtonState Down private ButtonState GetButtonStateFrom(Buttons button)
{ {
get return (Buttons & button) == button ? ButtonState.Pressed : ButtonState.Released;
{ }
return down;
}
}
public ButtonState Left private void AddToButtonsIfPressed(ButtonState state, Buttons button)
{ {
get Buttons |= (state == ButtonState.Pressed ? button : 0);
{ }
return left;
}
}
public ButtonState Right
{
get
{
return right;
}
}
public ButtonState Up
{
get
{
return up;
}
}
public override int GetHashCode() public override int GetHashCode()
{ {
return (int)buttons; return (int)Buttons;
} }
public override string ToString() public override string ToString()
{ {
String buttons = String.Empty; string buttons = Up == ButtonState.Pressed ? "Up" : "";
buttons += Down == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Down" : "";
buttons += this.up == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Up" : ""; buttons += Left == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Left" : "";
buttons += this.down == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Down" : ""; buttons += Right == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Right" : "";
buttons += this.left == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Left" : "";
buttons += this.right == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Right" : "";
if (String.IsNullOrEmpty(buttons)) if (String.IsNullOrEmpty(buttons))
{
buttons = "None"; buttons = "None";
}
return String.Format("{{DPad:{0}}}", buttons); return String.Format("{{DPad:{0}}}", buttons);
} }
@ -104,29 +71,19 @@ namespace ANX.Framework.Input
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj != null && obj.GetType() == typeof(GamePadDPad)) if (obj != null && obj.GetType() == typeof(GamePadDPad))
{
return this == (GamePadDPad)obj; return this == (GamePadDPad)obj;
}
return false; return false;
} }
public static bool operator ==(GamePadDPad lhs, GamePadDPad rhs) public static bool operator ==(GamePadDPad lhs, GamePadDPad rhs)
{ {
return lhs.buttons == rhs.buttons; return lhs.Buttons == rhs.Buttons;
} }
public static bool operator !=(GamePadDPad lhs, GamePadDPad rhs) public static bool operator !=(GamePadDPad lhs, GamePadDPad rhs)
{ {
return lhs.buttons != rhs.buttons; return lhs.Buttons != rhs.Buttons;
}
internal Buttons Buttons
{
get
{
return this.buttons;
}
} }
} }
} }

View File

@ -1,8 +1,3 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license

View File

@ -1,9 +1,5 @@
#region Using Statements
using System; using System;
using System.IO; using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -11,67 +7,87 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct GamePadState public struct GamePadState
{ {
#region Private Members #region Private
private GamePadThumbSticks thumbSticks; private GamePadThumbSticks thumbSticks;
private GamePadTriggers triggers; private GamePadTriggers triggers;
private GamePadButtons buttons; private GamePadButtons buttons;
private GamePadDPad dPad; private GamePadDPad dPad;
private Buttons buttonsValue; private Buttons buttonsValue;
#endregion
private bool isConnected; #region Public
private int packetNumber; public GamePadButtons Buttons
{
get { return this.buttons; }
}
#endregion // Private Members public GamePadDPad DPad
{
get { return this.dPad; }
}
public GamePadState(GamePadThumbSticks thumbSticks, GamePadTriggers triggers, GamePadButtons buttons, GamePadDPad dPad) public bool IsConnected
{
get;
internal set;
}
public int PacketNumber
{
get;
internal set;
}
public GamePadThumbSticks ThumbSticks
{
get { return this.thumbSticks; }
}
public GamePadTriggers Triggers
{
get { return this.triggers; }
}
#endregion
public GamePadState(GamePadThumbSticks thumbSticks, GamePadTriggers triggers, GamePadButtons buttons, GamePadDPad dPad)
: this()
{ {
this.thumbSticks = thumbSticks; this.thumbSticks = thumbSticks;
this.triggers = triggers; this.triggers = triggers;
this.buttons = buttons; this.buttons = buttons;
this.dPad = dPad; this.dPad = dPad;
this.isConnected = true; this.buttonsValue = this.buttons.Buttons | this.dPad.Buttons;
this.packetNumber = 0; this.IsConnected = true;
this.buttonsValue = this.buttons.Buttons | this.dPad.Buttons; this.PacketNumber = 0;
} }
public GamePadState(Vector2 leftThumbStick, Vector2 rightThumbStick, float leftTrigger, float rightTrigger, params Buttons[] buttons) public GamePadState(Vector2 leftThumbStick, Vector2 rightThumbStick, float leftTrigger, float rightTrigger,
params Buttons[] buttons)
: this()
{ {
this.thumbSticks = new GamePadThumbSticks(leftThumbStick, rightThumbStick); this.thumbSticks = new GamePadThumbSticks(leftThumbStick, rightThumbStick);
this.triggers = new GamePadTriggers(leftTrigger, rightTrigger); this.triggers = new GamePadTriggers(leftTrigger, rightTrigger);
Buttons buttonField = 0; Buttons buttonField = 0;
for (int i = 0; i < buttons.Length; i++) for (int i = 0; i < buttons.Length; i++)
{
buttonField |= buttons[i]; buttonField |= buttons[i];
}
this.buttonsValue = buttonField; this.buttonsValue = buttonField;
this.isConnected = true; this.IsConnected = true;
this.packetNumber = 0; this.PacketNumber = 0;
this.buttons = new GamePadButtons(this.buttonsValue); this.buttons = new GamePadButtons(this.buttonsValue);
this.dPad = new GamePadDPad(this.buttonsValue); this.dPad = new GamePadDPad(this.buttonsValue);
} }
//public GamePadState(int value, bool isConnected, int packetNumber, Vector2 thumbStickLeft, Vector2 thumbStickRight, float triggerLeft, float triggerRight)
//{
// this.buttonsValue = value;
// //TODO: this.buttons = new GamePadButtons(value);
// this.dPad = new GamePadDPad(value);
// this.isConnected = isConnected;
// this.packetNumber = packetNumber;
// this.thumbSticks = new GamePadThumbSticks(thumbStickLeft, thumbStickRight);
// this.triggers = new GamePadTriggers(triggerLeft, triggerRight);
//}
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj != null && obj.GetType() == typeof(GamePadState)) if (obj != null && obj.GetType() == typeof(GamePadState))
{
return this == (GamePadState)obj; return this == (GamePadState)obj;
}
return false; return false;
} }
@ -96,39 +112,14 @@ namespace ANX.Framework.Input
return String.Format("{{IsConnected:{0}}}", IsConnected); return String.Format("{{IsConnected:{0}}}", IsConnected);
} }
public bool IsButtonDown(Buttons button) { return ((this.buttonsValue & button) == button); } public bool IsButtonDown(Buttons button)
public bool IsButtonUp(Buttons button) { return ((this.buttonsValue & button) != button); } {
public GamePadButtons Buttons { get { return this.buttons; } } return (this.buttonsValue & button) == button;
public GamePadDPad DPad { get { return this.dPad; } } }
public bool IsConnected
{
get
{
return this.isConnected;
}
internal set
{
this.isConnected = value;
}
}
public int PacketNumber
{
get
{
return this.packetNumber;
}
internal set
{
this.packetNumber = value;
}
}
public GamePadThumbSticks ThumbSticks { get { return this.thumbSticks; } }
public GamePadTriggers Triggers { get { return this.triggers; } }
public bool IsButtonUp(Buttons button)
{
return (this.buttonsValue & button) != button;
}
} }
} }

View File

@ -1,9 +1,5 @@
#region Using Statements
using System; using System;
using System.IO; using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -11,13 +7,24 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct GamePadThumbSticks public struct GamePadThumbSticks
{ {
#region Private Members #region Private
private Vector2 left; private Vector2 left;
private Vector2 right; private Vector2 right;
#endregion
#endregion // Private Members public Vector2 Left
{
get { return this.left; }
}
public Vector2 Right
{
get { return this.right; }
}
public GamePadThumbSticks (Vector2 leftThumbstick, Vector2 rightThumbstick) public GamePadThumbSticks (Vector2 leftThumbstick, Vector2 rightThumbstick)
{ {
@ -28,9 +35,7 @@ namespace ANX.Framework.Input
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj != null && obj.GetType() == typeof(GamePadThumbSticks)) if (obj != null && obj.GetType() == typeof(GamePadThumbSticks))
{
return this == (GamePadThumbSticks)obj; return this == (GamePadThumbSticks)obj;
}
return false; return false;
} }
@ -55,8 +60,5 @@ namespace ANX.Framework.Input
return String.Format("{{Left:{0} Right:{1}}}", left, right); return String.Format("{{Left:{0} Right:{1}}}", left, right);
} }
public Vector2 Left { get { return this.left; } }
public Vector2 Right { get { return this.right; } }
} }
} }

View File

@ -1,9 +1,5 @@
#region Using Statements
using System; using System;
using System.IO; using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -11,68 +7,46 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
public struct GamePadTriggers [PercentageComplete(100)]
{ [TestState(TestStateAttribute.TestState.Untested)]
#region Private Members public struct GamePadTriggers
private float left; {
private float right; public float Left { get; private set; }
public float Right { get; private set; }
#endregion // Private Members public GamePadTriggers(float leftTrigger, float rightTrigger)
: this()
{
Left = MathHelper.Clamp(leftTrigger, 0f, 1f);
Right = MathHelper.Clamp(rightTrigger, 0f, 1f);
}
public GamePadTriggers (float leftTrigger,float rightTrigger) public override int GetHashCode()
{ {
if (leftTrigger>1) return Left.GetHashCode() ^ Right.GetHashCode();
{ }
leftTrigger = 1;
}
if (leftTrigger<0)
{
leftTrigger = 0;
}
if (rightTrigger>1)
{
rightTrigger = 1;
}
if (rightTrigger<0)
{
rightTrigger = 0;
}
left = leftTrigger;
right = rightTrigger;
}
public override int GetHashCode() public override string ToString()
{ {
return left.GetHashCode() ^ right.GetHashCode(); return String.Format("{{Left:{0} Right:{1}}}", Left, Right);
} }
public override string ToString() public override bool Equals(object obj)
{ {
return String.Format("{{Left:{0} Right:{1}}}", left, right); if (obj != null && obj.GetType() == typeof(GamePadTriggers))
} return this == (GamePadTriggers)obj;
public override bool Equals(object obj) return false;
{ }
if (obj != null && obj.GetType() == typeof(GamePadTriggers))
{
return this == (GamePadTriggers)obj;
}
return false; public static bool operator ==(GamePadTriggers lhs, GamePadTriggers rhs)
} {
return lhs.Left == rhs.Left && lhs.Right == rhs.Right;
}
public static bool operator ==(GamePadTriggers lhs, GamePadTriggers rhs) public static bool operator !=(GamePadTriggers lhs, GamePadTriggers rhs)
{ {
return lhs.left == rhs.left && lhs.right == rhs.right; return lhs.Left != rhs.Left || lhs.Right != rhs.Right;
} }
}
public static bool operator !=(GamePadTriggers lhs, GamePadTriggers rhs)
{
return lhs.left != rhs.left || lhs.right != rhs.right;
}
public float Left { get { return this.left; } }
public float Right { get { return this.right; } }
}
} }

View File

@ -1,25 +1,20 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
public enum GamePadType :short public enum GamePadType : short
{ {
Unknown, Unknown,
GamePad, GamePad,
Wheel, Wheel,
ArcadeStick, ArcadeStick,
FlightStick, FlightStick,
DancePad, DancePad,
Guitar, Guitar,
AlternateGuitar, AlternateGuitar,
DrumKit, DrumKit,
BigButtonPad=768 BigButtonPad = 768
} }
} }

View File

@ -1,17 +1,12 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
public enum KeyState public enum KeyState
{ {
Up, Up,
Down Down
} }
} }

View File

@ -1,8 +1,6 @@
#region Using Statements
using System; using System;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.Development;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -10,39 +8,38 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
public static class Keyboard [PercentageComplete(100)]
{ [TestState(TestStateAttribute.TestState.Tested)]
private static IKeyboard keyboard; public static class Keyboard
{
private static IKeyboard keyboard;
static Keyboard() internal static IntPtr WindowHandle
{ {
keyboard = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard; get
} {
return keyboard != null ? keyboard.WindowHandle : IntPtr.Zero;
}
set
{
if (keyboard != null)
keyboard.WindowHandle = value;
}
}
internal static IntPtr WindowHandle static Keyboard()
{ {
get keyboard = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard;
{ }
return keyboard != null ? keyboard.WindowHandle : IntPtr.Zero;
}
set
{
if (keyboard != null)
{
keyboard.WindowHandle = value;
}
}
}
public static KeyboardState GetState() public static KeyboardState GetState()
{ {
return keyboard.GetState(); return keyboard.GetState();
} }
public static KeyboardState GetState (PlayerIndex playerIndex) public static KeyboardState GetState(PlayerIndex playerIndex)
{ {
return keyboard.GetState(playerIndex); return keyboard.GetState(playerIndex);
} }
}
}
} }

View File

@ -1,8 +1,6 @@
#region Using Statements
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ANX.Framework.NonXNA.Development;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -10,36 +8,37 @@ using System.Collections.Generic;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct KeyboardState public struct KeyboardState
{ {
#region Private Members #region Private
private KeyState[] keyState; private KeyState[] keyState;
private List<Keys> pressedKeys; #endregion
#endregion // Private Members public KeyState this[Keys key]
{
get
{
return keyState[(int)key];
}
}
public KeyboardState(params Keys[] keys) public KeyboardState(params Keys[] keys)
{ {
pressedKeys = new List<Keys>();
pressedKeys.AddRange(keys);
keyState = new KeyState[255]; keyState = new KeyState[255];
keyState.Initialize();
for (int i = 0; i < keys.Length; i++) for (int i = 0; i < keys.Length; i++)
{
keyState[(int)keys[i]] = KeyState.Down; keyState[(int)keys[i]] = KeyState.Down;
}
} }
public bool IsKeyDown(Keys key) public bool IsKeyDown(Keys key)
{ {
return keyState != null ? keyState[(int)key] == KeyState.Down : false; return keyState[(int)key] == KeyState.Down;
} }
public bool IsKeyUp(Keys key) public bool IsKeyUp(Keys key)
{ {
return keyState != null ? keyState[(int)key] == KeyState.Up : true; return keyState[(int)key] == KeyState.Up;
} }
public override int GetHashCode() public override int GetHashCode()
@ -50,9 +49,7 @@ namespace ANX.Framework.Input
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj != null && obj.GetType() == typeof(KeyboardState)) if (obj != null && obj.GetType() == typeof(KeyboardState))
{
return this == (KeyboardState)obj; return this == (KeyboardState)obj;
}
return false; return false;
} }
@ -60,56 +57,46 @@ namespace ANX.Framework.Input
public static bool operator ==(KeyboardState lhs, KeyboardState rhs) public static bool operator ==(KeyboardState lhs, KeyboardState rhs)
{ {
if (lhs.keyState.Length != rhs.keyState.Length) if (lhs.keyState.Length != rhs.keyState.Length)
{
return false; return false;
}
for (int i = 0; i < lhs.keyState.Length; i++) for (int i = 0; i < lhs.keyState.Length; i++)
{
if (lhs.keyState[i] != rhs.keyState[i]) if (lhs.keyState[i] != rhs.keyState[i])
{
return false; return false;
}
}
return true; return true;
} }
public static bool operator !=(KeyboardState lhs, KeyboardState rhs) public static bool operator !=(KeyboardState lhs, KeyboardState rhs)
{ {
return !(lhs == rhs); if (lhs.keyState.Length == rhs.keyState.Length)
} {
for (int i = 0; i < lhs.keyState.Length; i++)
if (lhs.keyState[i] != rhs.keyState[i])
return true;
public KeyState this[Keys key] return false;
{ }
get
{ return true;
return keyState[(int)key];
}
} }
public Keys[] GetPressedKeys() public Keys[] GetPressedKeys()
{ {
List<Keys> value = new List<Keys>(); var result = new List<Keys>();
for (int i = 0; i < keyState.Length; ++i) for (int i = 0; i < keyState.Length; ++i)
{
if (keyState[i] == KeyState.Down) if (keyState[i] == KeyState.Down)
{ result.Add((Keys)i);
value.Add((Keys)i);
} return result.ToArray();
}
return value.ToArray();
} }
internal void AddPressedKey(Keys key) internal void AddPressedKey(Keys key)
{ {
this.pressedKeys.Add(key);
this.keyState[(int)key] = KeyState.Down; this.keyState[(int)key] = KeyState.Down;
} }
internal void RemovePressedKey(Keys key) internal void RemovePressedKey(Keys key)
{ {
this.pressedKeys.Remove(key);
this.keyState[(int)key] = KeyState.Up; this.keyState[(int)key] = KeyState.Up;
} }

View File

@ -1,175 +1,170 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
public enum Keys : byte public enum Keys : byte
{ {
None = 0, None = 0,
Back = 8, Back = 8,
Tab = 9, Tab = 9,
Enter = 13, Enter = 13,
Pause = 19, Pause = 19,
CapsLock = 20, CapsLock = 20,
Kana = 21, Kana = 21,
Kanji = 25, Kanji = 25,
Escape = 27, Escape = 27,
ImeConvert = 28, ImeConvert = 28,
ImeNoConvert = 29, ImeNoConvert = 29,
Space = 32, Space = 32,
PageUp = 33, PageUp = 33,
PageDown = 34, PageDown = 34,
End = 35, End = 35,
Home = 36, Home = 36,
Left = 37, Left = 37,
Up = 38, Up = 38,
Right = 39, Right = 39,
Down = 40, Down = 40,
Select = 41, Select = 41,
Print = 42, Print = 42,
Execute = 43, Execute = 43,
PrintScreen = 44, PrintScreen = 44,
Insert = 45, Insert = 45,
Delete = 46, Delete = 46,
Help = 47, Help = 47,
D0 = 48, D0 = 48,
D1 = 49, D1 = 49,
D2 = 50, D2 = 50,
D3 = 51, D3 = 51,
D4 = 52, D4 = 52,
D5 = 53, D5 = 53,
D6 = 54, D6 = 54,
D7 = 55, D7 = 55,
D8 = 56, D8 = 56,
D9 = 57, D9 = 57,
A = 65, A = 65,
B = 66, B = 66,
C = 67, C = 67,
D = 68, D = 68,
E = 69, E = 69,
F = 70, F = 70,
G = 71, G = 71,
H = 72, H = 72,
I = 73, I = 73,
J = 74, J = 74,
K = 75, K = 75,
L = 76, L = 76,
M = 77, M = 77,
N = 78, N = 78,
O = 79, O = 79,
P = 80, P = 80,
Q = 81, Q = 81,
R = 82, R = 82,
S = 83, S = 83,
T = 84, T = 84,
U = 85, U = 85,
V = 86, V = 86,
W = 87, W = 87,
X = 88, X = 88,
Y = 89, Y = 89,
Z = 90, Z = 90,
LeftWindows = 91, LeftWindows = 91,
RightWindows = 92, RightWindows = 92,
Apps = 93, Apps = 93,
Sleep = 95, Sleep = 95,
NumPad0 = 96, NumPad0 = 96,
NumPad1 = 97, NumPad1 = 97,
NumPad2 = 98, NumPad2 = 98,
NumPad3 = 99, NumPad3 = 99,
NumPad4 = 100, NumPad4 = 100,
NumPad5 = 101, NumPad5 = 101,
NumPad6 = 102, NumPad6 = 102,
NumPad7 = 103, NumPad7 = 103,
NumPad8 = 104, NumPad8 = 104,
NumPad9 = 105, NumPad9 = 105,
Multiply = 106, Multiply = 106,
Add = 107, Add = 107,
Separator = 108, Separator = 108,
Subtract = 109, Subtract = 109,
Decimal = 110, Decimal = 110,
Divide = 111, Divide = 111,
F1 = 112, F1 = 112,
F2 = 113, F2 = 113,
F3 = 114, F3 = 114,
F4 = 115, F4 = 115,
F5 = 116, F5 = 116,
F6 = 117, F6 = 117,
F7 = 118, F7 = 118,
F8 = 119, F8 = 119,
F9 = 120, F9 = 120,
F10 = 121, F10 = 121,
F11 = 122, F11 = 122,
F12 = 123, F12 = 123,
F13 = 124, F13 = 124,
F14 = 125, F14 = 125,
F15 = 126, F15 = 126,
F16 = 127, F16 = 127,
F17 = 128, F17 = 128,
F18 = 129, F18 = 129,
F19 = 130, F19 = 130,
F20 = 131, F20 = 131,
F21 = 132, F21 = 132,
F22 = 133, F22 = 133,
F23 = 134, F23 = 134,
F24 = 135, F24 = 135,
NumLock = 144, NumLock = 144,
Scroll = 145, Scroll = 145,
LeftShift = 160, LeftShift = 160,
RightShift = 161, RightShift = 161,
LeftControl = 162, LeftControl = 162,
RightControl = 163, RightControl = 163,
LeftAlt = 164, LeftAlt = 164,
RightAlt = 165, RightAlt = 165,
BrowserBack = 166, BrowserBack = 166,
BrowserForward = 167, BrowserForward = 167,
BrowserRefresh = 168, BrowserRefresh = 168,
BrowserStop = 169, BrowserStop = 169,
BrowserSearch = 170, BrowserSearch = 170,
BrowserFavorites = 171, BrowserFavorites = 171,
BrowserHome = 172, BrowserHome = 172,
VolumeMute = 173, VolumeMute = 173,
VolumeDown = 174, VolumeDown = 174,
VolumeUp = 175, VolumeUp = 175,
MediaNextTrack = 176, MediaNextTrack = 176,
MediaPreviousTrack = 177, MediaPreviousTrack = 177,
MediaStop = 178, MediaStop = 178,
MediaPlayPause = 179, MediaPlayPause = 179,
LaunchMail = 180, LaunchMail = 180,
SelectMedia = 181, SelectMedia = 181,
LaunchApplication1 = 182, LaunchApplication1 = 182,
LaunchApplication2 = 183, LaunchApplication2 = 183,
OemSemicolon = 186, OemSemicolon = 186,
OemPlus = 187, OemPlus = 187,
OemComma = 188, OemComma = 188,
OemMinus = 189, OemMinus = 189,
OemPeriod = 190, OemPeriod = 190,
OemQuestion = 191, OemQuestion = 191,
OemTilde = 192, OemTilde = 192,
ChatPadGreen = 202, ChatPadGreen = 202,
ChatPadOrange = 203, ChatPadOrange = 203,
OemOpenBrackets = 219, OemOpenBrackets = 219,
OemPipe = 220, OemPipe = 220,
OemCloseBrackets = 221, OemCloseBrackets = 221,
OemQuotes = 222, OemQuotes = 222,
Oem8 = 223, Oem8 = 223,
OemBackslash = 226, OemBackslash = 226,
ProcessKey = 229, ProcessKey = 229,
OemCopy = 242, OemCopy = 242,
OemAuto = 243, OemAuto = 243,
OemEnlW = 244, OemEnlW = 244,
Attn = 246, Attn = 246,
Crsel = 247, Crsel = 247,
Exsel = 248, Exsel = 248,
EraseEof = 249, EraseEof = 249,
Play = 250, Play = 250,
Zoom = 251, Zoom = 251,
Pa1 = 253, Pa1 = 253,
OemClear = 254 OemClear = 254
} }
} }

View File

@ -1,8 +1,3 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license

View File

@ -1,8 +1,6 @@
#region Using Statements
using System; using System;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.Development;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -10,48 +8,39 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public static class Mouse public static class Mouse
{ {
private static IMouse mouse; private static IMouse mouse;
public static IntPtr WindowHandle
{
get
{
return mouse != null ? mouse.WindowHandle : IntPtr.Zero;
}
set
{
if (mouse != null)
mouse.WindowHandle = value;
}
}
static Mouse() static Mouse()
{ {
mouse = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse; mouse = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse;
} }
public static IntPtr WindowHandle
{
get
{
return mouse != null ? mouse.WindowHandle : IntPtr.Zero;
}
set
{
if (mouse != null)
{
mouse.WindowHandle = value;
}
}
}
public static MouseState GetState() public static MouseState GetState()
{ {
if (mouse != null) return (mouse != null) ? mouse.GetState() : new MouseState();
{
return mouse.GetState();
}
else
{
return new MouseState();
}
} }
public static void SetPosition(int x, int y) public static void SetPosition(int x, int y)
{ {
if (mouse != null) if (mouse != null)
{
mouse.SetPosition(x, y); mouse.SetPosition(x, y);
}
} }
} }
} }

View File

@ -1,7 +1,5 @@
#region Using Statements
using System; using System;
using ANX.Framework.NonXNA.Development;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -10,38 +8,34 @@ using System;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
#if !WINDOWSMETRO //TODO: search replacement for Win8 #if !WINDOWSMETRO //TODO: search replacement for Win8
[SerializableAttribute] [Serializable]
#endif #endif
public struct MouseState [PercentageComplete(100)]
{ [TestState(TestStateAttribute.TestState.Untested)]
private int x; public struct MouseState
private int y; {
private int scrollWheel; public ButtonState LeftButton { get; private set; }
private ButtonState leftButton; public ButtonState MiddleButton { get; private set; }
private ButtonState middleButton; public ButtonState RightButton { get; private set; }
private ButtonState rightButton; public ButtonState XButton1 { get; private set; }
private ButtonState xButton1; public ButtonState XButton2 { get; private set; }
private ButtonState xButton2; public int ScrollWheelValue { get; private set; }
public MouseState (int x, int y, int scrollWheel,ButtonState leftButton,ButtonState middleButton,ButtonState rightButton,ButtonState xButton1,ButtonState xButton2) public int X { get; private set; }
{ public int Y { get; private set; }
this.x = x;
this.y = y;
this.scrollWheel = scrollWheel;
this.leftButton = leftButton;
this.middleButton = middleButton;
this.rightButton = rightButton;
this.xButton1 = xButton1;
this.xButton2 = xButton2;
}
public ButtonState LeftButton { get { return this.leftButton; } } public MouseState(int x, int y, int scrollWheel, ButtonState leftButton, ButtonState middleButton,
public ButtonState MiddleButton { get { return this.middleButton; } } ButtonState rightButton, ButtonState xButton1, ButtonState xButton2)
public ButtonState RightButton { get { return this.rightButton; } } : this()
public ButtonState XButton1 { get { return this.xButton1; } } {
public ButtonState XButton2 { get { return this.xButton2; } } X = x;
public int ScrollWheelValue { get { return this.scrollWheel; } } Y = y;
public int X { get { return this.x; } } ScrollWheelValue = scrollWheel;
public int Y { get { return this.y; } } LeftButton = leftButton;
MiddleButton = middleButton;
RightButton = rightButton;
XButton1 = xButton1;
XButton2 = xButton2;
}
public static bool operator ==(MouseState left, MouseState right) public static bool operator ==(MouseState left, MouseState right)
{ {
@ -69,30 +63,27 @@ namespace ANX.Framework.Input
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is MouseState) if (obj != null && obj is MouseState)
{
return this == (MouseState)obj; return this == (MouseState)obj;
}
return false; return false;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return ((((((this.x.GetHashCode() ^ this.y.GetHashCode()) ^ this.leftButton.GetHashCode()) ^ this.rightButton.GetHashCode()) ^ this.middleButton.GetHashCode()) ^ this.xButton1.GetHashCode()) ^ this.xButton2.GetHashCode()) ^ this.scrollWheel.GetHashCode(); return X.GetHashCode() ^ Y.GetHashCode() ^ LeftButton.GetHashCode() ^ RightButton.GetHashCode() ^
} MiddleButton.GetHashCode() ^ XButton1.GetHashCode() ^ XButton2.GetHashCode() ^ ScrollWheelValue.GetHashCode();
}
public override string ToString() public override string ToString()
{ {
string buttons = String.Empty; string buttons = LeftButton == ButtonState.Pressed ? "Left" : "";
buttons += RightButton == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Right" : "";
buttons += MiddleButton == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Middle" : "";
buttons += XButton1 == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "XButton1" : "";
buttons += XButton2 == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "XButton2" : "";
buttons += leftButton == ButtonState.Pressed ? "Left" : ""; return String.Format("{{X:{0} Y:{1} Buttons:{2} Wheel:{3}}}", X, Y, buttons, ScrollWheelValue);
buttons += rightButton == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Right" : ""; }
buttons += middleButton == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "Middle" : ""; }
buttons += xButton1 == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "XButton1" : "";
buttons += xButton2 == ButtonState.Pressed ? (buttons.Length > 0 ? " " : "") + "XButton2" : "";
return string.Format("{{X:{0} Y:{1} Buttons:{2} Wheel:{3}}}", this.x, this.y, buttons, this.scrollWheel);
}
}
} }

View File

@ -1,27 +1,24 @@
#region Using Statements
using System; using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input.Touch namespace ANX.Framework.Input.Touch
{ {
[Flags] [Flags]
public enum GestureType public enum GestureType
{ {
None = 0, None = 0,
Tap = 1, Tap = 1,
DoubleTap = 2, DoubleTap = 2,
Hold = 4, Hold = 4,
HorizontalDrag = 8, HorizontalDrag = 8,
VerticalDrag = 16, VerticalDrag = 16,
FreeDrag = 32, FreeDrag = 32,
Pinch = 64, Pinch = 64,
Flick = 128, Flick = 128,
DragComplete = 256, DragComplete = 256,
PinchComplete = 512, PinchComplete = 512,
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using ANX.Framework.NonXNA.Development;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -8,6 +9,8 @@ using System.Collections.Generic;
namespace ANX.Framework.Input.Touch namespace ANX.Framework.Input.Touch
{ {
[PercentageComplete(90)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct TouchCollection : IList<TouchLocation>, ICollection<TouchLocation>, IEnumerable<TouchLocation>, IEnumerable public struct TouchCollection : IList<TouchLocation>, ICollection<TouchLocation>, IEnumerable<TouchLocation>, IEnumerable
{ {
#region Enumerator (helper struct) #region Enumerator (helper struct)

View File

@ -1,7 +1,5 @@
#region Using Statements
using System; using System;
using ANX.Framework.NonXNA.Development;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -9,6 +7,8 @@ using System;
namespace ANX.Framework.Input.Touch namespace ANX.Framework.Input.Touch
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct TouchLocation : IEquatable<TouchLocation> public struct TouchLocation : IEquatable<TouchLocation>
{ {
#region Private #region Private

View File

@ -1,19 +1,14 @@
#region Using Statements
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Input.Touch namespace ANX.Framework.Input.Touch
{ {
public enum TouchLocationState public enum TouchLocationState
{ {
Invalid = 0, Invalid = 0,
Released = 1, Released = 1,
Pressed = 2, Pressed = 2,
Moved = 3, Moved = 3,
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA.InputSystem; using ANX.Framework.NonXNA.InputSystem;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
@ -8,6 +9,8 @@ using ANX.Framework.NonXNA.InputSystem;
namespace ANX.Framework.Input.Touch namespace ANX.Framework.Input.Touch
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public static class TouchPanel public static class TouchPanel
{ {
#region Private #region Private

View File

@ -1,7 +1,4 @@
#region Using Statements using ANX.Framework.NonXNA.Development;
using System;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -9,18 +6,11 @@ using System;
namespace ANX.Framework.Input.Touch namespace ANX.Framework.Input.Touch
{ {
public struct TouchPanelCapabilities [PercentageComplete(100)]
{ [TestState(TestStateAttribute.TestState.Tested)]
public bool IsConnected public struct TouchPanelCapabilities
{ {
get; public bool IsConnected { get; set; }
set; public int MaximumTouchCount { get; set; }
} }
public int MaximumTouchCount
{
get;
set;
}
}
} }

View File

@ -9,8 +9,8 @@ namespace ANX.Framework.NonXNA
public interface IGamePad public interface IGamePad
{ {
GamePadCapabilities GetCapabilities(PlayerIndex playerIndex); GamePadCapabilities GetCapabilities(PlayerIndex playerIndex);
GamePadState GetState(PlayerIndex playerIndex, out bool isConnected, out int packetNumber); GamePadState GetState(PlayerIndex playerIndex);
GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode, out bool isConnected, out int packetNumber); GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode);
bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor); bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor);
} }
} }

View File

@ -44,6 +44,7 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ANX.Framework.Windows.XAudio")] [assembly: InternalsVisibleTo("ANX.Framework.Windows.XAudio")]
[assembly: InternalsVisibleTo("ANX.InputSystem.Recording")] [assembly: InternalsVisibleTo("ANX.InputSystem.Recording")]
[assembly: InternalsVisibleTo("ANX.InputDevices.PsVita")] [assembly: InternalsVisibleTo("ANX.InputDevices.PsVita")]
[assembly: InternalsVisibleTo("ANX.InputDevices.Test")]
[assembly: InternalsVisibleTo("ANX.InputDevices.Windows.XInput")] [assembly: InternalsVisibleTo("ANX.InputDevices.Windows.XInput")]
[assembly: InternalsVisibleTo("ANX.PlatformSystem.Windows")] [assembly: InternalsVisibleTo("ANX.PlatformSystem.Windows")]
[assembly: InternalsVisibleTo("ANX.PlatformSystem.Linux")] [assembly: InternalsVisibleTo("ANX.PlatformSystem.Linux")]

View File

@ -1,12 +1,8 @@
#region Using Statements
using System; using System;
using System.Collections.Generic; using ANX.Framework;
using System.Linq; using ANX.Framework.Input;
using System.Text;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
@ -15,22 +11,22 @@ namespace ANX.InputDevices.OpenTK
{ {
public class GamePad : IGamePad public class GamePad : IGamePad
{ {
public Framework.Input.GamePadCapabilities GetCapabilities(Framework.PlayerIndex playerIndex) public GamePadCapabilities GetCapabilities(PlayerIndex playerIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Framework.Input.GamePadState GetState(Framework.PlayerIndex playerIndex, out bool isConnected, out int packetNumber) public GamePadState GetState(PlayerIndex playerIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Framework.Input.GamePadState GetState(Framework.PlayerIndex playerIndex, Framework.Input.GamePadDeadZone deadZoneMode, out bool isConnected, out int packetNumber) public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool SetVibration(Framework.PlayerIndex playerIndex, float leftMotor, float rightMotor) public bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -47,27 +47,23 @@ namespace ANX.InputDevices.PsVita
}; };
} }
public GamePadState GetState(PlayerIndex playerIndex, out bool isConnected, out int packetNumber) public GamePadState GetState(PlayerIndex playerIndex)
{ {
SceInput.GamePadData data = SceInput.GamePad.GetData((int)playerIndex); return GetState(playerIndex, GamePadDeadZone.None);
isConnected = data.Skip == false;
packetNumber = 0; // TODO
return new GamePadState(new Vector2(data.AnalogLeftX, data.AnalogLeftY),
new Vector2(data.AnalogRightX, data.AnalogRightY), 0f, 0f, ConvertButtons(data.ButtonsDown));
} }
public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode, public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
out bool isConnected, out int packetNumber)
{ {
// TODO: GamePadDeadZone // TODO: GamePadDeadZone
SceInput.GamePadData data = SceInput.GamePad.GetData((int)playerIndex); SceInput.GamePadData data = SceInput.GamePad.GetData((int)playerIndex);
isConnected = data.Skip == false;
packetNumber = 0; // TODO
return new GamePadState(new Vector2(data.AnalogLeftX, data.AnalogLeftY), return new GamePadState(new Vector2(data.AnalogLeftX, data.AnalogLeftY),
new Vector2(data.AnalogRightX, data.AnalogRightY), 0f, 0f, ConvertButtons(data.ButtonsDown)); new Vector2(data.AnalogRightX, data.AnalogRightY), 0f, 0f, ConvertButtons(data.ButtonsDown))
{
IsConnected = data.Skip == false,
PacketNumber = 0 // TODO
};
} }
public bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor) public bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)

View File

@ -15,47 +15,51 @@ namespace ANX.InputDevices.Test
return new GamePadCapabilities(); return new GamePadCapabilities();
} }
public GamePadState GetState(PlayerIndex playerIndex, out bool isConnected, public GamePadState GetState(PlayerIndex playerIndex)
out int packetNumber)
{ {
GamePadState gamepad; GamePadState gamepad;
switch (playerIndex) switch (playerIndex)
{ {
case PlayerIndex.One: case PlayerIndex.One:
isConnected = true; gamepad = new GamePadState(new Vector2(100, 100), new Vector2(100, 100), 0.5f, 0.5f, Buttons.A, Buttons.B)
packetNumber = 0; {
gamepad = new GamePadState(new Vector2(100, 100), new Vector2(100, 100), IsConnected = true,
0.5f, 0.5f, Buttons.A, Buttons.B); PacketNumber = 0,
};
break; break;
case PlayerIndex.Two: case PlayerIndex.Two:
isConnected = true; gamepad = new GamePadState(new Vector2(200, 200), new Vector2(100, 100), 0.5f, 0.5f, Buttons.A,
packetNumber = 0; Buttons.BigButton)
gamepad = new GamePadState(new Vector2(200, 200), new Vector2(100, 100), {
0.5f, 0.5f, Buttons.A, Buttons.BigButton); IsConnected = true,
PacketNumber = 0,
};
break; break;
case PlayerIndex.Three: case PlayerIndex.Three:
isConnected = true; gamepad = new GamePadState(new Vector2(100, 100), new Vector2(100, 100), 0.5f, 0.5f, Buttons.A, Buttons.X)
packetNumber = 0; {
gamepad = new GamePadState(new Vector2(100, 100), new Vector2(100, 100), IsConnected = true,
0.5f, 0.5f, Buttons.A, Buttons.X); PacketNumber = 0,
};
break; break;
case PlayerIndex.Four: case PlayerIndex.Four:
default: default:
isConnected = false; gamepad = new GamePadState()
packetNumber = 0; {
gamepad = new GamePadState(); IsConnected = false,
PacketNumber = 0,
};
break; break;
} }
return gamepad; return gamepad;
} }
public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode, public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
out bool isConnected, out int packetNumber)
{ {
return this.GetState(playerIndex, out isConnected, out packetNumber); return GetState(playerIndex);
} }
public bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor) public bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)

View File

@ -88,20 +88,16 @@ namespace ANX.InputDevices.Windows.XInput
#endregion #endregion
#region GetState #region GetState
public GamePadState GetState(PlayerIndex playerIndex, out bool isConnected, out int packetNumber) public GamePadState GetState(PlayerIndex playerIndex)
{ {
return GetState(playerIndex, GamePadDeadZone.None, out isConnected, out packetNumber); return GetState(playerIndex, GamePadDeadZone.None);
} }
public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode, out bool isConnected, public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
out int packetNumber)
{ {
isConnected = controller[(int)playerIndex].IsConnected; bool isConnected = controller[(int)playerIndex].IsConnected;
if (isConnected == false) if (isConnected == false)
{
packetNumber = 0;
return emptyState; return emptyState;
}
State nativeState = controller[(int)playerIndex].GetState(); State nativeState = controller[(int)playerIndex].GetState();
Vector2 leftThumb = ApplyDeadZone(nativeState.Gamepad.LeftThumbX, nativeState.Gamepad.LeftThumbY, Vector2 leftThumb = ApplyDeadZone(nativeState.Gamepad.LeftThumbX, nativeState.Gamepad.LeftThumbY,
@ -109,11 +105,12 @@ namespace ANX.InputDevices.Windows.XInput
Vector2 rightThumb = ApplyDeadZone(nativeState.Gamepad.RightThumbX, nativeState.Gamepad.RightThumbY, Vector2 rightThumb = ApplyDeadZone(nativeState.Gamepad.RightThumbX, nativeState.Gamepad.RightThumbY,
RightThumbDeadZoneSquare, deadZoneMode); RightThumbDeadZoneSquare, deadZoneMode);
var result = new GamePadState(leftThumb, rightThumb, nativeState.Gamepad.LeftTrigger * triggerRangeFactor, return new GamePadState(leftThumb, rightThumb, nativeState.Gamepad.LeftTrigger * triggerRangeFactor,
nativeState.Gamepad.RightTrigger * triggerRangeFactor, FormatConverter.Translate(nativeState.Gamepad.Buttons)); nativeState.Gamepad.RightTrigger * triggerRangeFactor, FormatConverter.Translate(nativeState.Gamepad.Buttons))
{
packetNumber = nativeState.PacketNumber; PacketNumber = nativeState.PacketNumber,
return result; IsConnected = isConnected
};
} }
#endregion #endregion

View File

@ -62,12 +62,12 @@ namespace ANX.InputSystem.Recording
return realGamePad.GetCapabilities(playerIndex); return realGamePad.GetCapabilities(playerIndex);
} }
public GamePadState GetState(PlayerIndex playerIndex, out bool isConnected, out int packetNumber) public GamePadState GetState(PlayerIndex playerIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode, out bool isConnected, out int packetNumber) public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }