[Input] Add GamePadCapabilities.IsMapped
authorthefiddler <stapostol@gmail.com>
Fri, 12 Sep 2014 06:36:52 +0000 (08:36 +0200)
committerthefiddler <stapostol@gmail.com>
Fri, 12 Sep 2014 06:42:26 +0000 (08:42 +0200)
Source/OpenTK/Input/GamePadCapabilities.cs
Source/OpenTK/Input/GamePadConfigurationDatabase.cs
Source/OpenTK/Platform/MappedGamePadDriver.cs

index 269081e..9947d83 100644 (file)
@@ -40,16 +40,18 @@ namespace OpenTK.Input
         GamePadAxes axes;
         byte gamepad_type;
         bool is_connected;
+        bool is_mapped;
 
         #region Constructors
 
-        internal GamePadCapabilities(GamePadType type, GamePadAxes axes, Buttons buttons, bool is_connected)
+        internal GamePadCapabilities(GamePadType type, GamePadAxes axes, Buttons buttons, bool is_connected, bool is_mapped)
             : this()
         {
             gamepad_type = (byte)type;
             this.axes = axes;
             this.buttons = buttons;
             this.is_connected = is_connected;
+            this.is_mapped = is_mapped;
         }
 
         #endregion
@@ -317,6 +319,15 @@ namespace OpenTK.Input
             get { return is_connected; }
         }
 
+        /// <summary>
+        /// Gets a <see cref="System.Boolean"/> value describing whether a valid button configuration
+        /// exists for this <c>GamePad</c> in the GamePad configuration database.
+        /// </summary>
+        public bool IsMapped
+        {
+            get { return is_mapped; }
+        }
+
         /// <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>
         public static bool operator ==(GamePadCapabilities left, GamePadCapabilities right)
@@ -338,11 +349,12 @@ namespace OpenTK.Input
         public override string ToString()
         {
             return String.Format(
-                "{{Type: {0}; Axes: {1}; Buttons: {2}; Connected: {3}}}",
+                "{{Type: {0}; Axes: {1}; Buttons: {2}; {3}; {4}}}",
                 GamePadType,
                 Convert.ToString((int)axes, 2),
                 Convert.ToString((int)buttons, 2),
-                IsConnected);
+                IsMapped ? "Mapped" : "Unmapped",
+                IsConnected ? "Connected" : "Disconnected");
         }
 
         /// <summary>
@@ -355,6 +367,7 @@ namespace OpenTK.Input
             return
                 buttons.GetHashCode() ^
                 is_connected.GetHashCode() ^
+                is_mapped.GetHashCode() ^
                 gamepad_type.GetHashCode();
         }
 
@@ -386,6 +399,7 @@ namespace OpenTK.Input
             return
                 buttons == other.buttons &&
                 is_connected == other.is_connected &&
+                is_mapped == other.is_mapped &&
                 gamepad_type == other.gamepad_type;
         }
 
index 2255fb8..e343f97 100644 (file)
@@ -34,6 +34,8 @@ namespace OpenTK.Input
 {
     class GamePadConfigurationDatabase
     {
+        internal const string UnmappedName = "Unmapped Controller";
+
         readonly Dictionary<Guid, string> Configurations = new Dictionary<Guid, string>();
 
         internal GamePadConfigurationDatabase()
index 7c94d69..99a0ce2 100644 (file)
@@ -204,7 +204,8 @@ namespace OpenTK.Platform
                     GamePadType.GamePad, // Todo: detect different types
                     mapped_axes,
                     mapped_buttons,
-                    true);
+                    joy.IsConnected,
+                    configuration.Name != GamePadConfigurationDatabase.UnmappedName);
             }
             else
             {