|
| 1 | +# Summary |
| 2 | +Proposal for adding important missing functionality to input, as well as other enhancements. |
| 3 | + |
| 4 | +# Contributors |
| 5 | +- ThomasMiz |
| 6 | + |
| 7 | +# Current Status |
| 8 | +- [x] Proposed |
| 9 | +- [x] Discussed with API Review Board (ARB) |
| 10 | +- [ ] Approved |
| 11 | +- [ ] Implemented |
| 12 | + |
| 13 | +# Design Decisions |
| 14 | +- 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. |
| 15 | + |
| 16 | +# Proposed API |
| 17 | +The only API changes will be to the events presented by IMouse, IKeyboard and possibly other device interfaces. |
| 18 | + |
| 19 | +## Enums |
| 20 | + |
| 21 | +#### KeyModifiers |
| 22 | +Based on [the modifier keys flag from GLFW](https://www.glfw.org/docs/latest/group__mods.html). |
| 23 | +```cs |
| 24 | +[Flags] |
| 25 | +public enum KeyModifiers |
| 26 | +{ |
| 27 | + Shift = 1 << 0, |
| 28 | + Control = 1 << 1, |
| 29 | + Alt = 1 << 2, |
| 30 | + Super = 1 << 3, |
| 31 | + CapsLock = 1 << 4, |
| 32 | + NumLock = 1 << 5 |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +## Structs |
| 37 | + |
| 38 | +#### KeyDownEvent |
| 39 | +```cs |
| 40 | +public readonly struct KeyDownEvent |
| 41 | +{ |
| 42 | + public IKeyboard Keyboard { get; } |
| 43 | + public Key Key { get; } |
| 44 | + public int KeyCode { get; } |
| 45 | + public KeyModifiers Modifiers { get; } |
| 46 | + public bool IsRepeat { get; } |
| 47 | + |
| 48 | + public KeyDownEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers, bool isRepeat); |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +#### KeyUpEvent |
| 53 | +```cs |
| 54 | +public readonly struct KeyUpEvent |
| 55 | +{ |
| 56 | + public IKeyboard Keyboard { get; } |
| 57 | + public Key Key { get; } |
| 58 | + public int KeyCode { get; } |
| 59 | + public KeyModifiers Modifiers { get; } |
| 60 | + |
| 61 | + public KeyUpEvent(IKeyboard keyboard, Key key, int keyCode, KeyModifiers modifiers); |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +#### KeyCharEvent |
| 66 | +```cs |
| 67 | +public readonly struct KeyCharEvent |
| 68 | +{ |
| 69 | + public IKeyboard Keyboard { get; } |
| 70 | + public char Character { get; } |
| 71 | + public int KeyCode { get; } |
| 72 | + |
| 73 | + public KeyCharEvent(IKeyboard keyboard, char character, int keyCode); |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +#### MouseMoveEvent |
| 78 | +```cs |
| 79 | +public readonly struct MouseMoveEvent |
| 80 | +{ |
| 81 | + public IMouse Mouse { get; } |
| 82 | + public Vector2 Position { get; } |
| 83 | + public Vector2 Delta { get; } |
| 84 | + |
| 85 | + public MouseMoveEvent(IMouse mouse, Vector2 position, Vector2 delta); |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +#### MouseButtonEvent |
| 90 | +```cs |
| 91 | +public readonly struct MouseButtonEvent |
| 92 | +{ |
| 93 | + public IMouse Mouse { get; } |
| 94 | + public Vector2 Position { get; } |
| 95 | + public MouseButton Button { get; } |
| 96 | + public KeyModifiers Modifiers { get; } |
| 97 | + |
| 98 | + public MouseButtonEvent(IMouse mouse, Vector2 position, MouseButton button, KeyModifiers modifiers); |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +#### MouseScrollEvent |
| 103 | +```cs |
| 104 | +public readonly struct MouseScrollEvent |
| 105 | +{ |
| 106 | + public IMouse Mouse { get; } |
| 107 | + public Vector2 Position { get; } |
| 108 | + public Vector2 WheelPosition { get; } |
| 109 | + public Vector2 Delta { get; } |
| 110 | + |
| 111 | + public MouseScrollEvent(IMouse mouse, Vector2 position, Vector2 wheelPosition, Vector2 delta); |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +#### MouseClickEvent |
| 116 | +```cs |
| 117 | +public readonly struct MouseClickEvent |
| 118 | +{ |
| 119 | + public IMouse Mouse { get; } |
| 120 | + public Vector2 Position { get; } |
| 121 | + public MouseButton Button { get; } |
| 122 | + public KeyModifiers Modifiers { get; } |
| 123 | + |
| 124 | + public MouseClickEvent(IMouse mouse, Vector2 position, MouseButton button, KeyModifiers modifiers) |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## Interface changes |
| 129 | + |
| 130 | +#### IKeyboard |
| 131 | +```cs |
| 132 | +public interface IKeyboard : IInputDevice |
| 133 | +{ |
| 134 | + // The old events get removed: |
| 135 | + // event Action<IKeyboard, Key> KeyDown; |
| 136 | + // event Action<IKeyboard, Key> KeyUp; |
| 137 | + // event Action<IKeyboard, char> KeyChar; |
| 138 | + |
| 139 | + // KeyDown reports key down and key repeats |
| 140 | + event Action<KeyDownEvent> KeyDown; |
| 141 | + event Action<KeyUpEvent> KeyUp; |
| 142 | + |
| 143 | + event Action<KeyCharEvent> KeyChar; |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +#### IMouse |
| 148 | +```cs |
| 149 | +public interface IMouse : IInputDevice |
| 150 | +{ |
| 151 | + // The old events get removed: |
| 152 | + // event Action<IMouse, Vector2> MouseMove; |
| 153 | + // event Action<IMouse, MouseButton> MouseDown; |
| 154 | + // event Action<IMouse, MouseButton> MouseUp; |
| 155 | + // event Action<IMouse, ScrollWheel> Scroll; |
| 156 | + // event Action<IMouse, MouseButton, Vector2> Click; |
| 157 | + // event Action<IMouse, MouseButton, Vector2> DoubleClick; |
| 158 | + |
| 159 | + event Action<MouseMoveEvent> MouseMove; |
| 160 | + event Action<MouseButtonEvent> MouseDown; |
| 161 | + event Action<MouseButtonEvent> MouseUp; |
| 162 | + event Action<MouseScrollEvent> Scroll; |
| 163 | + event Action<MouseClickEvent> Click; |
| 164 | + event Action<MouseClickEvent> DoubleClick; |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +These changes can also be applied to other IDevices to keep consistency across our API. |
0 commit comments