From 5ae012e6e91ebd1a3aa04160ff9274230bafc5d6 Mon Sep 17 00:00:00 2001 From: RedMser Date: Fri, 9 Sep 2022 17:19:30 +0200 Subject: Add documentation for viewport's input handling --- doc/classes/Control.xml | 4 ++-- doc/classes/Node.xml | 3 ++- doc/classes/Viewport.xml | 22 ++++++++++++++++++++++ doc/classes/Window.xml | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index c66a93ce37..9c7cb7b089 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -7,8 +7,8 @@ Base class for all UI-related nodes. [Control] features a bounding rectangle that defines its extents, an anchor position relative to its parent control or the current viewport, and offsets relative to the anchor. The offsets update automatically when the node, any of its parents, or the screen size change. For more information on Godot's UI system, anchors, offsets, and containers, see the related tutorials in the manual. To build flexible UIs, you'll need a mix of UI elements that inherit from [Control] and [Container] nodes. [b]User Interface nodes and input[/b] - Godot sends input events to the scene's root node first, by calling [method Node._input]. [method Node._input] forwards the event down the node tree to the nodes under the mouse cursor, or in focus. To do so, it calls [code]MainLoop._input_event[/code]. - [b]FIXME:[/b] No longer valid after DisplayServer split and Input refactoring. + Godot propagates input events via viewports. Each [Viewport] is responsible for propagating [InputEvent]s to their child nodes. As the [member SceneTree.root] is a [Window], this already happens automatically for all UI elements in your game. + Input events are propagated through the [SceneTree] from the root node to all child nodes by calling [method Node._input]. For UI elements specifically, it makes more sense to override the virtual method [method _gui_input], which filters out unrelated input events, such as by checking z-order, [member mouse_filter], focus, or if the event was inside of the control's bounding box. Call [method accept_event] so no other node receives the event. Once you accept an input, it becomes handled so [method Node._unhandled_input] will not process it. Only one [Control] node can be in focus. Only the node in focus will receive events. To get the focus, call [method grab_focus]. [Control] nodes lose focus when another node grabs it, or if you hide the node in focus. Sets [member mouse_filter] to [constant MOUSE_FILTER_IGNORE] to tell a [Control] node to ignore mouse or touch events. You'll need it if you place an icon on top of a button. diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 6ba7deba15..bceb285584 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -110,11 +110,12 @@ - Called when an [InputEventKey] or [InputEventShortcut] hasn't been consumed by [method _input] or any GUI [Control] item. The input event propagates up through the node tree until a node consumes it. + Called when an [InputEventKey] hasn't been consumed by [method _input] or any GUI [Control] item. The input event propagates up through the node tree until a node consumes it. It is only called if unhandled key input processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_unhandled_key_input]. To consume the input event and stop it propagating further to other nodes, [method Viewport.set_input_as_handled] can be called. This method can be used to handle Unicode character input with [kbd]Alt[/kbd], [kbd]Alt + Ctrl[/kbd], and [kbd]Alt + Shift[/kbd] modifiers, after shortcuts were handled. For gameplay input, this and [method _unhandled_input] are usually a better fit than [method _input] as they allow the GUI to intercept the events first. + This method also performs better than [method _unhandled_input], since unrelated events such as [InputEventMouseMotion] are automatically filtered. [b]Note:[/b] This method is only called if the node is present in the scene tree (i.e. if it's not an orphan). diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 87ee26fa32..998e782975 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -129,6 +129,9 @@ + Returns whether the current [InputEvent] has been handled. Input events are not handled until [method set_input_as_handled] has been called during the lifetime of an [InputEvent]. + This is usually done as part of input handling methods like [method Node._input], [method Control._gui_input] or others, as well as in corresponding signal handlers. + If [member handle_input_locally] is set to [code]false[/code], this method will try finding the first parent viewport that is set to handle input locally, and return its value for [method is_input_handled] instead. @@ -136,6 +139,13 @@ + Triggers the given [param event] in this [Viewport]. This can be used to pass an [InputEvent] between viewports, or to locally apply inputs that were sent over the network or saved to a file. + If [param in_local_coords] is [code]false[/code], the event's position is in the embedder's coordinates and will be converted to viewport coordinates. If [param in_local_coords] is [code]true[/code], the event's position is in viewport coordinates. + While this method serves a similar purpose as [method Input.parse_input_event], it does not remap the specified [param event] based on project settings like [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse]. + Calling this method will propagate calls to child nodes for following methods in the given order: + - [method Node._input] + - [method Control._gui_input] for [Control] nodes + If an earlier method marks the input as handled via [method set_input_as_handled], any later method in this list will not be called. @@ -149,6 +159,15 @@ + Triggers the given [InputEvent] in this [Viewport]. This can be used to pass input events between viewports, or to locally apply inputs that were sent over the network or saved to a file. + If [param in_local_coords] is [code]false[/code], the event's position is in the embedder's coordinates and will be converted to viewport coordinates. If [param in_local_coords] is [code]true[/code], the event's position is in viewport coordinates. + While this method serves a similar purpose as [method Input.parse_input_event], it does not remap the specified [param event] based on project settings like [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse]. + Calling this method will propagate calls to child nodes for following methods in the given order: + - [method Node._shortcut_input] + - [method Node._unhandled_input] + - [method Node._unhandled_key_input] + If an earlier method marks the input as handled via [method set_input_as_handled], any later method in this list will not be called. + If none of the methods handle the event and [member physics_object_picking] is [code]true[/code], the event is used for physics object picking. @@ -212,6 +231,9 @@ If [code]true[/code], the GUI controls on the viewport will lay pixel perfectly. + If [code]true[/code], this viewport will mark incoming input events as handled by itself. If [code]false[/code], this is instead done by the the first parent viewport that is set to handle input locally. + A [SubViewportContainer] will automatically set this property to [code]false[/code] for the [Viewport] contained inside of it. + See also [method set_input_as_handled] and [method is_input_handled]. The automatic LOD bias to use for meshes rendered within the [Viewport] (this is analogous to [member ReflectionProbe.mesh_lod_threshold]). Higher values will use less detailed versions of meshes that have LOD variations generated. If set to [code]0.0[/code], automatic LOD is disabled. Increase [member mesh_lod_threshold] to improve performance at the cost of geometry detail. diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index a688fb36b3..c278f7031f 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -469,7 +469,7 @@ - Emitted when the [Window] is currently focused and receives any input, passing the received event as an argument. + Emitted when the [Window] is currently focused and receives any input, passing the received event as an argument. The event's position, if present, is in the embedder's coordinate system. -- cgit v1.2.3