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 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) 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.packetNumber = 0;
this.buttonsValue = this.buttons.Buttons | this.dPad.Buttons; this.buttonsValue = this.buttons.Buttons | this.dPad.Buttons;
this.IsConnected = true;
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; } }
public GamePadDPad DPad { get { return this.dPad; } }
public bool IsConnected
{ {
get return (this.buttonsValue & button) == button;
{
return this.isConnected;
}
internal set
{
this.isConnected = value;
}
} }
public int PacketNumber public bool IsButtonUp(Buttons button)
{ {
get return (this.buttonsValue & button) != button;
{
return this.packetNumber;
} }
internal set
{
this.packetNumber = value;
}
}
public GamePadThumbSticks ThumbSticks { get { return this.thumbSticks; } }
public GamePadTriggers Triggers { get { return this.triggers; } }
} }
} }

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
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct GamePadTriggers public struct GamePadTriggers
{ {
#region Private Members public float Left { get; private set; }
private float left; public float Right { get; private set; }
private float right;
#endregion // Private Members public GamePadTriggers(float leftTrigger, float rightTrigger)
: this()
public GamePadTriggers (float leftTrigger,float rightTrigger)
{ {
if (leftTrigger>1) Left = MathHelper.Clamp(leftTrigger, 0f, 1f);
{ Right = MathHelper.Clamp(rightTrigger, 0f, 1f);
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 int GetHashCode()
{ {
return left.GetHashCode() ^ right.GetHashCode(); return Left.GetHashCode() ^ Right.GetHashCode();
} }
public override string ToString() public override string ToString()
{ {
return String.Format("{{Left:{0} Right:{1}}}", left, right); return String.Format("{{Left:{0} Right:{1}}}", Left, Right);
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj != null && obj.GetType() == typeof(GamePadTriggers)) if (obj != null && obj.GetType() == typeof(GamePadTriggers))
{
return this == (GamePadTriggers)obj; return this == (GamePadTriggers)obj;
}
return false; return false;
} }
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) 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 float Left { get { return this.left; } }
public float Right { get { return this.right; } }
} }
} }

View File

@ -1,15 +1,10 @@
#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,
@ -20,6 +15,6 @@ namespace ANX.Framework.Input
Guitar, Guitar,
AlternateGuitar, AlternateGuitar,
DrumKit, DrumKit,
BigButtonPad=768 BigButtonPad = 768
} }
} }

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,15 +8,12 @@ using ANX.Framework.NonXNA;
namespace ANX.Framework.Input namespace ANX.Framework.Input
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public static class Keyboard public static class Keyboard
{ {
private static IKeyboard keyboard; private static IKeyboard keyboard;
static Keyboard()
{
keyboard = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard;
}
internal static IntPtr WindowHandle internal static IntPtr WindowHandle
{ {
get get
@ -28,10 +23,13 @@ namespace ANX.Framework.Input
set set
{ {
if (keyboard != null) if (keyboard != null)
{
keyboard.WindowHandle = value; keyboard.WindowHandle = value;
} }
} }
static Keyboard()
{
keyboard = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard;
} }
public static KeyboardState GetState() public static KeyboardState GetState()
@ -39,10 +37,9 @@ namespace ANX.Framework.Input
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;
return false;
} }
public KeyState this[Keys key] return true;
{
get
{
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,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,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,15 +8,12 @@ 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;
static Mouse()
{
mouse = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse;
}
public static IntPtr WindowHandle public static IntPtr WindowHandle
{ {
get get
@ -28,30 +23,24 @@ namespace ANX.Framework.Input
set set
{ {
if (mouse != null) if (mouse != null)
{
mouse.WindowHandle = value; mouse.WindowHandle = value;
} }
} }
static Mouse()
{
mouse = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse;
} }
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
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
public struct MouseState public struct MouseState
{ {
private int x; public ButtonState LeftButton { get; private set; }
private int y; public ButtonState MiddleButton { get; private set; }
private int scrollWheel; public ButtonState RightButton { get; private set; }
private ButtonState leftButton; public ButtonState XButton1 { get; private set; }
private ButtonState middleButton; public ButtonState XButton2 { get; private set; }
private ButtonState rightButton; public int ScrollWheelValue { get; private set; }
private ButtonState xButton1; public int X { get; private set; }
private ButtonState xButton2; public int Y { get; private set; }
public MouseState (int x, int y, int scrollWheel,ButtonState leftButton,ButtonState middleButton,ButtonState rightButton,ButtonState xButton1,ButtonState xButton2)
{
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,8 +1,5 @@
#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

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,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,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
{ {
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public struct TouchPanelCapabilities public struct TouchPanelCapabilities
{ {
public bool IsConnected public bool IsConnected { get; set; }
{ public int MaximumTouchCount { get; set; }
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();
} }