1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 17:59:24 +01:00

Allow setting ExternalGestureHandling through the InputHandler constructor

This commit is contained in:
Ell 2023-03-04 23:41:25 +01:00
parent 8a4dc11072
commit 5086101bad
3 changed files with 12 additions and 9 deletions

View file

@ -27,6 +27,7 @@ Fixes
Improvements
- Increased TextFormatter macro recursion limit to 64
- Allow changing the default values used by default TextFormatter codes
- Allow setting ExternalGestureHandling through the InputHandler constructor
Removals
- Marked GetDownTime, GetUpTime and GetTimeSincePress in Keybind and Combination as obsolete

View file

@ -34,7 +34,7 @@ Keyboard and gamepad repeat events can be enabled or disabled through the `Handl
When enabled, repeat events for *pressing* are automatically triggered. This means that calling `IsPressed` every update call would return `true` for a control that is being held down every `KeyRepeatRate` seconds after `KeyRepeatDelay` seconds have passed once.
## Gesture handling
MonoGame's default touch handling can be a bit wonky to deal with, so the input handler also provides a much better user experience for touch gesture input.
MonoGame's default touch handling is not very library-friendly, so the input handler also provides a much more streamlined user experience for touch gesture input.
To enable touch input, the gestures you want to use first have to be enabled:
```cs
@ -52,6 +52,6 @@ if (this.InputHandler.GetGesture(GestureType.Tap, out var sample)) {
```
### External gesture handling
If your game already handles gestures through some other means, you might notice that one of the gesture handling methods stops working correctly. This is due to the fact that MonoGame's gesture querying system only supports each gesture to be queried once before it is removed from the queue.
If your game already handles gestures through some other means, you might notice that one of the gesture handling methods stops working correctly. This is due to the fact that MonoGame's gesture querying system only supports each gesture being queried once before it is removed from the queue.
If you want to continue using your own gesture handling, but still allow the `InputHandler` to use gestures (for [MLEM.Ui](ui.md), for example), you can set `GesturesExternal` to true in your `InputHandler`. Then, you can use `AddExternalGesture` to make the input handler aware of a gesture for the duration of the update frame that you added it on.
If you want to continue using your own gesture handling, but still allow the `InputHandler` to use gestures (for [MLEM.Ui](ui.md), for example), you can set `ExternalGestureHandling` to true in your `InputHandler`. Then, you can use `AddExternalGesture` to make the input handler aware of a gesture for the duration of the update frame that you added it on.

View file

@ -193,16 +193,18 @@ namespace MLEM.Input {
/// <summary>
/// Creates a new input handler with optional initial values.
/// </summary>
/// <param name="game">The game instance that this input handler belongs to</param>
/// <param name="handleKeyboard">If keyboard input should be handled</param>
/// <param name="handleMouse">If mouse input should be handled</param>
/// <param name="handleGamepads">If gamepad input should be handled</param>
/// <param name="handleTouch">If touch input should be handled</param>
public InputHandler(Game game, bool handleKeyboard = true, bool handleMouse = true, bool handleGamepads = true, bool handleTouch = true) : base(game) {
/// <param name="game">The game instance that this input handler belongs to.</param>
/// <param name="handleKeyboard">The initial value for <see cref="HandleKeyboard"/>, which determines whether this input handler handles keyboard inputs.</param>
/// <param name="handleMouse">The initial value for <see cref="HandleMouse"/>, which determines whether this input handler handles mouse inputs.</param>
/// <param name="handleGamepads">The initial value for <see cref="HandleGamepads"/>, which determines whether this input handler handles gamepad inputs.</param>
/// <param name="handleTouch">The initial value for <see cref="HandleTouch"/>, which determines whether this input handler handles touch inputs.</param>
/// <param name="externalGestureHandling">The initial value for <see cref="ExternalGestureHandling"/>, which determines whether gestures will be supplied using <see cref="AddExternalGesture"/> (or this input handler should handle gestures itself).</param>
public InputHandler(Game game, bool handleKeyboard = true, bool handleMouse = true, bool handleGamepads = true, bool handleTouch = true, bool externalGestureHandling = false) : base(game) {
this.HandleKeyboard = handleKeyboard;
this.HandleMouse = handleMouse;
this.HandleGamepads = handleGamepads;
this.HandleTouch = handleTouch;
this.ExternalGestureHandling = externalGestureHandling;
this.Gestures = this.gestures.AsReadOnly();
}