From 5215891a4fbc8882aa2cf77174119d902f6f23bd Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Tue, 24 Dec 2013 03:16:32 +0100 Subject: [PATCH] Added IJoystickDevice2 interface --- Source/OpenTK/Input/GamePadCapabilities.cs | 33 -------- Source/OpenTK/Input/GamePadType.cs | 4 +- Source/OpenTK/Input/IInputDriver2.cs | 1 + Source/OpenTK/Input/IJoystickDriver2.cs | 41 ++++++++++ Source/OpenTK/Input/Joystick.cs | 51 ++++++++++++ Source/OpenTK/Input/JoystickAxis.cs | 62 +++++++++++++++ Source/OpenTK/Input/JoystickButton.cs | 78 ++++++++++++++++++ Source/OpenTK/Input/JoystickCapabilities.cs | 75 ++++++++++++++++++ Source/OpenTK/Input/JoystickDevice.cs | 74 ----------------- Source/OpenTK/Input/JoystickState.cs | 79 +++++++++++++++++++ Source/OpenTK/OpenTK.csproj | 6 ++ Source/OpenTK/Platform/Factory.cs | 10 +++ Source/OpenTK/Platform/IPlatformFactory.cs | 2 + Source/OpenTK/Platform/MacOS/CarbonInput.cs | 5 ++ Source/OpenTK/Platform/MacOS/HIDInput.cs | 20 ++++- Source/OpenTK/Platform/MacOS/MacOSFactory.cs | 5 ++ Source/OpenTK/Platform/SDL2/Sdl2Factory.cs | 5 ++ .../OpenTK/Platform/SDL2/Sdl2InputDriver.cs | 8 ++ .../Platform/SDL2/Sdl2JoystickDriver.cs | 16 +++- Source/OpenTK/Platform/Windows/WinFactory.cs | 7 +- .../OpenTK/Platform/Windows/WinInputBase.cs | 2 + .../OpenTK/Platform/Windows/WinMMJoystick.cs | 8 +- Source/OpenTK/Platform/Windows/WinRawInput.cs | 5 ++ .../OpenTK/Platform/Windows/XInputJoystick.cs | 4 +- Source/OpenTK/Platform/X11/X11Factory.cs | 6 ++ Source/OpenTK/Platform/X11/X11Joystick.cs | 16 +++- 26 files changed, 503 insertions(+), 120 deletions(-) create mode 100644 Source/OpenTK/Input/IJoystickDriver2.cs create mode 100644 Source/OpenTK/Input/Joystick.cs create mode 100644 Source/OpenTK/Input/JoystickAxis.cs create mode 100644 Source/OpenTK/Input/JoystickButton.cs create mode 100644 Source/OpenTK/Input/JoystickCapabilities.cs create mode 100644 Source/OpenTK/Input/JoystickState.cs diff --git a/Source/OpenTK/Input/GamePadCapabilities.cs b/Source/OpenTK/Input/GamePadCapabilities.cs index 16707aba..c637f771 100644 --- a/Source/OpenTK/Input/GamePadCapabilities.cs +++ b/Source/OpenTK/Input/GamePadCapabilities.cs @@ -34,11 +34,6 @@ namespace OpenTK.Input public struct GamePadCapabilities : IEquatable { - byte axis_count; - byte button_count; - byte dpad_count; - byte trackball_count; - Buttons buttons; byte gamepad_type; bool is_connected; @@ -221,34 +216,6 @@ namespace OpenTK.Input #endregion - #region Internal Members - - internal int AxisCount - { - get { return axis_count; } - set { axis_count = (byte)value; } - } - - internal int ButtonCount - { - get { return button_count; } - set { button_count = (byte)value; } - } - - internal int DPadCount - { - get { return dpad_count; } - set { dpad_count = (byte)value; } - } - - internal int TrackballCount - { - get { return trackball_count; } - set { trackball_count = (byte)value; } - } - - #endregion - #region IEquatable Members public bool Equals(GamePadCapabilities other) diff --git a/Source/OpenTK/Input/GamePadType.cs b/Source/OpenTK/Input/GamePadType.cs index a4eddef8..1524e024 100644 --- a/Source/OpenTK/Input/GamePadType.cs +++ b/Source/OpenTK/Input/GamePadType.cs @@ -1,4 +1,4 @@ -// #region License +#region License // // GamePadType.cs // @@ -25,7 +25,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // -// #endregion +#endregion namespace OpenTK.Input { diff --git a/Source/OpenTK/Input/IInputDriver2.cs b/Source/OpenTK/Input/IInputDriver2.cs index 7cd788aa..0e4c5132 100644 --- a/Source/OpenTK/Input/IInputDriver2.cs +++ b/Source/OpenTK/Input/IInputDriver2.cs @@ -37,5 +37,6 @@ namespace OpenTK.Input IMouseDriver2 MouseDriver { get; } IKeyboardDriver2 KeyboardDriver { get; } IGamePadDriver GamePadDriver { get; } + IJoystickDriver2 JoystickDriver { get; } } } diff --git a/Source/OpenTK/Input/IJoystickDriver2.cs b/Source/OpenTK/Input/IJoystickDriver2.cs new file mode 100644 index 00000000..1359d1de --- /dev/null +++ b/Source/OpenTK/Input/IJoystickDriver2.cs @@ -0,0 +1,41 @@ +#region License +// +// IJoystickDriver2.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 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 +// 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; + +namespace OpenTK.Input +{ + interface IJoystickDriver2 + { + JoystickState GetState(int index); + JoystickCapabilities GetCapabilities(int index); + } +} diff --git a/Source/OpenTK/Input/Joystick.cs b/Source/OpenTK/Input/Joystick.cs new file mode 100644 index 00000000..0458abed --- /dev/null +++ b/Source/OpenTK/Input/Joystick.cs @@ -0,0 +1,51 @@ +#region License +// +// Joystick.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 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 +// 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; + +namespace OpenTK.Input +{ + public class Joystick + { + static readonly IJoystickDriver2 implementation = + Platform.Factory.Default.CreateJoystickDriver(); + + public static JoystickCapabilities GetCapabilities(int index) + { + return implementation.GetCapabilities(index); + } + + public static JoystickState GetState(int index) + { + return implementation.GetState(index); + } + } +} diff --git a/Source/OpenTK/Input/JoystickAxis.cs b/Source/OpenTK/Input/JoystickAxis.cs new file mode 100644 index 00000000..1e166e66 --- /dev/null +++ b/Source/OpenTK/Input/JoystickAxis.cs @@ -0,0 +1,62 @@ +#region License +// +// JoystickAxis.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 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 +// 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; + +namespace OpenTK.Input +{ + /// + /// 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, + } +} diff --git a/Source/OpenTK/Input/JoystickButton.cs b/Source/OpenTK/Input/JoystickButton.cs new file mode 100644 index 00000000..cf3a9ca6 --- /dev/null +++ b/Source/OpenTK/Input/JoystickButton.cs @@ -0,0 +1,78 @@ +#region License +// +// JoystickButton.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 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 +// 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; + +namespace OpenTK.Input +{ + #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 +} diff --git a/Source/OpenTK/Input/JoystickCapabilities.cs b/Source/OpenTK/Input/JoystickCapabilities.cs new file mode 100644 index 00000000..5265d209 --- /dev/null +++ b/Source/OpenTK/Input/JoystickCapabilities.cs @@ -0,0 +1,75 @@ +#region License +// +// JoystickCapabilities.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 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 +// 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; + +namespace OpenTK.Input +{ + public struct JoystickCapabilities + { + byte axis_count; + byte button_count; + byte dpad_count; + byte trackball_count; + + #region Public Members + + public int AxisCount + { + get { return axis_count; } + set { axis_count = (byte)value; } + } + + public int ButtonCount + { + get { return button_count; } + set { button_count = (byte)value; } + } + + #endregion + + #region Private Members + + int DPadCount + { + get { return dpad_count; } + set { dpad_count = (byte)value; } + } + + int TrackballCount + { + get { return trackball_count; } + set { trackball_count = (byte)value; } + } + + #endregion + } +} diff --git a/Source/OpenTK/Input/JoystickDevice.cs b/Source/OpenTK/Input/JoystickDevice.cs index 6f99cdac..d02d5b4c 100644 --- a/Source/OpenTK/Input/JoystickDevice.cs +++ b/Source/OpenTK/Input/JoystickDevice.cs @@ -271,49 +271,6 @@ namespace OpenTK.Input #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 /// @@ -376,37 +333,6 @@ namespace OpenTK.Input #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 /// diff --git a/Source/OpenTK/Input/JoystickState.cs b/Source/OpenTK/Input/JoystickState.cs new file mode 100644 index 00000000..28775e69 --- /dev/null +++ b/Source/OpenTK/Input/JoystickState.cs @@ -0,0 +1,79 @@ +#region License +// +// JoystickState.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 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 +// 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.Text; + +namespace OpenTK.Input +{ + public struct JoystickState + { + const int MaxAxes = 10; // JoystickAxis defines 10 axes + const float ConversionFactor = 1.0f / short.MaxValue; + unsafe fixed short axes[MaxAxes]; + JoystickButton buttons; + + public float GetAxis(JoystickAxis axis) + { + return GetAxis((int)axis); + } + + public float GetAxis(int axis) + { + float value = 0.0f; + if (axis >= 0 && axis < MaxAxes) + { + unsafe + { + fixed (short* paxis = axes) + { + value = *(paxis + axis) * ConversionFactor; + } + } + } + else + { + Debug.Print("[Joystick] Invalid axis {0}", axis); + } + return value; + } + + public bool IsButtonDown(JoystickButton button) + { + return (buttons & button) != 0; + } + + public bool IsButtonUp(JoystickButton button) + { + return (buttons & button) == 0; + } + } +} diff --git a/Source/OpenTK/OpenTK.csproj b/Source/OpenTK/OpenTK.csproj index c7de48e4..01e5c793 100644 --- a/Source/OpenTK/OpenTK.csproj +++ b/Source/OpenTK/OpenTK.csproj @@ -138,8 +138,14 @@ + + + + + + diff --git a/Source/OpenTK/Platform/Factory.cs b/Source/OpenTK/Platform/Factory.cs index a3ffa951..e49eb36b 100644 --- a/Source/OpenTK/Platform/Factory.cs +++ b/Source/OpenTK/Platform/Factory.cs @@ -149,6 +149,11 @@ namespace OpenTK.Platform return default_implementation.CreateGamePadDriver(); } + public Input.IJoystickDriver2 CreateJoystickDriver() + { + return default_implementation.CreateJoystickDriver(); + } + class UnsupportedPlatform : IPlatformFactory { #region Fields @@ -210,6 +215,11 @@ namespace OpenTK.Platform throw new PlatformNotSupportedException(error_string); } + public Input.IJoystickDriver2 CreateJoystickDriver() + { + throw new PlatformNotSupportedException(error_string); + } + #endregion #region IDisposable Members diff --git a/Source/OpenTK/Platform/IPlatformFactory.cs b/Source/OpenTK/Platform/IPlatformFactory.cs index 541c8710..c59654f3 100644 --- a/Source/OpenTK/Platform/IPlatformFactory.cs +++ b/Source/OpenTK/Platform/IPlatformFactory.cs @@ -52,5 +52,7 @@ namespace OpenTK.Platform OpenTK.Input.IMouseDriver2 CreateMouseDriver(); OpenTK.Input.IGamePadDriver CreateGamePadDriver(); + + Input.IJoystickDriver2 CreateJoystickDriver(); } } diff --git a/Source/OpenTK/Platform/MacOS/CarbonInput.cs b/Source/OpenTK/Platform/MacOS/CarbonInput.cs index 1fd65a2c..640b99b8 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonInput.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonInput.cs @@ -113,5 +113,10 @@ namespace OpenTK.Platform.MacOS throw new NotImplementedException(); } } + + public IJoystickDriver2 JoystickDriver + { + get { throw new NotImplementedException(); } + } } } diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index c3e55612..613d1c64 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -50,7 +50,7 @@ namespace OpenTK.Platform.MacOS // Requires Mac OS X 10.5 or higher. // Todo: create a driver for older installations. Maybe use CGGetLastMouseDelta for that? - class HIDInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2, IGamePadDriver + class HIDInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2, IGamePadDriver, IJoystickDriver2 { #region Fields @@ -93,7 +93,7 @@ namespace OpenTK.Platform.MacOS #endregion - #region Private Members + #region Private Members IOHIDManagerRef CreateHIDManager() { @@ -292,6 +292,8 @@ namespace OpenTK.Platform.MacOS public IMouseDriver2 MouseDriver { get { return this; } } public IKeyboardDriver2 KeyboardDriver { get { return this; } } public IGamePadDriver GamePadDriver { get { return this; } } + public IJoystickDriver2 JoystickDriver { get { return this; } } + #endregion @@ -385,6 +387,20 @@ namespace OpenTK.Platform.MacOS #endregion + #region IJoystickDriver2 Members + + JoystickState IJoystickDriver2.GetState(int index) + { + throw new NotImplementedException(); + } + + JoystickCapabilities IJoystickDriver2.GetCapabilities(int index) + { + throw new NotImplementedException(); + } + + #endregion + #region NativeMethods class NativeMethods diff --git a/Source/OpenTK/Platform/MacOS/MacOSFactory.cs b/Source/OpenTK/Platform/MacOS/MacOSFactory.cs index ad540311..e7dd5f05 100644 --- a/Source/OpenTK/Platform/MacOS/MacOSFactory.cs +++ b/Source/OpenTK/Platform/MacOS/MacOSFactory.cs @@ -93,6 +93,11 @@ namespace OpenTK.Platform.MacOS { return InputDriver.GamePadDriver; } + + public IJoystickDriver2 CreateJoystickDriver() + { + return InputDriver.JoystickDriver; + } #endregion diff --git a/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs b/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs index 4c39156f..b8015f6b 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs @@ -104,6 +104,11 @@ namespace OpenTK.Platform.SDL2 return InputDriver.GamePadDriver; } + public IJoystickDriver2 CreateJoystickDriver() + { + return InputDriver.JoystickDriver; + } + #endregion #region IDisposable Members diff --git a/Source/OpenTK/Platform/SDL2/Sdl2InputDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2InputDriver.cs index 3a69be40..023af9a2 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2InputDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2InputDriver.cs @@ -220,6 +220,14 @@ namespace OpenTK.Platform.SDL2 } } + public IJoystickDriver2 JoystickDriver + { + get + { + return joystick_driver; + } + } + #endregion #region IDisposable Members diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs index 6c7e2728..701c38d6 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs @@ -32,7 +32,7 @@ using OpenTK.Input; namespace OpenTK.Platform.SDL2 { - class Sdl2JoystickDriver : IJoystickDriver, IGamePadDriver, IDisposable + class Sdl2JoystickDriver : IJoystickDriver, IJoystickDriver2, IGamePadDriver, IDisposable { const float RangeMultiplier = 1.0f / 32768.0f; @@ -322,6 +322,20 @@ namespace OpenTK.Platform.SDL2 #endregion + #region IJoystickDriver2 Members + + JoystickState IJoystickDriver2.GetState(int index) + { + throw new NotImplementedException(); + } + + JoystickCapabilities IJoystickDriver2.GetCapabilities(int index) + { + throw new NotImplementedException(); + } + + #endregion + #region IDisposable Members void Dispose(bool manual) diff --git a/Source/OpenTK/Platform/Windows/WinFactory.cs b/Source/OpenTK/Platform/Windows/WinFactory.cs index 5ea1a8eb..4fa46e2e 100644 --- a/Source/OpenTK/Platform/Windows/WinFactory.cs +++ b/Source/OpenTK/Platform/Windows/WinFactory.cs @@ -130,7 +130,12 @@ namespace OpenTK.Platform.Windows { return InputDriver.GamePadDriver; } - + + public IJoystickDriver2 CreateJoystickDriver() + { + return InputDriver.JoystickDriver; + } + #endregion IInputDriver2 InputDriver diff --git a/Source/OpenTK/Platform/Windows/WinInputBase.cs b/Source/OpenTK/Platform/Windows/WinInputBase.cs index 252a6f8d..7d0865f1 100644 --- a/Source/OpenTK/Platform/Windows/WinInputBase.cs +++ b/Source/OpenTK/Platform/Windows/WinInputBase.cs @@ -164,6 +164,8 @@ namespace OpenTK.Platform.Windows public abstract IKeyboardDriver2 KeyboardDriver { get; } public abstract IGamePadDriver GamePadDriver { get; } + public abstract IJoystickDriver2 JoystickDriver { get; } + #endregion #region IDisposable Members diff --git a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs index 07c208cc..e7c71541 100644 --- a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs +++ b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs @@ -445,10 +445,10 @@ namespace OpenTK.Platform.Windows JoystickError result = UnsafeNativeMethods.joyGetDevCaps(index, out caps, JoyCaps.SizeInBytes); if (result == JoystickError.NoError) { - gpcaps.AxisCount = caps.NumAxes; - gpcaps.ButtonCount = caps.NumButtons; - if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0) - gpcaps.DPadCount++; + //gpcaps.AxisCount = caps.NumAxes; + //gpcaps.ButtonCount = caps.NumButtons; + //if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0) + // gpcaps.DPadCount++; } } else diff --git a/Source/OpenTK/Platform/Windows/WinRawInput.cs b/Source/OpenTK/Platform/Windows/WinRawInput.cs index c905b65b..04025efd 100644 --- a/Source/OpenTK/Platform/Windows/WinRawInput.cs +++ b/Source/OpenTK/Platform/Windows/WinRawInput.cs @@ -190,6 +190,11 @@ namespace OpenTK.Platform.Windows get { return joystick_driver; } } + public override IJoystickDriver2 JoystickDriver + { + get { throw new NotImplementedException(); } + } + #endregion } } diff --git a/Source/OpenTK/Platform/Windows/XInputJoystick.cs b/Source/OpenTK/Platform/Windows/XInputJoystick.cs index f3e0c04e..c6d7def1 100644 --- a/Source/OpenTK/Platform/Windows/XInputJoystick.cs +++ b/Source/OpenTK/Platform/Windows/XInputJoystick.cs @@ -1,4 +1,4 @@ -// #region License +#region License // // XInputJoystick.cs // @@ -25,7 +25,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // -// #endregion +#endregion using System; using System.Collections.Generic; diff --git a/Source/OpenTK/Platform/X11/X11Factory.cs b/Source/OpenTK/Platform/X11/X11Factory.cs index 8b8344df..0fb80058 100644 --- a/Source/OpenTK/Platform/X11/X11Factory.cs +++ b/Source/OpenTK/Platform/X11/X11Factory.cs @@ -98,6 +98,12 @@ namespace OpenTK.Platform.X11 return new X11Joystick(); } + public virtual OpenTK.Input.IJoystickDriver2 CreateJoystickDriver() + { + return new X11Joystick(); + } + + #endregion #region IDisposable Members diff --git a/Source/OpenTK/Platform/X11/X11Joystick.cs b/Source/OpenTK/Platform/X11/X11Joystick.cs index b4948169..36fac9f2 100644 --- a/Source/OpenTK/Platform/X11/X11Joystick.cs +++ b/Source/OpenTK/Platform/X11/X11Joystick.cs @@ -36,7 +36,7 @@ namespace OpenTK.Platform.X11 { struct X11JoyDetails { } - sealed class X11Joystick : IJoystickDriver, IGamePadDriver + sealed class X11Joystick : IJoystickDriver, IJoystickDriver2, IGamePadDriver { #region Fields @@ -277,5 +277,19 @@ namespace OpenTK.Platform.X11 } #endregion + + #region IJoystickDriver2 Members + + JoystickState IJoystickDriver2.GetState(int index) + { + throw new NotImplementedException(); + } + + JoystickCapabilities IJoystickDriver2.GetCapabilities(int index) + { + throw new NotImplementedException(); + } + + #endregion } }