#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
* Copyright 2009-2020 Ethan Lee and the MonoGame Team
*
* Released under the Microsoft Public License.
* See LICENSE for details.
*/
#endregion
namespace Microsoft.Xna.Framework.Input
{
public struct GamePadTriggers
{
#region Public Properties
public float Left
{
get
{
return left;
}
}
public float Right
{
get
{
return right;
}
}
#endregion
#region Private Variables
private float left;
private float right;
#endregion
#region Public Constructor
public GamePadTriggers(float leftTrigger, float rightTrigger)
{
left = MathHelper.Clamp(leftTrigger, 0.0f, 1.0f);
right = MathHelper.Clamp(rightTrigger, 0.0f, 1.0f);
}
#endregion
#region Internal Constructor
internal GamePadTriggers(
float leftTrigger,
float rightTrigger,
GamePadDeadZone deadZoneMode
) {
/* XNA applies dead zones before rounding/clamping values.
* The public constructor does not allow this because the
* dead zone must be known first.
*/
if (deadZoneMode == GamePadDeadZone.None)
{
left = MathHelper.Clamp(leftTrigger, 0.0f, 1.0f);
right = MathHelper.Clamp(rightTrigger, 0.0f, 1.0f);
}
else
{
left = MathHelper.Clamp(
GamePad.ExcludeAxisDeadZone(
leftTrigger,
GamePad.TriggerThreshold
),
0.0f,
1.0f
);
right = MathHelper.Clamp(
GamePad.ExcludeAxisDeadZone(
rightTrigger,
GamePad.TriggerThreshold
),
0.0f,
1.0f
);
}
}
#endregion
#region Public Static Operators and Override Methods
///
/// Determines whether two specified instances of are
/// equal.
///
/// The first object to compare.
/// The second object to compare.
///
/// True if and are equal;
/// otherwise, false.
///
public static bool operator ==(GamePadTriggers left, GamePadTriggers right)
{
return ( (MathHelper.WithinEpsilon(left.left, right.left)) &&
(MathHelper.WithinEpsilon(left.right, right.right)) );
}
///
/// Determines whether two specified instances of are
/// not equal.
///
/// The first object to compare.
/// The second object to compare.
///
/// True if and are not equal;
/// otherwise, false.
///
public static bool operator !=(GamePadTriggers left, GamePadTriggers right)
{
return !(left == right);
}
///
/// Returns a value indicating whether this instance is equal to a specified object.
///
/// An object to compare to this instance.
///
/// True if is a and has the
/// same value as this instance; otherwise, false.
///
public override bool Equals(object obj)
{
return (obj is GamePadTriggers) && (this == (GamePadTriggers) obj);
}
public override int GetHashCode ()
{
return this.Left.GetHashCode() + this.Right.GetHashCode();
}
#endregion
}
}