From 9a57a7af4a3316164049511b6acb6a484f0bc761 Mon Sep 17 00:00:00 2001 From: ThomasMiz <32400648+ThomasMiz@users.noreply.github.com> Date: Tue, 12 Jan 2021 12:53:56 -0300 Subject: [PATCH 1/5] Created Propostal - Enhanced Input Events.md --- .../Proposal - Enhanced Input Events.md | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 documentation/proposals/Proposal - Enhanced Input Events.md diff --git a/documentation/proposals/Proposal - Enhanced Input Events.md b/documentation/proposals/Proposal - Enhanced Input Events.md new file mode 100644 index 0000000000..eee2041cee --- /dev/null +++ b/documentation/proposals/Proposal - Enhanced Input Events.md @@ -0,0 +1,157 @@ +# Summary +Proposal for adding important missing functionality to input, as well as other enhancements. + +# Contributors +- ThomasMiz + +# Current Status +- [x] Proposed +- [ ] Discussed with API Review Board (ARB) +- [ ] Approved +- [ ] Implemented + +# Design Decisions +- Event parameters will be turned into readonly structures to prevent long parameter lists in some cases and allow more parameters (such as deltas) to be added in the future without breaking. + +# Proposed API +The only API changes will be to the events presented by IMouse, IKeyboard and possibly other device interfaces. + +## Enums + +#### KeyAction +```cs +/// +/// Defines actions for keyboard keys. +/// +public enum KeyAction +{ + Press, + Repeat, + Release +} +``` + +#### ButtonAction +```cs +/// +/// Defines actions for mouse buttons. +/// +public enum ButtonAction +{ + Press, + Release +} +``` + +#### KeyModifiers +Based on [the modifier keys flag from GLFW](https://www.glfw.org/docs/latest/group__mods.html). +```cs +[Flags] +public enum KeyModifiers +{ + Shift = 1, + Control = 2, + Alt = 4, + Super = 8, + CapsLock = 16, + NumLock = 32 +} +``` + +## Structs + +#### KeyEventArgs +```cs +public readonly struct KeyEventArgs +{ + public IKeyboard Keyboard { get; } + public Key Key { get; } + public int KeyCode { get; } + public KeyAction Action { get; } + public KeyModifiers Modifiers { get; } +} +``` + +#### CharacterTypedEventArgs +```cs +public readonly struct CharacterTypedEventArgs +{ + public IKeyboard Keyboard { get; } + public char Character { get; } +} +``` + +#### MouseMoveEventArgs +```cs +public readonly struct MouseMoveEventArgs +{ + public IMouse Mouse { get; } + public Vector2 Position { get; } + // We can also add to get the difference between Position and the Position in the last move mouse invocation: + // public Vector2 Delta { get; } +} +``` + +#### MouseButtonEventArgs +```cs +public readonly struct MouseButtonEventArgs +{ + public IMouse Mouse { get; } + public Vector2 Position { get; } + public MouseButton Button { get; } + public ButtonAction Action { get; } + public KeyModifiers Modifiers { get; } +} +``` + +#### MouseScrollEventArgs +This would replace the current ScrollWheel struct. +```cs +public readonly struct MouseScrollEventArgs +{ + public IMouse Mouse { get; } + public Vector2 Position { get; } + public Vector2 WheelPosition { get; } +} +``` + +## Interface changes + +#### IKeyboard +```cs +public interface IKeyboard : IInputDevice +{ + // event Action KeyDown; + // event Action KeyUp; + // event Action KeyChar; + + event Action KeyDown; + event Action KeyUp; + // The KeyAction.Press and Repeat are reported through KeyDown. KeyAction.Release is reported through KeyUp. + // Another possibility is to report KeyAction.Repeat on a separate event, or to pack the three into a single KeyAction event. + + event Action CharacterTyped; +} +``` + +#### IMouse +```cs +public interface IMouse : IInputDevice +{ + // event Action MouseMove; + // event Action MouseDown; + // event Action MouseUp; + // event Action Scroll; + // event Action Click; + // event Action DoubleClick; + + event Action MouseMove; + event Action MouseDown; + event Action MouseUp; + event Action Scroll; + event Action Click; + event Action DoubleClick; +} +``` + +These changes can also be applied to other IDevices to keep consistency across our API. \ No newline at end of file From 9fa2a1d27141b48e9f1d9c627411d22e4bec2f8d Mon Sep 17 00:00:00 2001 From: ThomasMiz <32400648+ThomasMiz@users.noreply.github.com> Date: Sat, 1 May 2021 15:19:32 -0300 Subject: [PATCH 2/5] Update Proposal - Enhanced Input Events.md --- .../Proposal - Enhanced Input Events.md | 78 +++++++++++-------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/documentation/proposals/Proposal - Enhanced Input Events.md b/documentation/proposals/Proposal - Enhanced Input Events.md index eee2041cee..0b2dd4b508 100644 --- a/documentation/proposals/Proposal - Enhanced Input Events.md +++ b/documentation/proposals/Proposal - Enhanced Input Events.md @@ -6,7 +6,7 @@ Proposal for adding important missing functionality to input, as well as other e # Current Status - [x] Proposed -- [ ] Discussed with API Review Board (ARB) +- [x] Discussed with API Review Board (ARB) - [ ] Approved - [ ] Implemented @@ -25,9 +25,9 @@ The only API changes will be to the events presented by IMouse, IKeyboard and po /// public enum KeyAction { - Press, + Pressed, Repeat, - Release + Released } ``` @@ -38,8 +38,8 @@ public enum KeyAction /// public enum ButtonAction { - Press, - Release + Pressed, + Released } ``` @@ -49,20 +49,20 @@ Based on [the modifier keys flag from GLFW](https://www.glfw.org/docs/latest/gro [Flags] public enum KeyModifiers { - Shift = 1, - Control = 2, - Alt = 4, - Super = 8, - CapsLock = 16, - NumLock = 32 + Shift = 1 << 1, + Control = 1 << 2, + Alt = 1 << 3, + Super = 1 << 4, + CapsLock = 1 << 5, + NumLock = 1 << 6 } ``` ## Structs -#### KeyEventArgs +#### KeyEvent ```cs -public readonly struct KeyEventArgs +public readonly struct KeyEvent { public IKeyboard Keyboard { get; } public Key Key { get; } @@ -72,18 +72,18 @@ public readonly struct KeyEventArgs } ``` -#### CharacterTypedEventArgs +#### KeyCharEvent ```cs -public readonly struct CharacterTypedEventArgs +public readonly struct KeyCharEvent { public IKeyboard Keyboard { get; } public char Character { get; } } ``` -#### MouseMoveEventArgs +#### MouseMoveEvent ```cs -public readonly struct MouseMoveEventArgs +public readonly struct MouseMoveEvent { public IMouse Mouse { get; } public Vector2 Position { get; } @@ -92,9 +92,9 @@ public readonly struct MouseMoveEventArgs } ``` -#### MouseButtonEventArgs +#### MouseButtonEvent ```cs -public readonly struct MouseButtonEventArgs +public readonly struct MouseButtonEvent { public IMouse Mouse { get; } public Vector2 Position { get; } @@ -104,14 +104,26 @@ public readonly struct MouseButtonEventArgs } ``` -#### MouseScrollEventArgs +#### MouseScrollEvent This would replace the current ScrollWheel struct. ```cs -public readonly struct MouseScrollEventArgs +public readonly struct MouseScrollEvent { public IMouse Mouse { get; } public Vector2 Position { get; } public Vector2 WheelPosition { get; } + // public Vector2 Delta { get; } +} +``` + +#### MouseClickEvent +```cs +public readonly struct MouseClickEvent +{ + public IMouse Mouse { get; } + public Vector2 Position { get; } + public MouseButton Button { get; } + public KeyModifier Modifiers { get; } } ``` @@ -121,16 +133,15 @@ public readonly struct MouseScrollEventArgs ```cs public interface IKeyboard : IInputDevice { + // The old events get removed: // event Action KeyDown; // event Action KeyUp; // event Action KeyChar; - event Action KeyDown; - event Action KeyUp; - // The KeyAction.Press and Repeat are reported through KeyDown. KeyAction.Release is reported through KeyUp. - // Another possibility is to report KeyAction.Repeat on a separate event, or to pack the three into a single KeyAction event. + // Reports all key events, KeyAction.Press, KeyAction.Repeat and KeyAction.Release + event Action KeyAction; - event Action CharacterTyped; + event Action KeyChar; } ``` @@ -138,6 +149,7 @@ public interface IKeyboard : IInputDevice ```cs public interface IMouse : IInputDevice { + // The old events get removed: // event Action MouseMove; // event Action MouseDown; // event Action MouseUp; @@ -145,13 +157,13 @@ public interface IMouse : IInputDevice // event Action Click; // event Action DoubleClick; - event Action MouseMove; - event Action MouseDown; - event Action MouseUp; - event Action Scroll; - event Action Click; - event Action DoubleClick; + event Action MouseMove; + event Action MouseDown; + event Action MouseUp; + event Action Scroll; + event Action Click; + event Action DoubleClick; } ``` -These changes can also be applied to other IDevices to keep consistency across our API. \ No newline at end of file +These changes can also be applied to other IDevices to keep consistency across our API. From 1c4712ca52da23752cc4c2320ce6e17149ca437c Mon Sep 17 00:00:00 2001 From: ThomasMiz <32400648+ThomasMiz@users.noreply.github.com> Date: Sat, 1 May 2021 15:46:36 -0300 Subject: [PATCH 3/5] Update Proposal - Enhanced Input Events.md --- .../Proposal - Enhanced Input Events.md | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/documentation/proposals/Proposal - Enhanced Input Events.md b/documentation/proposals/Proposal - Enhanced Input Events.md index 0b2dd4b508..15ff0eee8c 100644 --- a/documentation/proposals/Proposal - Enhanced Input Events.md +++ b/documentation/proposals/Proposal - Enhanced Input Events.md @@ -18,31 +18,6 @@ The only API changes will be to the events presented by IMouse, IKeyboard and po ## Enums -#### KeyAction -```cs -/// -/// Defines actions for keyboard keys. -/// -public enum KeyAction -{ - Pressed, - Repeat, - Released -} -``` - -#### ButtonAction -```cs -/// -/// Defines actions for mouse buttons. -/// -public enum ButtonAction -{ - Pressed, - Released -} -``` - #### KeyModifiers Based on [the modifier keys flag from GLFW](https://www.glfw.org/docs/latest/group__mods.html). ```cs @@ -60,14 +35,25 @@ public enum KeyModifiers ## Structs -#### KeyEvent +#### KeyDownEvent ```cs -public readonly struct KeyEvent +public readonly struct KeyDownEvent +{ + public IKeyboard Keyboard { get; } + public Key Key { get; } + public int KeyCode { get; } + public KeyModifiers Modifiers { get; } + public boolean IsRepeat { get; } +} +``` + +#### KeyUpEvent +```cs +public readonly struct KeyUpEvent { public IKeyboard Keyboard { get; } public Key Key { get; } public int KeyCode { get; } - public KeyAction Action { get; } public KeyModifiers Modifiers { get; } } ``` @@ -78,6 +64,7 @@ public readonly struct KeyCharEvent { public IKeyboard Keyboard { get; } public char Character { get; } + public int KeyCode { get; } } ``` @@ -87,8 +74,7 @@ public readonly struct MouseMoveEvent { public IMouse Mouse { get; } public Vector2 Position { get; } - // We can also add to get the difference between Position and the Position in the last move mouse invocation: - // public Vector2 Delta { get; } + public Vector2 Delta { get; } } ``` @@ -99,7 +85,6 @@ public readonly struct MouseButtonEvent public IMouse Mouse { get; } public Vector2 Position { get; } public MouseButton Button { get; } - public ButtonAction Action { get; } public KeyModifiers Modifiers { get; } } ``` @@ -112,7 +97,7 @@ public readonly struct MouseScrollEvent public IMouse Mouse { get; } public Vector2 Position { get; } public Vector2 WheelPosition { get; } - // public Vector2 Delta { get; } + public Vector2 Delta { get; } } ``` @@ -138,8 +123,9 @@ public interface IKeyboard : IInputDevice // event Action KeyUp; // event Action KeyChar; - // Reports all key events, KeyAction.Press, KeyAction.Repeat and KeyAction.Release - event Action KeyAction; + // KeyDown reports key down and key repeats + event Action KeyDown; + event Action KeyUp; event Action KeyChar; } From 34d258dee66e66d690c206f5ad457d3f812986a7 Mon Sep 17 00:00:00 2001 From: ThomasMiz <32400648+ThomasMiz@users.noreply.github.com> Date: Fri, 16 Jul 2021 21:31:15 -0300 Subject: [PATCH 4/5] Added ctors - Enhanced Input Events.md --- .../Proposal - Enhanced Input Events.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/documentation/proposals/Proposal - Enhanced Input Events.md b/documentation/proposals/Proposal - Enhanced Input Events.md index 15ff0eee8c..6aa88cf423 100644 --- a/documentation/proposals/Proposal - Enhanced Input Events.md +++ b/documentation/proposals/Proposal - Enhanced Input Events.md @@ -43,7 +43,9 @@ public readonly struct KeyDownEvent public Key Key { get; } public int KeyCode { get; } public KeyModifiers Modifiers { get; } - public boolean IsRepeat { get; } + public bool IsRepeat { get; } + + public KeyDownEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers, bool isRepeat) } ``` @@ -55,6 +57,8 @@ public readonly struct KeyUpEvent public Key Key { get; } public int KeyCode { get; } public KeyModifiers Modifiers { get; } + + public KeyUpEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers) } ``` @@ -65,6 +69,8 @@ public readonly struct KeyCharEvent public IKeyboard Keyboard { get; } public char Character { get; } public int KeyCode { get; } + + public KeyCharEvent(IKeyboard keyboard, char character, int keyCode) } ``` @@ -75,6 +81,8 @@ public readonly struct MouseMoveEvent public IMouse Mouse { get; } public Vector2 Position { get; } public Vector2 Delta { get; } + + public MouseMoveEvent(IMouse mouse, Vector2 position, Vector2 delta) } ``` @@ -86,6 +94,8 @@ public readonly struct MouseButtonEvent public Vector2 Position { get; } public MouseButton Button { get; } public KeyModifiers Modifiers { get; } + + public MouseButtonEvent(IMouse mouse, Vector2 position, MouseButton button, KeyModifiers modifiers) } ``` @@ -98,6 +108,8 @@ public readonly struct MouseScrollEvent public Vector2 Position { get; } public Vector2 WheelPosition { get; } public Vector2 Delta { get; } + + public MouseScrollEvent(IMouse mouse, Vector2 position, Vector2 wheelPosition, Vector2 delta) } ``` @@ -108,7 +120,9 @@ public readonly struct MouseClickEvent public IMouse Mouse { get; } public Vector2 Position { get; } public MouseButton Button { get; } - public KeyModifier Modifiers { get; } + public KeyModifiers Modifiers { get; } + + public MouseClickEvent(IMouse mouse, Vector2 position, MouseButton button, KeyModifiers modifiers) } ``` From baa3518f7a34c86dc0805fae826d05e1511a03ab Mon Sep 17 00:00:00 2001 From: ThomasMiz <32400648+ThomasMiz@users.noreply.github.com> Date: Sat, 17 Jul 2021 10:37:34 -0300 Subject: [PATCH 5/5] Applied suggestions - Enhanced Input Events.md Co-authored-by: Dylan Perks <11160611+Perksey@users.noreply.github.com> --- .../Proposal - Enhanced Input Events.md | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/documentation/proposals/Proposal - Enhanced Input Events.md b/documentation/proposals/Proposal - Enhanced Input Events.md index 6aa88cf423..94c27e66c7 100644 --- a/documentation/proposals/Proposal - Enhanced Input Events.md +++ b/documentation/proposals/Proposal - Enhanced Input Events.md @@ -24,12 +24,12 @@ Based on [the modifier keys flag from GLFW](https://www.glfw.org/docs/latest/gro [Flags] public enum KeyModifiers { - Shift = 1 << 1, - Control = 1 << 2, - Alt = 1 << 3, - Super = 1 << 4, - CapsLock = 1 << 5, - NumLock = 1 << 6 + Shift = 1 << 0, + Control = 1 << 1, + Alt = 1 << 2, + Super = 1 << 3, + CapsLock = 1 << 4, + NumLock = 1 << 5 } ``` @@ -45,7 +45,7 @@ public readonly struct KeyDownEvent public KeyModifiers Modifiers { get; } public bool IsRepeat { get; } - public KeyDownEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers, bool isRepeat) + public KeyDownEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers, bool isRepeat); } ``` @@ -58,7 +58,7 @@ public readonly struct KeyUpEvent public int KeyCode { get; } public KeyModifiers Modifiers { get; } - public KeyUpEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers) + public KeyUpEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers); } ``` @@ -70,7 +70,7 @@ public readonly struct KeyCharEvent public char Character { get; } public int KeyCode { get; } - public KeyCharEvent(IKeyboard keyboard, char character, int keyCode) + public KeyCharEvent(IKeyboard keyboard, char character, int keyCode); } ``` @@ -82,7 +82,7 @@ public readonly struct MouseMoveEvent public Vector2 Position { get; } public Vector2 Delta { get; } - public MouseMoveEvent(IMouse mouse, Vector2 position, Vector2 delta) + public MouseMoveEvent(IMouse mouse, Vector2 position, Vector2 delta); } ``` @@ -95,12 +95,11 @@ public readonly struct MouseButtonEvent public MouseButton Button { get; } public KeyModifiers Modifiers { get; } - public MouseButtonEvent(IMouse mouse, Vector2 position, MouseButton button, KeyModifiers modifiers) + public MouseButtonEvent(IMouse mouse, Vector2 position, MouseButton button, KeyModifiers modifiers); } ``` #### MouseScrollEvent -This would replace the current ScrollWheel struct. ```cs public readonly struct MouseScrollEvent { @@ -109,7 +108,7 @@ public readonly struct MouseScrollEvent public Vector2 WheelPosition { get; } public Vector2 Delta { get; } - public MouseScrollEvent(IMouse mouse, Vector2 position, Vector2 wheelPosition, Vector2 delta) + public MouseScrollEvent(IMouse mouse, Vector2 position, Vector2 wheelPosition, Vector2 delta); } ```