2013-12-24 11:52:57 +00:00
#region License
2013-12-19 15:28:20 +00:00
//
// GamePadCapabilities.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2013 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
2013-12-24 11:52:57 +00:00
#endregion
2013-12-19 15:28:20 +00:00
using System ;
namespace OpenTK.Input
{
2014-01-02 00:33:08 +00:00
/// <summary>
/// Describes the capabilities of a <c>GamePad</c> input device.
/// </summary>
2013-12-22 21:01:04 +00:00
public struct GamePadCapabilities : IEquatable < GamePadCapabilities >
2013-12-19 15:28:20 +00:00
{
2013-12-23 23:15:28 +00:00
Buttons buttons ;
2013-12-24 11:47:09 +00:00
GamePadAxes axes ;
2013-12-23 23:15:28 +00:00
byte gamepad_type ;
bool is_connected ;
#region Constructors
2013-12-24 11:47:09 +00:00
internal GamePadCapabilities ( GamePadType type , GamePadAxes axes , Buttons buttons , bool is_connected )
2013-12-23 23:15:28 +00:00
: this ( )
2013-12-19 15:28:20 +00:00
{
2013-12-23 23:15:28 +00:00
gamepad_type = ( byte ) type ;
2013-12-24 11:47:09 +00:00
this . axes = axes ;
2013-12-23 23:15:28 +00:00
this . buttons = buttons ;
this . is_connected = is_connected ;
2013-12-19 15:28:20 +00:00
}
2013-12-23 23:15:28 +00:00
#endregion
#region Public Members
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="GamePadType"/> value describing the type of a <see cref="GamePad"/> input device.
/// This value depends on the connected device and the drivers in use. If <c>IsConnected</c>
/// is false, then this value will be <c>GamePadType.Unknown</c>.
/// </summary>
/// <value>The <c>GamePadType</c> of the connected input device.</value>
2013-12-23 23:15:28 +00:00
public GamePadType GamePadType
2013-12-19 15:28:20 +00:00
{
2013-12-23 23:15:28 +00:00
get { return ( GamePadType ) gamepad_type ; }
2013-12-19 15:28:20 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// an up digital pad button.
/// </summary>
/// <value><c>true</c> if this instance has an up digital pad button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasDPadUpButton
2013-12-19 15:28:20 +00:00
{
2013-12-23 23:15:28 +00:00
get { return ( buttons & Buttons . DPadUp ) ! = 0 ; }
2013-12-19 15:28:20 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a down digital pad button.
/// </summary>
/// <value><c>true</c> if this instance has a down digital pad button; otherwise, <c>false</c>.</value>
public bool HasDPadDownButton
2013-12-19 15:28:20 +00:00
{
2014-01-02 00:33:08 +00:00
get { return ( buttons & Buttons . DPadDown ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a left digital pad button.
/// </summary>
/// <value><c>true</c> if this instance has a left digital pad button; otherwise, <c>false</c>.</value>
public bool HasDPadLeftButton
2013-12-23 23:15:28 +00:00
{
2014-01-02 00:33:08 +00:00
get { return ( buttons & Buttons . DPadLeft ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a right digital pad button.
/// </summary>
/// <value><c>true</c> if this instance has a right digital pad button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasDPadRightButton
{
get { return ( buttons & Buttons . DPadRight ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// an A button.
/// </summary>
/// <value><c>true</c> if this instance has an A button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasAButton
{
get { return ( buttons & Buttons . A ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a B button.
/// </summary>
/// <value><c>true</c> if this instance has a B button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasBButton
{
get { return ( buttons & Buttons . B ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a X button.
/// </summary>
/// <value><c>true</c> if this instance has a X button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasXButton
{
get { return ( buttons & Buttons . X ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a Y button.
/// </summary>
/// <value><c>true</c> if this instance has a Y button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasYButton
{
get { return ( buttons & Buttons . Y ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a left stick button.
/// </summary>
/// <value><c>true</c> if this instance has a left stick button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasLeftStickButton
{
get { return ( buttons & Buttons . LeftStick ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a right stick button.
/// </summary>
/// <value><c>true</c> if this instance has a right stick button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasRightStickButton
{
get { return ( buttons & Buttons . RightStick ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a left shoulder button.
/// </summary>
/// <value><c>true</c> if this instance has a left shoulder button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasLeftShoulderButton
{
get { return ( buttons & Buttons . LeftShoulder ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a right shoulder button.
/// </summary>
/// <value><c>true</c> if this instance has a right shoulder button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasRightShoulderButton
{
get { return ( buttons & Buttons . RightShoulder ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a back button.
/// </summary>
/// <value><c>true</c> if this instance has a back button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasBackButton
{
get { return ( buttons & Buttons . Back ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a big button. (also known as "guide" or "home" button).
/// </summary>
/// <value><c>true</c> if this instance has a big button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasBigButton
{
get { return ( buttons & Buttons . BigButton ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a start button.
/// </summary>
/// <value><c>true</c> if this instance has a start button; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasStartButton
{
get { return ( buttons & Buttons . Start ) ! = 0 ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a left thumbstick with a x-axis.
/// </summary>
/// <value><c>true</c> if this instance has a left thumbstick with a x-axis; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasLeftXThumbStick
{
2013-12-24 11:47:09 +00:00
get { return ( axes & GamePadAxes . LeftX ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a left thumbstick with a y-axis.
/// </summary>
/// <value><c>true</c> if this instance has a left thumbstick with a y-axis; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasLeftYThumbStick
{
2013-12-24 11:47:09 +00:00
get { return ( axes & GamePadAxes . LeftY ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a right thumbstick with a x-axis.
/// </summary>
/// <value><c>true</c> if this instance has a right thumbstick with a x-axis; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasRightXThumbStick
{
2013-12-24 11:47:09 +00:00
get { return ( axes & GamePadAxes . RightX ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a right thumbstick with a y-axis.
/// </summary>
/// <value><c>true</c> if this instance has a right thumbstick with a y-axis; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasRightYThumbStick
{
2013-12-24 11:47:09 +00:00
get { return ( axes & GamePadAxes . RightY ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a left trigger.
/// </summary>
/// <value><c>true</c> if this instance has a left trigger; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasLeftTrigger
{
2013-12-24 11:47:09 +00:00
get { return ( axes & GamePadAxes . LeftTrigger ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a right trigger.
/// </summary>
/// <value><c>true</c> if this instance has a right trigger; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasRightTrigger
{
2013-12-24 11:47:09 +00:00
get { return ( axes & GamePadAxes . RightTrigger ) ! = 0 ; }
2013-12-23 23:15:28 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a low-frequency vibration motor.
/// </summary>
/// <value><c>true</c> if this instance has a low-frequency vibration motor; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasLeftVibrationMotor
{
get { return false ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a high-frequency vibration motor.
/// </summary>
/// <value><c>true</c> if this instance has a high frequency vibration motor; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasRightVibrationMotor
{
get { return false ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> has
/// a microphone input.
/// </summary>
/// <value><c>true</c> if this instance has a microphone input; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool HasVoiceSupport
{
get { return false ; }
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Gets a <see cref="System.Boolean"/> value describing whether this <c>GamePad</c> is
/// currently connected.
/// </summary>
/// <value><c>true</c> if this instance is currently connected; otherwise, <c>false</c>.</value>
2013-12-23 23:15:28 +00:00
public bool IsConnected
{
get { return is_connected ; }
2013-12-19 15:28:20 +00:00
}
2013-12-22 21:01:04 +00:00
2014-01-02 00:33:08 +00:00
/// <param name="left">A <see cref="GamePadCapabilities"/> structure to test for equality.</param>
/// <param name="right">A <see cref="GamePadCapabilities"/> structure to test for equality.</param>
2013-12-22 21:01:04 +00:00
public static bool operator = = ( GamePadCapabilities left , GamePadCapabilities right )
{
return left . Equals ( right ) ;
}
2014-01-02 00:33:08 +00:00
/// <param name="left">A <see cref="GamePadCapabilities"/> structure to test for inequality.</param>
/// <param name="right">A <see cref="GamePadCapabilities"/> structure to test for inequality.</param>
2013-12-22 21:01:04 +00:00
public static bool operator ! = ( GamePadCapabilities left , GamePadCapabilities right )
{
return ! left . Equals ( right ) ;
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.GamePadCapabilities"/>.
/// </summary>
/// <returns>A <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.GamePadCapabilities"/>.</returns>
2013-12-22 21:01:04 +00:00
public override string ToString ( )
{
return String . Format (
2013-12-24 11:47:09 +00:00
"{{Type: {0}; Axes: {1}; Buttons: {2}; Connected: {3}}}" ,
GamePadType ,
Convert . ToString ( ( int ) axes , 2 ) ,
Convert . ToString ( ( int ) buttons , 2 ) ,
IsConnected ) ;
2013-12-22 21:01:04 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Serves as a hash function for a <see cref="OpenTK.Input.GamePadCapabilities"/> object.
/// </summary>
/// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a
/// hash table.</returns>
2013-12-22 21:01:04 +00:00
public override int GetHashCode ( )
{
return
2013-12-23 23:15:28 +00:00
buttons . GetHashCode ( ) ^
is_connected . GetHashCode ( ) ^
gamepad_type . GetHashCode ( ) ;
2013-12-22 21:01:04 +00:00
}
2014-01-02 00:33:08 +00:00
/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="OpenTK.Input.GamePadCapabilities"/>.
/// </summary>
/// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="OpenTK.Input.GamePadCapabilities"/>.</param>
/// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current
/// <see cref="OpenTK.Input.GamePadCapabilities"/>; otherwise, <c>false</c>.</returns>
2013-12-22 21:01:04 +00:00
public override bool Equals ( object obj )
{
return
obj is GamePadCapabilities & &
Equals ( ( GamePadCapabilities ) obj ) ;
}
2013-12-23 23:15:28 +00:00
#endregion
2013-12-22 21:01:04 +00:00
#region IEquatable < GamePadCapabilities > Members
2014-01-02 00:33:08 +00:00
/// <summary>
/// Determines whether the specified <see cref="OpenTK.Input.GamePadCapabilities"/> is equal to the current <see cref="OpenTK.Input.GamePadCapabilities"/>.
/// </summary>
/// <param name="other">The <see cref="OpenTK.Input.GamePadCapabilities"/> to compare with the current <see cref="OpenTK.Input.GamePadCapabilities"/>.</param>
/// <returns><c>true</c> if the specified <see cref="OpenTK.Input.GamePadCapabilities"/> is equal to the current
/// <see cref="OpenTK.Input.GamePadCapabilities"/>; otherwise, <c>false</c>.</returns>
2013-12-22 21:01:04 +00:00
public bool Equals ( GamePadCapabilities other )
{
return
2013-12-23 23:15:28 +00:00
buttons = = other . buttons & &
is_connected = = other . is_connected & &
gamepad_type = = other . gamepad_type ;
2013-12-22 21:01:04 +00:00
}
#endregion
2013-12-19 15:28:20 +00:00
}
}