From 5086101bad1238e0b02bc885cd297bd7b9b69f65 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 4 Mar 2023 23:41:25 +0100 Subject: [PATCH] Allow setting ExternalGestureHandling through the InputHandler constructor --- CHANGELOG.md | 1 + Docs/articles/input.md | 6 +++--- MLEM/Input/InputHandler.cs | 14 ++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e997ef3..6ead0e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Docs/articles/input.md b/Docs/articles/input.md index f2d0ae5..f465807 100644 --- a/Docs/articles/input.md +++ b/Docs/articles/input.md @@ -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. diff --git a/MLEM/Input/InputHandler.cs b/MLEM/Input/InputHandler.cs index 6bd26ca..5729513 100644 --- a/MLEM/Input/InputHandler.cs +++ b/MLEM/Input/InputHandler.cs @@ -193,16 +193,18 @@ namespace MLEM.Input { /// /// Creates a new input handler with optional initial values. /// - /// The game instance that this input handler belongs to - /// If keyboard input should be handled - /// If mouse input should be handled - /// If gamepad input should be handled - /// If touch input should be handled - public InputHandler(Game game, bool handleKeyboard = true, bool handleMouse = true, bool handleGamepads = true, bool handleTouch = true) : base(game) { + /// The game instance that this input handler belongs to. + /// The initial value for , which determines whether this input handler handles keyboard inputs. + /// The initial value for , which determines whether this input handler handles mouse inputs. + /// The initial value for , which determines whether this input handler handles gamepad inputs. + /// The initial value for , which determines whether this input handler handles touch inputs. + /// The initial value for , which determines whether gestures will be supplied using (or this input handler should handle gestures itself). + 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(); }