Skip to content

Commit d6d2c4a

Browse files
committed
Control::accept_event Changed and Move to Node
1 parent 48403b5 commit d6d2c4a

File tree

11 files changed

+74
-26
lines changed

11 files changed

+74
-26
lines changed

doc/classes/Control.xml

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[b]User Interface nodes and input[/b]
1010
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.
1111
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.
12-
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.
12+
Call [method Node.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.
1313
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.
1414
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.
1515
[Theme] resources change the Control's appearance. If you change the [Theme] on a [Control] node, it affects all of its children. To override some of the theme's parameters, call one of the [code]add_theme_*_override[/code] methods, like [method add_theme_font_override]. You can override the theme with the Inspector.
@@ -120,7 +120,7 @@
120120
<return type="void" />
121121
<param index="0" name="event" type="InputEvent" />
122122
<description>
123-
Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See [method accept_event].
123+
Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See [method Node.accept_event].
124124
[b]Example usage for clicking a control:[/b]
125125
[codeblocks]
126126
[gdscript]
@@ -214,13 +214,6 @@
214214
Returns an [Array] of [Vector3i] text ranges and text base directions, in the left-to-right order. Ranges should cover full source [param text] without overlaps. BiDi algorithm will be used on each range separately.
215215
</description>
216216
</method>
217-
<method name="accept_event">
218-
<return type="void" />
219-
<description>
220-
Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening to [method Node._unhandled_input] or [method Node._unhandled_key_input].
221-
[b]Note:[/b] This does not affect the methods in [Input], only the way events are propagated.
222-
</description>
223-
</method>
224217
<method name="add_theme_color_override">
225218
<return type="void" />
226219
<param index="0" name="name" type="StringName" />

doc/classes/Input.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</brief_description>
66
<description>
77
The [Input] singleton handles key presses, mouse buttons and movement, gamepads, and input actions. Actions and their events can be set in the [b]Input Map[/b] tab in [b]Project &gt; Project Settings[/b], or with the [InputMap] class.
8-
[b]Note:[/b] [Input]'s methods reflect the global input state and are not affected by [method Control.accept_event] or [method Viewport.set_input_as_handled], as those methods only deal with the way input is propagated in the [SceneTree].
8+
[b]Note:[/b] [Input]'s methods reflect the global input state and are not affected by [method Node.accept_event] or [method Viewport.set_input_as_handled], as those methods only deal with the way input is propagated in the [SceneTree].
99
</description>
1010
<tutorials>
1111
<link title="Inputs documentation index">$DOCS_URL/tutorials/inputs/index.html</link>

doc/classes/Node.xml

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@
130130
[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).
131131
</description>
132132
</method>
133+
<method name="accept_event">
134+
<return type="void" />
135+
<description>
136+
Stops the input from propagating further down the [SceneTree].
137+
[b]Note:[/b] This does not affect the methods in [Input], only the way events are propagated.
138+
</description>
139+
</method>
133140
<method name="add_child">
134141
<return type="void" />
135142
<param index="0" name="node" type="Node" />

misc/extension_api_validation/4.3-stable.expected

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ Validate extension JSON: Error: Field 'classes/OS/methods/execute_with_pipe/argu
8282
Optional argument added. Compatibility method registered.
8383

8484

85+
GH-96989
86+
--------
87+
Validate extension JSON: API was removed: classes/Control/methods/accept_event
88+
89+
Method moved to Node. Compatibility method registered.
90+
91+
8592
GH-94684
8693
--------
8794
Validate extension JSON: Error: Field 'classes/SoftBody3D/methods/set_point_pinned/arguments': size changed value in new API, from 3 to 4.

scene/gui/control.compat.inc

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**************************************************************************/
2+
/* control.compat.inc */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#ifndef DISABLE_DEPRECATED
32+
33+
void Control::_accept_event_bind_compat_96989() {
34+
accept_event();
35+
}
36+
37+
void Control::_bind_compatibility_methods() {
38+
ClassDB::bind_compatibility_method(D_METHOD("accept_event"), &Control::_accept_event_bind_compat_96989);
39+
}
40+
41+
#endif

scene/gui/control.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/**************************************************************************/
3030

3131
#include "control.h"
32+
#include "control.compat.inc"
3233

3334
#include "container.h"
3435
#include "core/config/project_settings.h"
@@ -1830,13 +1831,6 @@ void Control::_call_gui_input(const Ref<InputEvent> &p_event) {
18301831
void Control::gui_input(const Ref<InputEvent> &p_event) {
18311832
}
18321833

1833-
void Control::accept_event() {
1834-
ERR_MAIN_THREAD_GUARD;
1835-
if (is_inside_tree()) {
1836-
get_viewport()->_gui_accept_event();
1837-
}
1838-
}
1839-
18401834
bool Control::has_point(const Point2 &p_point) const {
18411835
ERR_READ_THREAD_GUARD_V(false);
18421836
bool ret;
@@ -3389,7 +3383,6 @@ void Control::_notification(int p_notification) {
33893383
}
33903384

33913385
void Control::_bind_methods() {
3392-
ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event);
33933386
ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size);
33943387
ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);
33953388

scene/gui/control.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ class Control : public CanvasItem {
348348
void _notification(int p_notification);
349349
static void _bind_methods();
350350

351+
#ifndef DISABLE_DEPRECATED
352+
void _accept_event_bind_compat_96989();
353+
static void _bind_compatibility_methods();
354+
#endif
355+
351356
// Exposed virtual methods.
352357

353358
GDVIRTUAL1RC(bool, _has_point, Vector2)
@@ -501,7 +506,6 @@ class Control : public CanvasItem {
501506
// Input events.
502507

503508
virtual void gui_input(const Ref<InputEvent> &p_event);
504-
void accept_event();
505509

506510
virtual bool has_point(const Point2 &p_point) const;
507511

scene/main/node.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3427,6 +3427,13 @@ void Node::unhandled_input(const Ref<InputEvent> &p_event) {
34273427
void Node::unhandled_key_input(const Ref<InputEvent> &p_key_event) {
34283428
}
34293429

3430+
void Node::accept_event() {
3431+
ERR_MAIN_THREAD_GUARD;
3432+
if (is_inside_tree() && get_viewport()->is_inside_tree()) {
3433+
get_viewport()->set_input_as_handled();
3434+
}
3435+
}
3436+
34303437
Variant Node::_call_deferred_thread_group_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
34313438
if (p_argcount < 1) {
34323439
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
@@ -3583,6 +3590,7 @@ void Node::_bind_methods() {
35833590
ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Node::set_process_mode);
35843591
ClassDB::bind_method(D_METHOD("get_process_mode"), &Node::get_process_mode);
35853592
ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process);
3593+
ClassDB::bind_method(D_METHOD("accept_event"), &Node::accept_event);
35863594

35873595
ClassDB::bind_method(D_METHOD("set_process_thread_group", "mode"), &Node::set_process_thread_group);
35883596
ClassDB::bind_method(D_METHOD("get_process_thread_group"), &Node::get_process_thread_group);

scene/main/node.h

+2
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ class Node : public Object {
664664
bool can_process() const;
665665
bool can_process_notification(int p_what) const;
666666

667+
void accept_event();
668+
667669
void set_physics_interpolation_mode(PhysicsInterpolationMode p_mode);
668670
PhysicsInterpolationMode get_physics_interpolation_mode() const { return data.physics_interpolation_mode; }
669671
_FORCE_INLINE_ bool is_physics_interpolated() const { return data.physics_interpolated; }

scene/main/viewport.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -2460,12 +2460,6 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
24602460
}
24612461
}
24622462

2463-
void Viewport::_gui_accept_event() {
2464-
if (is_inside_tree()) {
2465-
set_input_as_handled();
2466-
}
2467-
}
2468-
24692463
void Viewport::_drop_mouse_focus() {
24702464
Control *c = gui.mouse_focus;
24712465
BitField<MouseButtonMask> mask = gui.mouse_focus_mask;

scene/main/viewport.h

-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ class Viewport : public Node {
439439
void _gui_control_grab_focus(Control *p_control);
440440
void _gui_grab_click_focus(Control *p_control);
441441
void _post_gui_grab_click_focus();
442-
void _gui_accept_event();
443442

444443
bool _gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check);
445444

0 commit comments

Comments
 (0)