Relaxed checks to allow input devices that do not contain any axes and/or buttons (e.g. tablets or keyboard extensions).

This commit is contained in:
the_fiddler 2009-03-08 20:03:33 +00:00
parent c9e8d2f686
commit ca1e416a53
3 changed files with 7 additions and 14 deletions

View file

@ -50,10 +50,10 @@ namespace OpenTK.Input
internal JoystickDevice(int id, int axes, int buttons) internal JoystickDevice(int id, int axes, int buttons)
{ {
if (axes <= 0) if (axes < 0)
throw new ArgumentOutOfRangeException("axes"); throw new ArgumentOutOfRangeException("axes");
if (buttons <= 0) if (buttons < 0)
throw new ArgumentOutOfRangeException("buttons"); throw new ArgumentOutOfRangeException("buttons");
Id = id; Id = id;
@ -331,7 +331,7 @@ namespace OpenTK.Input
internal JoystickButtonCollection(int numButtons) internal JoystickButtonCollection(int numButtons)
{ {
if (numButtons <= 0) if (numButtons < 0)
throw new ArgumentOutOfRangeException("numButtons"); throw new ArgumentOutOfRangeException("numButtons");
button_state = new bool[numButtons]; button_state = new bool[numButtons];
@ -424,7 +424,7 @@ namespace OpenTK.Input
internal JoystickAxisCollection(int numAxes) internal JoystickAxisCollection(int numAxes)
{ {
if (numAxes <= 0) if (numAxes < 0)
throw new ArgumentOutOfRangeException("numAxes"); throw new ArgumentOutOfRangeException("numAxes");
axis_state = new float[numAxes]; axis_state = new float[numAxes];

View file

@ -86,12 +86,6 @@ namespace OpenTK.Platform.Windows
if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0) if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0)
num_axes += 2; num_axes += 2;
if (num_axes == 0)
{
Debug.Print("WinMM device {0} has 0 axes. Device will not be used.");
return null;
}
stick = new JoystickDevice<WinMMJoyDetails>(number, num_axes, caps.NumButtons); stick = new JoystickDevice<WinMMJoyDetails>(number, num_axes, caps.NumButtons);
stick.Details = new WinMMJoyDetails(num_axes); stick.Details = new WinMMJoyDetails(num_axes);
@ -131,6 +125,8 @@ namespace OpenTK.Platform.Windows
key.Close(); key.Close();
} }
if (stick != null)
Debug.Print("Found joystick on device number {0}", number);
return stick; return stick;
} }

View file

@ -131,8 +131,6 @@ namespace OpenTK.Platform.X11
string path = base_path + number.ToString(); string path = base_path + number.ToString();
JoystickDevice<X11JoyDetails> stick = null; JoystickDevice<X11JoyDetails> stick = null;
Debug.Write(String.Format("Attempting to open joystick {0}... ", path));
int fd = -1; int fd = -1;
try try
{ {
@ -155,13 +153,12 @@ namespace OpenTK.Platform.X11
UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons); UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons);
stick = new JoystickDevice<X11JoyDetails>(fd, axes, buttons); stick = new JoystickDevice<X11JoyDetails>(fd, axes, buttons);
Debug.Print("Found joystick on path {0}", path);
} }
finally finally
{ {
if (stick == null && fd != -1) if (stick == null && fd != -1)
UnsafeNativeMethods.close(fd); UnsafeNativeMethods.close(fd);
Debug.Print(stick != null ? "success!" : "failed.");
} }
return stick; return stick;