-
-
Notifications
You must be signed in to change notification settings - Fork 441
Enhanced Input Events #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a57a7a
Created Propostal - Enhanced Input Events.md
ThomasMiz 9fa2a1d
Update Proposal - Enhanced Input Events.md
ThomasMiz 1c4712c
Update Proposal - Enhanced Input Events.md
ThomasMiz 34d258d
Added ctors - Enhanced Input Events.md
ThomasMiz baa3518
Applied suggestions - Enhanced Input Events.md
ThomasMiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
documentation/proposals/Proposal - Enhanced Input Events.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| /// <summary> | ||
| /// Defines actions for keyboard keys. | ||
| /// </summary> | ||
| public enum KeyAction | ||
| { | ||
| Press, | ||
| Repeat, | ||
| Release | ||
| } | ||
| ``` | ||
|
|
||
| #### ButtonAction | ||
| ```cs | ||
| /// <summary> | ||
| /// Defines actions for mouse buttons. | ||
| /// </summary> | ||
| 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 | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
Perksey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
ThomasMiz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```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<IKeyboard, Key> KeyDown; | ||
| // event Action<IKeyboard, Key> KeyUp; | ||
| // event Action<IKeyboard, char> KeyChar; | ||
|
|
||
| event Action<KeyEventArgs> KeyDown; | ||
| event Action<KeyEventArgs> KeyUp; | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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<CharacterTypedEventArgs> CharacterTyped; | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
|
|
||
| #### IMouse | ||
| ```cs | ||
| public interface IMouse : IInputDevice | ||
| { | ||
| // event Action<IMouse, Vector2> MouseMove; | ||
| // event Action<IMouse, MouseButton> MouseDown; | ||
| // event Action<IMouse, MouseButton> MouseUp; | ||
| // event Action<IMouse, ScrollWheel> Scroll; | ||
| // event Action<IMouse, MouseButton, Vector2> Click; | ||
| // event Action<IMouse, MouseButton, Vector2> DoubleClick; | ||
|
|
||
| event Action<MouseMoveEventArgs> MouseMove; | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| event Action<MouseButtonEventArgs> MouseDown; | ||
| event Action<MouseButtonEventArgs> MouseUp; | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| event Action<MouseScrollEventArgs> Scroll; | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| event Action<MouseButtonEventArgs> Click; | ||
| event Action<MouseButtonEventArgs> DoubleClick; | ||
Perksey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
|
|
||
| These changes can also be applied to other IDevices to keep consistency across our API. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.