diff --git a/OpenTK/GameWindow.cs b/OpenTK/GameWindow.cs index f0ce00fb3..a8b67872a 100644 --- a/OpenTK/GameWindow.cs +++ b/OpenTK/GameWindow.cs @@ -455,18 +455,6 @@ namespace OpenTK #endregion - #region Joysticks - - /// - /// Gets a readonly IList containing all available OpenTK.Input.JoystickDevices. - /// - public IList Joysticks - { - get { return InputDriver.Joysticks; } - } - - #endregion - #region Keyboard /// diff --git a/OpenTK/Input/Interfaces.cs b/OpenTK/Input/Interfaces.cs index 8729d3fcf..6b2945d65 100644 --- a/OpenTK/Input/Interfaces.cs +++ b/OpenTK/Input/Interfaces.cs @@ -5,7 +5,6 @@ #endregion using System; -using System.Collections.Generic; using System.Drawing; namespace OpenTK.Input { @@ -23,30 +22,17 @@ namespace OpenTK.Input { Keyboard, /// Device is a mouse. Mouse, - /// Device is a Human Interface Device. Joysticks, joypads, pens - /// and some specific usb keyboards/mice fall into this category. - Hid } /// Defines the interface for an input driver. - public interface IInputDriver : IJoystickDriver, IDisposable { + public interface IInputDriver : IDisposable { - /// Gets the list of available KeyboardDevices. + /// Gets the available KeyboardDevice. KeyboardDevice Keyboard { get; } - /// Gets the list of available MouseDevices. + /// Gets the available MouseDevice. MouseDevice Mouse { get; } - /// Updates the state of the driver. - void Poll(); - Point DesktopCursorPos { get; set; } } - - /// Defines the interface for JoystickDevice drivers. - public interface IJoystickDriver { - - /// Gets the list of available JoystickDevices. - IList Joysticks { get; } - } } diff --git a/OpenTK/Input/JoystickDevice.cs b/OpenTK/Input/JoystickDevice.cs deleted file mode 100644 index 1c7c7b9bc..000000000 --- a/OpenTK/Input/JoystickDevice.cs +++ /dev/null @@ -1,471 +0,0 @@ -#region License -// -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. -// -// 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; -using System.Collections.Generic; - -namespace OpenTK.Input -{ - /// - /// Represents a joystick device and provides methods to query its status. - /// - public abstract class JoystickDevice : IInputDevice - { - #region Fields - - int id; - string description; - JoystickAxisCollection axis_collection; - JoystickButtonCollection button_collection; - JoystickMoveEventArgs move_args = new JoystickMoveEventArgs(0, 0, 0); - JoystickButtonEventArgs button_args = new JoystickButtonEventArgs(0, false); - - #endregion - - #region Constructors - - internal JoystickDevice(int id, int axes, int buttons) - { - if (axes < 0) - throw new ArgumentOutOfRangeException("axes"); - - if (buttons < 0) - throw new ArgumentOutOfRangeException("buttons"); - - Id = id; - axis_collection = new JoystickAxisCollection(axes); - button_collection = new JoystickButtonCollection(buttons); - } - - #endregion - - #region Public Members - - /// - /// Gets a JoystickAxisCollection containing the state of each axis on this instance. Values are normalized in the [-1, 1] range. - /// - public JoystickAxisCollection Axis { get { return axis_collection; } } - - /// - /// Gets JoystickButtonCollection containing the state of each button on this instance. True indicates that the button is pressed. - /// - public JoystickButtonCollection Button { get { return button_collection; } } - - #endregion - - #region IInputDevice Members - - /// - /// Gets a System.String containing a unique description for this instance. - /// - public string Description - { - get { return description; } - internal set { description = value; } - } - - /// - /// Gets a value indicating the InputDeviceType of this InputDevice. - /// - public InputDeviceType DeviceType - { - get { return InputDeviceType.Hid; } - } - - #endregion - - #region Events - - /// - /// Occurs when an axis of this JoystickDevice instance is moved. - /// - public EventHandler Move = - delegate(object sender, JoystickMoveEventArgs e) { }; - - /// - /// Occurs when a button of this JoystickDevice instance is pressed. - /// - public EventHandler ButtonDown = - delegate(object sender, JoystickButtonEventArgs e) { }; - - /// - /// Occurs when a button of this JoystickDevice is released. - /// - public EventHandler ButtonUp = - delegate(object sender, JoystickButtonEventArgs e) { }; - - #endregion - - #region Internal Members - - internal int Id - { - get { return id; } - set { id = value; } - } - - internal void SetAxis(JoystickAxis axis, float @value) - { - move_args.Axis = axis; - move_args.Delta = move_args.Value - @value; - axis_collection[axis] = move_args.Value = @value; - Move(this, move_args); - } - - internal void SetButton(JoystickButton button, bool @value) - { - if (button_collection[button] != @value) - { - button_args.Button = button; - button_collection[button] = button_args.Pressed = @value; - if (@value) - ButtonDown(this, button_args); - else - ButtonUp(this, button_args); - } - } - - #endregion - } - - #region JoystickDevice : JoystickDevice - - // Provides platform-specific information about the relevant JoystickDevice. - internal sealed class JoystickDevice : JoystickDevice - { - internal JoystickDevice(int id, int axes, int buttons) - : base(id, axes, buttons) - { } - - internal TDetail Details; - } - - #endregion - - #region Event Arguments - - /// - /// The base class for JoystickDevice event arguments. - /// - public class JoystickEventArgs : EventArgs - { - } - - /// - /// Provides data for the and events. - /// This class is cached for performance reasons - avoid storing references outside the scope of the event. - /// - public class JoystickButtonEventArgs : EventArgs - { - #region Fields - - JoystickButton button; - bool pressed; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The index of the joystick button for the event. - /// The current state of the button. - internal JoystickButtonEventArgs(JoystickButton button, bool pressed) - { - this.button = button; - this.pressed = pressed; - } - - #endregion - - #region Public Members - - /// - /// The index of the joystick button for the event. - /// - public JoystickButton Button { get { return this.button; } internal set { this.button = value; } } - - /// - /// Gets a System.Boolean representing the state of the button for the event. - /// - public bool Pressed { get { return pressed; } internal set { this.pressed = value; } } - - #endregion - } - - /// - /// Provides data for the event. - /// This class is cached for performance reasons - avoid storing references outside the scope of the event. - /// - public class JoystickMoveEventArgs : JoystickEventArgs - { - #region Fields - - JoystickAxis axis; - float value; - float delta; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The index of the joystick axis that was moved. - /// The absolute value of the joystick axis. - /// The relative change in value of the joystick axis. - public JoystickMoveEventArgs(JoystickAxis axis, float value, float delta) - { - this.axis = axis; - this.value = value; - this.delta = delta; - } - - #endregion - - #region Public Members - - /// - /// Gets a System.Int32 representing the index of the axis that was moved. - /// - public JoystickAxis Axis { get { return axis; } internal set { this.axis = value; } } - - /// - /// Gets a System.Single representing the absolute position of the axis. - /// - public float Value { get { return value; } internal set { this.value = value; } } - - /// - /// Gets a System.Single representing the relative change in the position of the axis. - /// - public float Delta { get { return delta; } internal set { this.delta = value; } } - - #endregion - } - - #endregion - - #region JoystickButton - - /// - /// Defines available JoystickDevice buttons. - /// - public enum JoystickButton - { - /// The first button of the JoystickDevice. - Button0 = 0, - /// The second button of the JoystickDevice. - Button1, - /// The third button of the JoystickDevice. - Button2, - /// The fourth button of the JoystickDevice. - Button3, - /// The fifth button of the JoystickDevice. - Button4, - /// The sixth button of the JoystickDevice. - Button5, - /// The seventh button of the JoystickDevice. - Button6, - /// The eighth button of the JoystickDevice. - Button7, - /// The ninth button of the JoystickDevice. - Button8, - /// The tenth button of the JoystickDevice. - Button9, - /// The eleventh button of the JoystickDevice. - Button10, - /// The twelfth button of the JoystickDevice. - Button11, - /// The thirteenth button of the JoystickDevice. - Button12, - /// The fourteenth button of the JoystickDevice. - Button13, - /// The fifteenth button of the JoystickDevice. - Button14, - /// The sixteenth button of the JoystickDevice. - Button15, - } - - #endregion - - #region JoystickButtonCollection - - /// - /// Defines a collection of JoystickButtons. - /// - public sealed class JoystickButtonCollection - { - #region Fields - - bool[] button_state; - - #endregion - - #region Constructors - - internal JoystickButtonCollection(int numButtons) - { - if (numButtons < 0) - throw new ArgumentOutOfRangeException("numButtons"); - - button_state = new bool[numButtons]; - } - - #endregion - - #region Public Members - - /// - /// Gets a System.Boolean indicating whether the JoystickButton with the specified index is pressed. - /// - /// The index of the JoystickButton to check. - /// True if the JoystickButton is pressed; false otherwise. - public bool this[int index] - { - get { return button_state[index]; } - internal set { button_state[index] = value; } - } - - /// - /// Gets a System.Boolean indicating whether the specified JoystickButton is pressed. - /// - /// The JoystickButton to check. - /// True if the JoystickButton is pressed; false otherwise. - public bool this[JoystickButton button] - { - get { return button_state[(int)button]; } - internal set { button_state[(int)button] = value; } - } - - /// - /// Gets a System.Int32 indicating the available amount of JoystickButtons. - /// - public int Count - { - get { return button_state.Length; } - } - - #endregion - } - - #endregion - - #region JoystickAxis - - /// - /// Defines available JoystickDevice axes. - /// - public enum JoystickAxis - { - /// The first axis of the JoystickDevice. - Axis0 = 0, - /// The second axis of the JoystickDevice. - Axis1, - /// The third axis of the JoystickDevice. - Axis2, - /// The fourth axis of the JoystickDevice. - Axis3, - /// The fifth axis of the JoystickDevice. - Axis4, - /// The sixth axis of the JoystickDevice. - Axis5, - /// The seventh axis of the JoystickDevice. - Axis6, - /// The eighth axis of the JoystickDevice. - Axis7, - /// The ninth axis of the JoystickDevice. - Axis8, - /// The tenth axis of the JoystickDevice. - Axis9, - } - - #endregion - - #region JoystickAxisCollection - - /// - /// Defines a collection of JoystickAxes. - /// - public sealed class JoystickAxisCollection - { - #region Fields - - float[] axis_state; - - #endregion - - #region Constructors - - internal JoystickAxisCollection(int numAxes) - { - if (numAxes < 0) - throw new ArgumentOutOfRangeException("numAxes"); - - axis_state = new float[numAxes]; - } - - #endregion - - #region Public Members - - /// - /// Gets a System.Single indicating the absolute position of the JoystickAxis with the specified index. - /// - /// The index of the JoystickAxis to check. - /// A System.Single in the range [-1, 1]. - public float this[int index] - { - get { return axis_state[index]; } - internal set { axis_state[index] = value; } - } - - /// - /// Gets a System.Single indicating the absolute position of the JoystickAxis. - /// - /// The JoystickAxis to check. - /// A System.Single in the range [-1, 1]. - public float this[JoystickAxis axis] - { - get { return axis_state[(int)axis]; } - internal set { axis_state[(int)axis] = value; } - } - - /// - /// Gets a System.Int32 indicating the available amount of JoystickAxes. - /// - public int Count - { - get { return axis_state.Length; } - } - - #endregion - } - - #endregion -} diff --git a/OpenTK/OpenTK.csproj b/OpenTK/OpenTK.csproj index f918e9d85..cac240524 100644 --- a/OpenTK/OpenTK.csproj +++ b/OpenTK/OpenTK.csproj @@ -73,7 +73,6 @@ - @@ -105,7 +104,6 @@ - @@ -116,7 +114,6 @@ - diff --git a/OpenTK/Platform/MacOS/CarbonGLNative.cs b/OpenTK/Platform/MacOS/CarbonGLNative.cs index 296f1d281..7a590c122 100644 --- a/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -106,7 +106,6 @@ namespace OpenTK.Platform.MacOS new Rect((short)x, (short)y, (short)width, (short)height)); mDisplayDevice = device; - dummy_joystick_list.Add(new JoystickDevice(0, 0, 0)); } #endregion @@ -1066,10 +1065,6 @@ namespace OpenTK.Platform.MacOS KeyboardDevice keyboard = new KeyboardDevice(); MouseDevice mouse = new MouseDevice(); - List dummy_joystick_list = new List(1); - - public void Poll() { - } public KeyboardDevice Keyboard { get { return keyboard; } @@ -1090,10 +1085,6 @@ namespace OpenTK.Platform.MacOS get { return System.Windows.Forms.Cursor.Position; } set { System.Windows.Forms.Cursor.Position = value; } } - - public IList Joysticks { - get { return dummy_joystick_list; } - } #endregion } diff --git a/OpenTK/Platform/Windows/WinGLNative.cs b/OpenTK/Platform/Windows/WinGLNative.cs index 3e19a5eca..4952676e8 100644 --- a/OpenTK/Platform/Windows/WinGLNative.cs +++ b/OpenTK/Platform/Windows/WinGLNative.cs @@ -75,7 +75,6 @@ namespace OpenTK.Platform.Windows Icon icon; // Used for IInputDriver implementation - WinMMJoystick joystick_driver = new WinMMJoystick(); KeyboardDevice keyboard = new KeyboardDevice(); MouseDevice mouse = new MouseDevice(); static readonly WinKeyMap KeyMap = new WinKeyMap(); @@ -1110,10 +1109,6 @@ namespace OpenTK.Platform.Windows #endregion #region IInputDriver Members - - public void Poll() { - joystick_driver.Poll(); - } public KeyboardDevice Keyboard { get { return keyboard; } @@ -1136,15 +1131,6 @@ namespace OpenTK.Platform.Windows #endregion - #region IJoystickDriver Members - - public IList Joysticks - { - get { return joystick_driver.Joysticks; } - } - - #endregion - #region IDisposable Members public void Dispose() diff --git a/OpenTK/Platform/Windows/WinMMJoystick.cs b/OpenTK/Platform/Windows/WinMMJoystick.cs deleted file mode 100644 index 6ff1a14ac..000000000 --- a/OpenTK/Platform/Windows/WinMMJoystick.cs +++ /dev/null @@ -1,431 +0,0 @@ -#region License -// -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. -// -// 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; -using System.Collections.Generic; -using System.Text; -using System.Runtime.InteropServices; -using OpenTK.Input; -using System.Security; -using Microsoft.Win32; -using System.Diagnostics; - -namespace OpenTK.Platform.Windows -{ - sealed class WinMMJoystick : IJoystickDriver - { - #region Fields - - List sticks = new List(); - IList sticks_readonly; - - // Todo: Read the joystick name from the registry. - //static readonly string RegistryJoyConfig = @"Joystick%dConfiguration"; - //static readonly string RegistryJoyName = @"Joystick%dOEMName"; - //static readonly string RegstryJoyCurrent = @"CurrentJoystickSettings"; - - bool disposed; - - #endregion - - #region Constructors - - public WinMMJoystick() - { - sticks_readonly = sticks.AsReadOnly(); - - // WinMM supports up to 16 joysticks. - int number = 0; - while (number < UnsafeNativeMethods.joyGetNumDevs()) - { - JoystickDevice stick = OpenJoystick(number++); - if (stick != null) - { - sticks.Add(stick); - } - } - } - - #endregion - - #region Private Members - - JoystickDevice OpenJoystick(int number) - { - JoystickDevice stick = null; - - JoyCaps caps; - JoystickError result = UnsafeNativeMethods.joyGetDevCaps(number, out caps, JoyCaps.SizeInBytes); - if (result != JoystickError.NoError) - return null; - - int num_axes = caps.NumAxes; - if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0) - num_axes += 2; - - stick = new JoystickDevice(number, num_axes, caps.NumButtons); - stick.Details = new WinMMJoyDetails(num_axes); - - // Make sure to reverse the vertical axes, so that +1 points up and -1 points down. - int axis = 0; - if (axis < caps.NumAxes) - { stick.Details.Min[axis] = caps.XMin; stick.Details.Max[axis] = caps.XMax; axis++; } - if (axis < caps.NumAxes) - { stick.Details.Min[axis] = caps.YMax; stick.Details.Max[axis] = caps.YMin; axis++; } - if (axis < caps.NumAxes) - { stick.Details.Min[axis] = caps.ZMax; stick.Details.Max[axis] = caps.ZMin; axis++; } - if (axis < caps.NumAxes) - { stick.Details.Min[axis] = caps.RMin; stick.Details.Max[axis] = caps.RMax; axis++; } - if (axis < caps.NumAxes) - { stick.Details.Min[axis] = caps.UMin; stick.Details.Max[axis] = caps.UMax; axis++; } - if (axis < caps.NumAxes) - { stick.Details.Min[axis] = caps.VMax; stick.Details.Max[axis] = caps.VMin; axis++; } - - if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0) - { - stick.Details.PovType = PovType.Exists; - if ((caps.Capabilities & JoystCapsFlags.HasPov4Dir) != 0) - stick.Details.PovType |= PovType.Discrete; - if ((caps.Capabilities & JoystCapsFlags.HasPovContinuous) != 0) - stick.Details.PovType |= PovType.Continuous; - } - -#warning "Implement joystick name detection for WinMM." - stick.Description = String.Format("Joystick/Joystick #{0} ({1} axes, {2} buttons)", number, stick.Axis.Count, stick.Button.Count); - // Todo: Try to get the device name from the registry. Oh joy! - //string key_path = String.Format("{0}\\{1}\\{2}", RegistryJoyConfig, caps.RegKey, RegstryJoyCurrent); - //RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path, false); - //if (key == null) - // key = Registry.CurrentUser.OpenSubKey(key_path, false); - //if (key == null) - // stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons)", number, stick.Axis.Count, stick.Button.Count); - //else - //{ - // key.Close(); - //} - - if (stick != null) - Debug.Print("Found joystick on device number {0}", number); - return stick; - } - - #endregion - - #region IJoystickDriver - - public int DeviceCount - { - get { return sticks.Count; } - } - - public IList Joysticks - { - get { return sticks_readonly; } - } - - public void Poll() - { - foreach (JoystickDevice js in sticks) - { - JoyInfoEx info = new JoyInfoEx(); - info.Size = JoyInfoEx.SizeInBytes; - info.Flags = JoystickFlags.All; - UnsafeNativeMethods.joyGetPosEx(js.Id, ref info); - - int num_axes = js.Axis.Count; - if ((js.Details.PovType & PovType.Exists) != 0) - num_axes -= 2; // Because the last two axis are used for POV input. - - int axis = 0; - if (axis < num_axes) - { js.SetAxis((JoystickAxis)axis, js.Details.CalculateOffset((float)info.XPos, axis)); axis++; } - if (axis < num_axes) - { js.SetAxis((JoystickAxis)axis, js.Details.CalculateOffset((float)info.YPos, axis)); axis++; } - if (axis < num_axes) - { js.SetAxis((JoystickAxis)axis, js.Details.CalculateOffset((float)info.ZPos, axis)); axis++; } - if (axis < num_axes) - { js.SetAxis((JoystickAxis)axis, js.Details.CalculateOffset((float)info.RPos, axis)); axis++; } - if (axis < num_axes) - { js.SetAxis((JoystickAxis)axis, js.Details.CalculateOffset((float)info.UPos, axis)); axis++; } - if (axis < num_axes) - { js.SetAxis((JoystickAxis)axis, js.Details.CalculateOffset((float)info.VPos, axis)); axis++; } - - if ((js.Details.PovType & PovType.Exists) != 0) - { - float x = 0, y = 0; - - // A discrete POV returns specific values for left, right, etc. - // A continuous POV returns an integer indicating an angle in degrees * 100, e.g. 18000 == 180.00 degrees. - // The vast majority of joysticks have discrete POVs, so we'll treat all of them as discrete for simplicity. - if ((JoystickPovPosition)info.Pov != JoystickPovPosition.Centered) - { - if (info.Pov > (int)JoystickPovPosition.Left || info.Pov < (int)JoystickPovPosition.Right) - { y = 1; } - if ((info.Pov > (int)JoystickPovPosition.Forward) && (info.Pov < (int)JoystickPovPosition.Backward)) - { x = 1; } - if ((info.Pov > (int)JoystickPovPosition.Right) && (info.Pov < (int)JoystickPovPosition.Left)) - { y = -1; } - if (info.Pov > (int)JoystickPovPosition.Backward) - { x = -1; } - } - //if ((js.Details.PovType & PovType.Discrete) != 0) - //{ - // if ((JoystickPovPosition)info.Pov == JoystickPovPosition.Centered) - // { x = 0; y = 0; } - // else if ((JoystickPovPosition)info.Pov == JoystickPovPosition.Forward) - // { x = 0; y = -1; } - // else if ((JoystickPovPosition)info.Pov == JoystickPovPosition.Left) - // { x = -1; y = 0; } - // else if ((JoystickPovPosition)info.Pov == JoystickPovPosition.Backward) - // { x = 0; y = 1; } - // else if ((JoystickPovPosition)info.Pov == JoystickPovPosition.Right) - // { x = 1; y = 0; } - //} - //else if ((js.Details.PovType & PovType.Continuous) != 0) - //{ - // if ((JoystickPovPosition)info.Pov == JoystickPovPosition.Centered) - // { - // // This approach moves the hat on a circle, not a square as it should. - // float angle = (float)(System.Math.PI * info.Pov / 18000.0 + System.Math.PI / 2); - // x = (float)System.Math.Cos(angle); - // y = (float)System.Math.Sin(angle); - // if (x < 0.001) - // x = 0; - // if (y < 0.001) - // y = 0; - // } - //} - //else - // throw new NotImplementedException("Please post an issue report at http://www.opentk.com/issues"); - - js.SetAxis((JoystickAxis)axis++, x); - js.SetAxis((JoystickAxis)axis++, y); - } - - int button = 0; - while (button < js.Button.Count) - { - js.SetButton((JoystickButton)button, (info.Buttons & (1 << button)) != 0); - button++; - } - } - } - - #endregion - - #region IDisposable - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - void Dispose(bool manual) - { - if (!disposed) - { - if (manual) - { - } - - disposed = true; - } - } - - ~WinMMJoystick() - { - Dispose(false); - } - - #endregion - - #region UnsafeNativeMethods - - [Flags] - enum JoystickFlags - { - X = 0x1, - Y = 0x2, - Z = 0x4, - R = 0x8, - U = 0x10, - V = 0x20, - Pov = 0x40, - Buttons = 0x80, - All = X | Y | Z | R | U | V | Pov | Buttons - } - - enum JoystickError : uint - { - NoError = 0, - InvalidParameters = 165, - NoCanDo = 166, - Unplugged = 167 - //MM_NoDriver = 6, - //MM_InvalidParameter = 11 - } - - [Flags] - enum JoystCapsFlags - { - HasZ = 0x1, - HasR = 0x2, - HasU = 0x4, - HasV = 0x8, - HasPov = 0x16, - HasPov4Dir = 0x32, - HasPovContinuous = 0x64 - } - - enum JoystickPovPosition : ushort - { - Centered = 0xFFFF, - Forward = 0, - Right = 9000, - Backward = 18000, - Left = 27000 - } - struct JoyCaps - { - public ushort Mid; - public ushort ProductId; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] - public string ProductName; - public int XMin; - public int XMax; - public int YMin; - public int YMax; - public int ZMin; - public int ZMax; - public int NumButtons; - public int PeriodMin; - public int PeriodMax; - public int RMin; - public int RMax; - public int UMin; - public int UMax; - public int VMin; - public int VMax; - public JoystCapsFlags Capabilities; - public int MaxAxes; - public int NumAxes; - public int MaxButtons; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] - public string RegKey; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] - public string OemVxD; - - public static readonly int SizeInBytes; - - static JoyCaps() - { - SizeInBytes = Marshal.SizeOf(default(JoyCaps)); - } - } - - struct JoyInfoEx - { - public int Size; - [MarshalAs(UnmanagedType.I4)] - public JoystickFlags Flags; - public int XPos; - public int YPos; - public int ZPos; - public int RPos; - public int UPos; - public int VPos; - public uint Buttons; - public uint ButtonNumber; - public int Pov; - uint Reserved1; - uint Reserved2; - - public static readonly int SizeInBytes; - - static JoyInfoEx() - { - SizeInBytes = Marshal.SizeOf(default(JoyInfoEx)); - } - } - - static class UnsafeNativeMethods - { - [DllImport("Winmm.dll"), SuppressUnmanagedCodeSecurity] - public static extern JoystickError joyGetDevCaps(int uJoyID, out JoyCaps pjc, int cbjc); - [DllImport("Winmm.dll"), SuppressUnmanagedCodeSecurity] - public static extern uint joyGetPosEx(int uJoyID, ref JoyInfoEx pji); - [DllImport("Winmm.dll"), SuppressUnmanagedCodeSecurity] - public static extern int joyGetNumDevs(); - } - - #endregion - - #region enum PovType - - [Flags] - enum PovType - { - None = 0x0, - Exists = 0x1, - Discrete = 0x2, - Continuous = 0x4 - } - - #endregion - - #region struct WinMMJoyDetails - - struct WinMMJoyDetails - { - public readonly float[] Min, Max; // Minimum and maximum offset of each axis. - public PovType PovType; - - public WinMMJoyDetails(int num_axes) - { - Min = new float[num_axes]; - Max = new float[num_axes]; - PovType = PovType.None; - } - - public float CalculateOffset(float pos, int axis) - { - float offset = (2 * (pos - Min[axis])) / (Max[axis] - Min[axis]) - 1; - if (offset > 1) - return 1; - else if (offset < -1) - return -1; - else if (offset < 0.001f && offset > -0.001f) - return 0; - else - return offset; - } - } - - #endregion - } -} diff --git a/OpenTK/Platform/X11/X11Input.cs b/OpenTK/Platform/X11/X11Input.cs index 80f112a88..1b89b5dde 100644 --- a/OpenTK/Platform/X11/X11Input.cs +++ b/OpenTK/Platform/X11/X11Input.cs @@ -20,7 +20,6 @@ namespace OpenTK.Platform.X11 /// internal sealed class X11Input : IInputDriver { - X11Joystick joystick_driver = new X11Joystick(); KeyboardDevice keyboard = new KeyboardDevice(); MouseDevice mouse = new MouseDevice(); @@ -151,15 +150,6 @@ namespace OpenTK.Platform.X11 set { System.Windows.Forms.Cursor.Position = value; } } - public IList Joysticks { - get { return joystick_driver.Joysticks; } - } - - /// Polls and updates state of all keyboard, mouse and joystick devices. - public void Poll() { - joystick_driver.Poll(); - } - #endregion public void Dispose() { diff --git a/OpenTK/Platform/X11/X11Joystick.cs b/OpenTK/Platform/X11/X11Joystick.cs deleted file mode 100644 index c073ef19e..000000000 --- a/OpenTK/Platform/X11/X11Joystick.cs +++ /dev/null @@ -1,252 +0,0 @@ -#region License -// -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. -// -// 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; -using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.InteropServices; -using OpenTK.Input; - -namespace OpenTK.Platform.X11 -{ - struct X11JoyDetails { } - - sealed class X11Joystick : IJoystickDriver - { - #region Fields - - List sticks = new List(); - IList sticks_readonly; - - bool disposed; - - #endregion - - #region Constructors - - public X11Joystick() - { - sticks_readonly = sticks.AsReadOnly(); - - int number = 0, max_sticks = 25; - while (number < max_sticks) - { - JoystickDevice stick = OpenJoystick(JoystickPath, number++); - if (stick != null) - { - stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})", - number, stick.Axis.Count, stick.Button.Count, JoystickPath); - sticks.Add(stick); - } - } - - number = 0; - while (number < max_sticks) - { - JoystickDevice stick = OpenJoystick(JoystickPathLegacy, number++); - if (stick != null) - { - stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})", - number, stick.Axis.Count, stick.Button.Count, JoystickPathLegacy); - sticks.Add(stick); - } - } - } - - #endregion - - #region IJoystickDriver - - public int DeviceCount - { - get { return sticks.Count; } - } - - public IList Joysticks - { - get { return sticks_readonly; } - } - - public void Poll() - { - JoystickEvent e; - - foreach (JoystickDevice js in sticks) - { - unsafe - { - while ((long)UnsafeNativeMethods.read(js.Id, (void*)&e, (UIntPtr)sizeof(JoystickEvent)) > 0) - { - e.Type &= ~JoystickEventType.Init; - - switch (e.Type) - { - case JoystickEventType.Axis: - // Flip vertical axes so that +1 point up. - if (e.Number % 2 == 0) - js.SetAxis((JoystickAxis)e.Number, e.Value / 32767.0f); - else - js.SetAxis((JoystickAxis)e.Number, -e.Value / 32767.0f); - break; - - case JoystickEventType.Button: - js.SetButton((JoystickButton)e.Number, e.Value != 0); - break; - } - } - } - } - } - - #endregion - - #region Private Members - - JoystickDevice OpenJoystick(string base_path, int number) - { - string path = base_path + number.ToString(); - JoystickDevice stick = null; - - int fd = -1; - try - { - fd = UnsafeNativeMethods.open(path, OpenFlags.NonBlock); - if (fd == -1) - return null; - - // Check joystick driver version (must be 1.0+) - int driver_version = 0x00000800; - UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Version, ref driver_version); - if (driver_version < 0x00010000) - return null; - - // Get number of joystick axes - int axes = 0; - UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Axes, ref axes); - - // Get number of joystick buttons - int buttons = 0; - UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons); - - stick = new JoystickDevice(fd, axes, buttons); - Debug.Print("Found joystick on path {0}", path); - } - finally - { - if (stick == null && fd != -1) - UnsafeNativeMethods.close(fd); - } - - return stick; - } - - #region UnsafeNativeMethods - - struct JoystickEvent - { - public uint Time; // (u32) event timestamp in milliseconds - public short Value; // (s16) value - public JoystickEventType Type; // (u8) event type - public byte Number; // (u8) axis/button number - } - - [Flags] - enum JoystickEventType : byte - { - Button = 0x01, // button pressed/released - Axis = 0x02, // joystick moved - Init = 0x80 // initial state of device - } - - enum JoystickIoctlCode : uint - { - Version = 0x80046a01, - Axes = 0x80016a11, - Buttons = 0x80016a12 - } - - static readonly string JoystickPath = "/dev/input/js"; - static readonly string JoystickPathLegacy = "/dev/js"; - - [Flags] - enum OpenFlags - { - NonBlock = 0x00000800 - } - - static class UnsafeNativeMethods - { - [DllImport("libc", SetLastError = true)] - public static extern int ioctl(int d, JoystickIoctlCode request, ref int data); - - [DllImport("libc", SetLastError = true)] - public static extern int open([MarshalAs(UnmanagedType.LPStr)]string pathname, OpenFlags flags); - - [DllImport("libc", SetLastError = true)] - public static extern int close(int fd); - - [DllImport("libc", SetLastError = true)] - unsafe public static extern IntPtr read(int fd, void* buffer, UIntPtr count); - } - - #endregion - - #endregion - - #region IDisposable Members - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - void Dispose(bool manual) - { - if (!disposed) - { - if (manual) - { - } - - foreach (JoystickDevice js in sticks) - { - UnsafeNativeMethods.close(js.Id); - } - - disposed = true; - } - } - - ~X11Joystick() - { - Dispose(false); - } - - #endregion - } -}