diff --git a/Silk.NET.sln b/Silk.NET.sln index 3298c81bf4..81164fbe62 100644 --- a/Silk.NET.sln +++ b/Silk.NET.sln @@ -59,6 +59,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenAL.Extensions. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenAL.Extensions.Soft.DeferredUpdates", "src\OpenAL\Extensions\Silk.NET.OpenAL.Extensions.Soft.DeferredUpdates\Silk.NET.OpenAL.Extensions.Soft.DeferredUpdates.csproj", "{50987EDD-9F49-4981-ADAE-98F01F4A4FBA}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Input", "Input", "{AE36230C-E8F4-4332-9F50-9253E6511FED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Input.Common", "src\Input\Silk.NET.Input.Common\Silk.NET.Input.Common.csproj", "{8FFF49D6-B029-400B-8510-19088868DFA6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -360,6 +364,18 @@ Global {50987EDD-9F49-4981-ADAE-98F01F4A4FBA}.Release|x64.Build.0 = Release|Any CPU {50987EDD-9F49-4981-ADAE-98F01F4A4FBA}.Release|x86.ActiveCfg = Release|Any CPU {50987EDD-9F49-4981-ADAE-98F01F4A4FBA}.Release|x86.Build.0 = Release|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Debug|x64.ActiveCfg = Debug|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Debug|x64.Build.0 = Debug|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Debug|x86.ActiveCfg = Debug|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Debug|x86.Build.0 = Debug|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Release|Any CPU.Build.0 = Release|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Release|x64.ActiveCfg = Release|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Release|x64.Build.0 = Release|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Release|x86.ActiveCfg = Release|Any CPU + {8FFF49D6-B029-400B-8510-19088868DFA6}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {BFE429EB-4C2E-4BF3-A302-C9C5A2FDA6D7} = {23324041-2076-477C-A4BF-B385B8066C6C} @@ -385,5 +401,6 @@ Global {4EE697B8-E6AA-47EF-B9E3-C4F9FFBCA4E7} = {896B1A79-FEC8-4B7A-8A9C-0CC8EDA2CCFC} {94D7D3A3-3640-4791-BE19-CA50C59187C6} = {896B1A79-FEC8-4B7A-8A9C-0CC8EDA2CCFC} {50987EDD-9F49-4981-ADAE-98F01F4A4FBA} = {896B1A79-FEC8-4B7A-8A9C-0CC8EDA2CCFC} + {8FFF49D6-B029-400B-8510-19088868DFA6} = {AE36230C-E8F4-4332-9F50-9253E6511FED} EndGlobalSection EndGlobal diff --git a/documentation/proposals/Proposal - Input.md b/documentation/proposals/Proposal - Input.md index 2bc3608173..a3207a597c 100644 --- a/documentation/proposals/Proposal - Input.md +++ b/documentation/proposals/Proposal - Input.md @@ -1,10 +1,11 @@ -# Summary +# Summary Proposal API for Input via keyboards, mice, and controllers. # Contributors - Dylan Perks, Ultz Limited - Aaron Pearson, Ultz Limited - Vassalware, Silk.NET Contributors +- Void, Silk.NET codeowners # Current Status - [x] Proposed @@ -117,7 +118,7 @@ public interface IInputPlatform public static class InputWindowExtensions { public static void RegisterInputPlatform(IInputPlatform platform); - public static void DeregisterInputPlatform(IInputPlatform platform); + public static void UnregisterInputPlatform(IInputPlatform platform); public static IInputContext GetInput(this IWindow window); } ``` @@ -129,6 +130,8 @@ public struct ScrollWheel { public float X { get; } public float Y { get; } + + public ScrollWheel(float x, float y); } ``` @@ -139,6 +142,8 @@ public struct Button public ButtonName Name { get; } public int Index { get; } public bool Pressed { get; } + + public Button(ButtonName name, int index, bool pressed); } ``` @@ -148,6 +153,8 @@ public struct Axis { public int Index { get; } public float Position { get; } + + public Axis(int index, float position); } ``` @@ -158,6 +165,8 @@ public struct Thumbstick public int Index { get; } public float Position { get; } public float Direction { get; } + + public Thumbstick(int index, float position, float direction); } ``` @@ -167,6 +176,8 @@ public struct Trigger { public int Index { get; } public float Position { get; } + + public Trigger(int index, float position); } ``` @@ -176,6 +187,8 @@ public struct Hat { public int Index { get; } public Position2D Position { get; } + + public Hat(int index, Position2D position); } ``` @@ -185,6 +198,8 @@ public struct Deadzone { public float Value { get; } public DeadzoneMethod Method { get; } + + public Deadzone(float value, DeadzoneMethod method); } ``` @@ -389,3 +404,22 @@ public enum Key LastKey } ``` + +### MouseButton +```cs +public enum MouseButton +{ + Left, + Middle, + Right, + Button4, + Button5, + Button6, + Button7, + Button8, + Button9, + Button10, + Button11, + Button12 +} +``` diff --git a/src/Input/Silk.NET.Input.Common/Axis.cs b/src/Input/Silk.NET.Input.Common/Axis.cs new file mode 100644 index 0000000000..1a953e0647 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Axis.cs @@ -0,0 +1,19 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public struct Axis + { + public int Index { get; } + public float Position { get; } + + public Axis(int index, float position) + { + Index = index; + Position = position; + } + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Button.cs b/src/Input/Silk.NET.Input.Common/Button.cs new file mode 100644 index 0000000000..45275c5080 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Button.cs @@ -0,0 +1,21 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public struct Button + { + public ButtonName Name { get; } + public int Index { get; } + public bool Pressed { get; } + + public Button(ButtonName name, int index, bool pressed) + { + Name = name; + Index = index; + Pressed = pressed; + } + } +} \ 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 new file mode 100644 index 0000000000..9b0f1b57d0 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Deadzone.cs @@ -0,0 +1,19 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public struct Deadzone + { + public float Value { get; } + public DeadzoneMethod Method { get; } + + public Deadzone(float value, DeadzoneMethod method) + { + Value = value; + Method = method; + } + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Enums/ButtonName.cs b/src/Input/Silk.NET.Input.Common/Enums/ButtonName.cs new file mode 100644 index 0000000000..39a7680dd2 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Enums/ButtonName.cs @@ -0,0 +1,28 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public enum ButtonName + { + A, + B, + X, + Y, + Back, + Home, + DPadUp, + DPadDown, + DPadLeft, + DPadRight, + LeftBumper, + LeftStick, + LeftTrigger, + RightBumper, + RightStick, + RightTrigger, + Start + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs b/src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs new file mode 100644 index 0000000000..cac6bfca41 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs @@ -0,0 +1,15 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public enum DeadzoneMethod + { + // y = x except where |x| is between 0 and d (the deadzone value) + Traditional, + // y = (1 - d)x + (d * sgn(x)) + AdaptiveGradient + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Enums/Key.cs b/src/Input/Silk.NET.Input.Common/Enums/Key.cs new file mode 100644 index 0000000000..1f4840d6c1 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Enums/Key.cs @@ -0,0 +1,158 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public enum Key + { + Unknown = 0, + ShiftLeft, + LShift = ShiftLeft, + ShiftRight, + RShift = ShiftRight, + ControlLeft, + LControl = ControlLeft, + ControlRight, + RControl = ControlRight, + AltLeft, + LAlt = AltLeft, + AltRight, + RAlt = AltRight, + WinLeft, + LWin = WinLeft, + WinRight, + RWin = WinRight, + Menu, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, + F22, + F23, + F24, + F25, + F26, + F27, + F28, + F29, + F30, + F31, + F32, + F33, + F34, + F35, + Up, + Down, + Left, + Right, + Enter, + Escape, + Space, + Tab, + BackSpace, + Back = BackSpace, + Insert, + Delete, + PageUp, + PageDown, + Home, + End, + CapsLock, + ScrollLock, + PrintScreen, + Pause, + NumLock, + Clear, + Sleep, + Keypad0, + Keypad1, + Keypad2, + Keypad3, + Keypad4, + Keypad5, + Keypad6, + Keypad7, + Keypad8, + Keypad9, + KeypadDivide, + KeypadMultiply, + KeypadSubtract, + KeypadMinus = KeypadSubtract, + KeypadAdd, + KeypadPlus = KeypadAdd, + KeypadDecimal, + KeypadPeriod = KeypadDecimal, + KeypadEnter, + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + Number0, + Number1, + Number2, + Number3, + Number4, + Number5, + Number6, + Number7, + Number8, + Number9, + Tilde, + Grave = Tilde, + Minus, + Plus, + BracketLeft, + LBracket = BracketLeft, + BracketRight, + RBracket = BracketRight, + Semicolon, + Quote, + Comma, + Period, + Slash, + BackSlash, + NonUSBackSlash, + LastKey + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Enums/MouseButton.cs b/src/Input/Silk.NET.Input.Common/Enums/MouseButton.cs new file mode 100644 index 0000000000..e20ef5870f --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Enums/MouseButton.cs @@ -0,0 +1,23 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public enum MouseButton + { + Left, + Middle, + Right, + Button4, + Button5, + Button6, + Button7, + Button8, + Button9, + Button10, + Button11, + Button12 + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Enums/Position2D.cs b/src/Input/Silk.NET.Input.Common/Enums/Position2D.cs new file mode 100644 index 0000000000..1a8d6e0da0 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Enums/Position2D.cs @@ -0,0 +1,23 @@ +// This file is part of Silk.NET. +// +// 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 +{ + [Flags] + public enum Position2D + { + Up, + Down, + Left, + Right, + + UpLeft = Up | Left, + UpRight = Up | Right, + DownLeft = Down | Left, + DownRight = Down | Right + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Hat.cs b/src/Input/Silk.NET.Input.Common/Hat.cs new file mode 100644 index 0000000000..a33676802d --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Hat.cs @@ -0,0 +1,19 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +namespace Silk.NET.Input.Common +{ + public struct Hat + { + public int Index { get; } + public Position2D Position { get; } + + public Hat(int index, Position2D position) + { + Index = index; + Position = position; + } + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/InputWindowExtensions.cs b/src/Input/Silk.NET.Input.Common/InputWindowExtensions.cs new file mode 100644 index 0000000000..c8514c5697 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/InputWindowExtensions.cs @@ -0,0 +1,28 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +using System; +using Silk.NET.Windowing.Common; + +namespace Silk.NET.Input.Common +{ + public static class InputWindowExtensions + { + public static void RegisterInputPlatform(IInputPlatform platform) + { + throw new NotImplementedException(); + } + + public static void UnregisterInputPlatform(IInputPlatform platform) + { + throw new NotImplementedException(); + } + + public static IInputContext GetInput(this IWindow window) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Input/Silk.NET.Input.Common/Interfaces/IGamepad.cs b/src/Input/Silk.NET.Input.Common/Interfaces/IGamepad.cs new file mode 100644 index 0000000000..e798a64f82 --- /dev/null +++ b/src/Input/Silk.NET.Input.Common/Interfaces/IGamepad.cs @@ -0,0 +1,22 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +using System; +using System.Collections.Generic; + +namespace Silk.NET.Input.Common +{ + public interface IGamepad : IInputDevice + { + IReadOnlyCollection