Permalink
Browse files

Merge branch 'mac_joystick' into develop

  • Loading branch information...
2 parents 3a63496 + fda2d32 commit e984ddd783c044126e5c432cc2152b38f9fa06cd @thefiddler thefiddler committed Jan 5, 2014
@@ -236,7 +236,7 @@ int DrawGamePads(Graphics gfx, int line)
GamePadState state = GamePad.GetState(i);
if (state.IsConnected)
{
- DrawString(gfx, caps.ToString(), line++);
+ DrawString(gfx, String.Format("{0}: {1}", i, caps), line++);
DrawString(gfx, state.ToString(), line++);
}
}
@@ -248,7 +248,7 @@ int DrawGamePads(Graphics gfx, int line)
JoystickState state = Joystick.GetState(i);
if (state.IsConnected)
{
- DrawString(gfx, caps.ToString(), line++);
+ DrawString(gfx, String.Format("{0}: {1}", i, caps), line++);
DrawString(gfx, state.ToString(), line++);
}
}
@@ -5,7 +5,7 @@
// Author:
// Stefanos A. <stapostol@gmail.com>
//
-// Copyright (c) 2006-2013 Stefanos Apostolopoulos
+// Copyright (c) 2006-2014 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
@@ -58,5 +58,9 @@ public enum JoystickAxis
Axis8,
/// <summary>The tenth axis of the JoystickDevice.</summary>
Axis9,
+ /// <summary>The eleventh axis of the JoystickDevice.</summary>
+ Axis10,
+ /// <summary>The highest supported axis of the JoystickDevice.</summary>
+ Last = Axis10,
}
}
@@ -70,5 +70,7 @@ public enum JoystickButton
Button14,
/// <summary>The sixteenth button of the JoystickDevice.</summary>
Button15,
+ /// <summary>The last supported button of the JoystickDevice.</summary>
+ Last = Button15,
}
}
@@ -155,7 +155,7 @@ internal void SetButton(JoystickButton button, bool @value)
#region JoystickDevice<TDetail> : JoystickDevice
// Provides platform-specific information about the relevant JoystickDevice.
- internal sealed class JoystickDevice<TDetail> : JoystickDevice
+ internal class JoystickDevice<TDetail> : JoystickDevice
where TDetail : new()
{
internal JoystickDevice(int id, int axes, int buttons)
@@ -40,8 +40,8 @@ public struct JoystickState : IEquatable<JoystickState>
{
// If we ever add more values to JoystickAxis or JoystickButton
// then we'll need to increase these limits.
- internal const int MaxAxes = 10;
- internal const int MaxButtons = 32;
+ internal const int MaxAxes = (int)JoystickAxis.Last;
+ internal const int MaxButtons = (int)JoystickButton.Last;
const float ConversionFactor = 1.0f / (short.MaxValue + 0.5f);
@@ -32,7 +32,10 @@
namespace OpenTK.Platform.MacOS.Carbon
{
+ using CFIndex = System.IntPtr;
using CFRunLoop = System.IntPtr;
+ using CFStringRef = System.IntPtr;
+ using CFTypeRef = System.IntPtr;
struct CFArray
{
@@ -59,6 +62,7 @@ public int Count
}
}
}
+
struct CFDictionary
{
public CFDictionary(IntPtr reference)
@@ -76,18 +80,16 @@ public int Count
return CF.CFDictionaryGetCount(dictionaryRef);
}
}
+
public double GetNumberValue(string key)
{
- unsafe
- {
- double retval;
- IntPtr cfnum = CF.CFDictionaryGetValue(dictionaryRef,
- CF.CFSTR(key));
+ double retval;
+ IntPtr cfnum = CF.CFDictionaryGetValue(dictionaryRef,
+ CF.CFSTR(key));
- CF.CFNumberGetValue(cfnum, CF.CFNumberType.kCFNumberDoubleType, &retval);
+ CF.CFNumberGetValue(cfnum, CF.CFNumberType.kCFNumberDoubleType, out retval);
- return retval;
- }
+ return retval;
}
}
class CF
@@ -106,6 +108,9 @@ class CF
[DllImport(appServices)]
internal static extern IntPtr CFDictionaryGetValue(IntPtr theDictionary, IntPtr theKey);
+ [DllImport(appServices)]
+ internal static extern void CFRelease(CFTypeRef cf);
+
// this mirrors the definition in CFString.h.
// I don't know why, but __CFStringMakeConstantString is marked as "private and should not be used directly"
// even though the CFSTR macro just calls it.
@@ -117,9 +122,38 @@ internal static IntPtr CFSTR(string cStr)
}
[DllImport(appServices)]
- internal unsafe static extern bool CFNumberGetValue (IntPtr number, CFNumberType theType, int* valuePtr);
+ internal static extern Boolean CFStringGetCString(
+ CFStringRef theString,
+ byte[] buffer,
+ CFIndex bufferSize,
+ CFStringEncoding encoding
+ );
+
+ internal static string CFStringGetCString(IntPtr cfstr)
+ {
+ CFIndex length = CFStringGetLength(cfstr);
+ if (length != IntPtr.Zero)
+ {
+ byte[] utf8_chars = new byte[length.ToInt32() + 1];
+ if (CFStringGetCString(cfstr, utf8_chars, new IntPtr(utf8_chars.Length), CFStringEncoding.UTF8))
+ {
+ return Encoding.UTF8.GetString(utf8_chars);
+ }
+ }
+ return String.Empty;
+ }
+
+ [DllImport(appServices)]
+ internal static extern CFIndex CFStringGetLength(
+ CFStringRef theString
+ );
+
+ [DllImport(appServices)]
+ internal static extern bool CFNumberGetValue (IntPtr number, CFNumberType theType, out int valuePtr);
[DllImport(appServices)]
- internal unsafe static extern bool CFNumberGetValue(IntPtr number, CFNumberType theType, double* valuePtr);
+ internal static extern bool CFNumberGetValue (IntPtr number, CFNumberType theType, out long valuePtr);
+ [DllImport(appServices)]
+ internal static extern bool CFNumberGetValue(IntPtr number, CFNumberType theType, out double valuePtr);
internal enum CFNumberType
{
@@ -150,6 +184,25 @@ public enum CFRunLoopExitReason
HandledSource = 4
}
+ public enum CFStringEncoding
+ {
+ MacRoman = 0,
+ WindowsLatin1 = 0x0500,
+ ISOLatin1 = 0x0201,
+ NextStepLatin = 0x0B01,
+ ASCII = 0x0600,
+ Unicode = 0x0100,
+ UTF8 = 0x08000100,
+ NonLossyASCII = 0x0BFF,
+
+ UTF16 = 0x0100,
+ UTF16BE = 0x10000100,
+ UTF16LE = 0x14000100,
+ UTF32 = 0x0c000100,
+ UTF32BE = 0x18000100,
+ UTF32LE = 0x1c000100
+ }
+
public static readonly IntPtr RunLoopModeDefault = CF.CFSTR("kCFRunLoopDefaultMode");
[DllImport(appServices)]
Oops, something went wrong.

0 comments on commit e984ddd

Please sign in to comment.