[SDL2] Added JoystickGetGUID method
authorthefiddler <stapostol@gmail.com>
Tue, 31 Dec 2013 13:08:28 +0000 (14:08 +0100)
committerthefiddler <stapostol@gmail.com>
Tue, 31 Dec 2013 13:08:28 +0000 (14:08 +0100)
Source/OpenTK/Platform/SDL2/Sdl2.cs

index 5d0cde5..8ad2548 100644 (file)
@@ -301,6 +301,10 @@ namespace OpenTK.Platform.SDL2
         public static extern byte JoystickGetButton(IntPtr joystick, int button);
 
         [SuppressUnmanagedCodeSecurity]
+        [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetGuid", ExactSpelling = true)]
+        public static extern JoystickGuid JoystickGetGUID(IntPtr joystick);
+
+        [SuppressUnmanagedCodeSecurity]
         [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickName", ExactSpelling = true)]
         static extern IntPtr JoystickNameInternal(IntPtr joystick);
         public static string JoystickName(IntPtr joystick)
@@ -1404,6 +1408,26 @@ namespace OpenTK.Platform.SDL2
         byte padding2;
     }
 
+    struct JoystickGuid
+    {
+        unsafe fixed byte data[16];
+
+        public Guid ToGuid()
+        {
+            byte[] bytes = new byte[16];
+
+            unsafe
+            {
+                fixed (byte* pdata = data)
+                {
+                    Marshal.Copy(new IntPtr(pdata), bytes, 0, bytes.Length); 
+                }
+            }
+
+            return new Guid(bytes);
+        }
+    }
+
     struct KeyboardEvent
     {
         public EventType Type;