#region License // // GamePadCapabilities.cs // // Author: // Stefanos A. // // 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. // #endregion using System; namespace OpenTK.Input { /// /// Describes the capabilities of a GamePad input device. /// public struct GamePadCapabilities : IEquatable { Buttons buttons; GamePadAxes axes; byte gamepad_type; bool is_connected; #region Constructors internal GamePadCapabilities(GamePadType type, GamePadAxes axes, Buttons buttons, bool is_connected) : this() { gamepad_type = (byte)type; this.axes = axes; this.buttons = buttons; this.is_connected = is_connected; } #endregion #region Public Members /// /// Gets a value describing the type of a input device. /// This value depends on the connected device and the drivers in use. If IsConnected /// is false, then this value will be GamePadType.Unknown. /// /// The GamePadType of the connected input device. public GamePadType GamePadType { get { return (GamePadType)gamepad_type; } } /// /// Gets a value describing whether this GamePad has /// an up digital pad button. /// /// true if this instance has an up digital pad button; otherwise, false. public bool HasDPadUpButton { get { return (buttons & Buttons.DPadUp) != 0; } } /// /// Gets a value describing whether this GamePad has /// a down digital pad button. /// /// true if this instance has a down digital pad button; otherwise, false. public bool HasDPadDownButton { get { return (buttons & Buttons.DPadDown) != 0; } } /// /// Gets a value describing whether this GamePad has /// a left digital pad button. /// /// true if this instance has a left digital pad button; otherwise, false. public bool HasDPadLeftButton { get { return (buttons & Buttons.DPadLeft) != 0; } } /// /// Gets a value describing whether this GamePad has /// a right digital pad button. /// /// true if this instance has a right digital pad button; otherwise, false. public bool HasDPadRightButton { get { return (buttons & Buttons.DPadRight) != 0; } } /// /// Gets a value describing whether this GamePad has /// an A button. /// /// true if this instance has an A button; otherwise, false. public bool HasAButton { get { return (buttons & Buttons.A) != 0; } } /// /// Gets a value describing whether this GamePad has /// a B button. /// /// true if this instance has a B button; otherwise, false. public bool HasBButton { get { return (buttons & Buttons.B) != 0; } } /// /// Gets a value describing whether this GamePad has /// a X button. /// /// true if this instance has a X button; otherwise, false. public bool HasXButton { get { return (buttons & Buttons.X) != 0; } } /// /// Gets a value describing whether this GamePad has /// a Y button. /// /// true if this instance has a Y button; otherwise, false. public bool HasYButton { get { return (buttons & Buttons.Y) != 0; } } /// /// Gets a value describing whether this GamePad has /// a left stick button. /// /// true if this instance has a left stick button; otherwise, false. public bool HasLeftStickButton { get { return (buttons & Buttons.LeftStick) != 0; } } /// /// Gets a value describing whether this GamePad has /// a right stick button. /// /// true if this instance has a right stick button; otherwise, false. public bool HasRightStickButton { get { return (buttons & Buttons.RightStick) != 0; } } /// /// Gets a value describing whether this GamePad has /// a left shoulder button. /// /// true if this instance has a left shoulder button; otherwise, false. public bool HasLeftShoulderButton { get { return (buttons & Buttons.LeftShoulder) != 0; } } /// /// Gets a value describing whether this GamePad has /// a right shoulder button. /// /// true if this instance has a right shoulder button; otherwise, false. public bool HasRightShoulderButton { get { return (buttons & Buttons.RightShoulder) != 0; } } /// /// Gets a value describing whether this GamePad has /// a back button. /// /// true if this instance has a back button; otherwise, false. public bool HasBackButton { get { return (buttons & Buttons.Back) != 0; } } /// /// Gets a value describing whether this GamePad has /// a big button. (also known as "guide" or "home" button). /// /// true if this instance has a big button; otherwise, false. public bool HasBigButton { get { return (buttons & Buttons.BigButton) != 0; } } /// /// Gets a value describing whether this GamePad has /// a start button. /// /// true if this instance has a start button; otherwise, false. public bool HasStartButton { get { return (buttons & Buttons.Start) != 0; } } /// /// Gets a value describing whether this GamePad has /// a left thumbstick with a x-axis. /// /// true if this instance has a left thumbstick with a x-axis; otherwise, false. public bool HasLeftXThumbStick { get { return (axes & GamePadAxes.LeftX) != 0; } } /// /// Gets a value describing whether this GamePad has /// a left thumbstick with a y-axis. /// /// true if this instance has a left thumbstick with a y-axis; otherwise, false. public bool HasLeftYThumbStick { get { return (axes & GamePadAxes.LeftY) != 0; } } /// /// Gets a value describing whether this GamePad has /// a right thumbstick with a x-axis. /// /// true if this instance has a right thumbstick with a x-axis; otherwise, false. public bool HasRightXThumbStick { get { return (axes & GamePadAxes.RightX) != 0; } } /// /// Gets a value describing whether this GamePad has /// a right thumbstick with a y-axis. /// /// true if this instance has a right thumbstick with a y-axis; otherwise, false. public bool HasRightYThumbStick { get { return (axes & GamePadAxes.RightY) != 0; } } /// /// Gets a value describing whether this GamePad has /// a left trigger. /// /// true if this instance has a left trigger; otherwise, false. public bool HasLeftTrigger { get { return (axes & GamePadAxes.LeftTrigger) != 0; } } /// /// Gets a value describing whether this GamePad has /// a right trigger. /// /// true if this instance has a right trigger; otherwise, false. public bool HasRightTrigger { get { return (axes & GamePadAxes.RightTrigger) != 0; } } /// /// Gets a value describing whether this GamePad has /// a low-frequency vibration motor. /// /// true if this instance has a low-frequency vibration motor; otherwise, false. public bool HasLeftVibrationMotor { get { return false; } } /// /// Gets a value describing whether this GamePad has /// a high-frequency vibration motor. /// /// true if this instance has a high frequency vibration motor; otherwise, false. public bool HasRightVibrationMotor { get { return false; } } /// /// Gets a value describing whether this GamePad has /// a microphone input. /// /// true if this instance has a microphone input; otherwise, false. public bool HasVoiceSupport { get { return false; } } /// /// Gets a value describing whether this GamePad is /// currently connected. /// /// true if this instance is currently connected; otherwise, false. public bool IsConnected { get { return is_connected; } } /// A structure to test for equality. /// A structure to test for equality. public static bool operator ==(GamePadCapabilities left, GamePadCapabilities right) { return left.Equals(right); } /// A structure to test for inequality. /// A structure to test for inequality. public static bool operator !=(GamePadCapabilities left, GamePadCapabilities right) { return !left.Equals(right); } /// /// Returns a that represents the current . /// /// A that represents the current . public override string ToString() { return String.Format( "{{Type: {0}; Axes: {1}; Buttons: {2}; Connected: {3}}}", GamePadType, Convert.ToString((int)axes, 2), Convert.ToString((int)buttons, 2), IsConnected); } /// /// Serves as a hash function for a object. /// /// A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a /// hash table. public override int GetHashCode() { return buttons.GetHashCode() ^ is_connected.GetHashCode() ^ gamepad_type.GetHashCode(); } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// true if the specified is equal to the current /// ; otherwise, false. public override bool Equals(object obj) { return obj is GamePadCapabilities && Equals((GamePadCapabilities)obj); } #endregion #region IEquatable Members /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// true if the specified is equal to the current /// ; otherwise, false. public bool Equals(GamePadCapabilities other) { return buttons == other.buttons && is_connected == other.is_connected && gamepad_type == other.gamepad_type; } #endregion } }