diff --git a/Silk.NET.sln b/Silk.NET.sln index 9f5d188048..1f26bbb3a4 100644 --- a/Silk.NET.sln +++ b/Silk.NET.sln @@ -169,6 +169,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Input.Desktop", "s EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Input", "src\Input\Silk.NET.Input\Silk.NET.Input.csproj", "{020A8E88-B607-4281-BA0D-5ED03484A201}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InputTest", "examples\InputTest\InputTest.csproj", "{3E744E54-F450-4051-8919-04D9B591688E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1058,6 +1060,18 @@ Global {020A8E88-B607-4281-BA0D-5ED03484A201}.Release|x64.Build.0 = Release|Any CPU {020A8E88-B607-4281-BA0D-5ED03484A201}.Release|x86.ActiveCfg = Release|Any CPU {020A8E88-B607-4281-BA0D-5ED03484A201}.Release|x86.Build.0 = Release|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Debug|x64.ActiveCfg = Debug|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Debug|x64.Build.0 = Debug|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Debug|x86.ActiveCfg = Debug|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Debug|x86.Build.0 = Debug|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Release|Any CPU.Build.0 = Release|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Release|x64.ActiveCfg = Release|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Release|x64.Build.0 = Release|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Release|x86.ActiveCfg = Release|Any CPU + {3E744E54-F450-4051-8919-04D9B591688E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {BFE429EB-4C2E-4BF3-A302-C9C5A2FDA6D7} = {23324041-2076-477C-A4BF-B385B8066C6C} @@ -1134,5 +1148,6 @@ Global {136C6154-D300-4B82-80D3-17B637841A2B} = {0651C5EF-50AA-4598-8D9C-8F210ADD8490} {3908DEF6-7403-49F5-B8EC-5B3B12C325D4} = {FA9D1C95-5585-4DEC-B226-1447A486C376} {020A8E88-B607-4281-BA0D-5ED03484A201} = {FA9D1C95-5585-4DEC-B226-1447A486C376} + {3E744E54-F450-4051-8919-04D9B591688E} = {E1F91563-7277-4E9B-A3B7-8D5FD9802A4A} EndGlobalSection EndGlobal diff --git a/examples/InputTest/InputTest.csproj b/examples/InputTest/InputTest.csproj new file mode 100644 index 0000000000..ef123cd998 --- /dev/null +++ b/examples/InputTest/InputTest.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.1 + + + + + + + diff --git a/examples/InputTest/Program.cs b/examples/InputTest/Program.cs new file mode 100644 index 0000000000..6415f986da --- /dev/null +++ b/examples/InputTest/Program.cs @@ -0,0 +1,26 @@ +using System; +using Silk.NET.Input.Common; +using Silk.NET.Input.Desktop; +using Silk.NET.Windowing.Common; +using Silk.NET.Windowing.Desktop; + +namespace InputTest +{ + internal class Program + { + private static void Main() + { + var window = new GlfwWindow(WindowOptions.Default); + + var inputContext = new GlfwInputContext(window); + inputContext.ConnectionChanged += ControllerConnected; + } + + public static void ControllerConnected(IInputDevice device, bool isConnected) + { + Console.WriteLine(isConnected + ? $"Controller {device.Name} connected" + : $"Controller {device.Name} disconnected"); + } + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Deadzone.cs b/src/Input/Silk.NET.Input.Common/Deadzone.cs index e7b0fc39cf..ac32532cd4 100644 --- a/src/Input/Silk.NET.Input.Common/Deadzone.cs +++ b/src/Input/Silk.NET.Input.Common/Deadzone.cs @@ -3,6 +3,8 @@ // You may modify and distribute Silk.NET under the terms // of the MIT license. See the LICENSE file for details. +using System; + namespace Silk.NET.Input.Common { /// @@ -30,5 +32,25 @@ public Deadzone(float value, DeadzoneMethod method) Value = value; Method = method; } + + /// + /// Applies this deadzone to a raw input value. + /// + /// The raw input value to apply the deadzone to. + /// The input with deadzone applied. + /// If the deadzone method isn't part of + /// + public float Apply(float raw) + { + switch (Method) + { + case DeadzoneMethod.Traditional: + return Math.Abs(raw) < Value ? 0 : raw; + case DeadzoneMethod.AdaptiveGradient: + return (1 - Value) * raw + Value * Math.Sign(raw); + default: + throw new ArgumentOutOfRangeException(); + } + } } } \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Interfaces/IInputContext.cs b/src/Input/Silk.NET.Input.Common/Interfaces/IInputContext.cs index 3a68187dba..72d41f491e 100644 --- a/src/Input/Silk.NET.Input.Common/Interfaces/IInputContext.cs +++ b/src/Input/Silk.NET.Input.Common/Interfaces/IInputContext.cs @@ -54,5 +54,10 @@ public interface IInputContext : IDisposable /// support other devices. /// IReadOnlyList OtherDevices { get; } + + /// + /// Called when the connection status of a device changes. + /// + event Action ConnectionChanged; } } \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Interfaces/IInputDevice.cs b/src/Input/Silk.NET.Input.Common/Interfaces/IInputDevice.cs index d466bc2128..b5d5b929f3 100644 --- a/src/Input/Silk.NET.Input.Common/Interfaces/IInputDevice.cs +++ b/src/Input/Silk.NET.Input.Common/Interfaces/IInputDevice.cs @@ -3,8 +3,6 @@ // You may modify and distribute Silk.NET under the terms // of the MIT license. See the LICENSE file for details. -using System; - namespace Silk.NET.Input.Common { /// @@ -26,10 +24,5 @@ public interface IInputDevice /// Whether or not this device is currently connected. /// bool IsConnected { get; } - - /// - /// Called when the connection of this device changes. - /// - event Action ConnectionChanged; } } \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Desktop/GlfwInputContext.cs b/src/Input/Silk.NET.Input.Desktop/GlfwInputContext.cs index bf8314507f..eeeae42127 100644 --- a/src/Input/Silk.NET.Input.Desktop/GlfwInputContext.cs +++ b/src/Input/Silk.NET.Input.Desktop/GlfwInputContext.cs @@ -57,5 +57,8 @@ public void WindowUpdate(double obj) { throw new NotImplementedException(); } + + /// + public event Action ConnectionChanged; } } diff --git a/src/Input/Silk.NET.Input.Desktop/Implementations/GlfwGamepad.cs b/src/Input/Silk.NET.Input.Desktop/Implementations/GlfwGamepad.cs index b387e154f0..b785ced56c 100644 --- a/src/Input/Silk.NET.Input.Desktop/Implementations/GlfwGamepad.cs +++ b/src/Input/Silk.NET.Input.Desktop/Implementations/GlfwGamepad.cs @@ -19,7 +19,6 @@ public GlfwGamepad(int i) public string Name => Util.Do(() => Util.Glfw.GetGamepadName(Index)); public int Index { get; } public bool IsConnected => Util.Do(() => Util.Glfw.JoystickIsGamepad(Index)); - public event Action ConnectionChanged; public IReadOnlyList