Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewport gui input order for 3.x #55339

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/classes/Viewport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
Returns [code]true[/code] if there are visible modals on-screen.
</description>
</method>
<method name="gui_input">
<return type="void" />
<argument index="0" name="local_event" type="InputEvent" />
<description>
</description>
</method>
<method name="gui_is_dragging" qualifiers="const">
<return type="bool" />
<description>
Expand Down
28 changes: 28 additions & 0 deletions scene/gui/viewport_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,33 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
}
}

void ViewportContainer::_gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (Engine::get_singleton()->is_editor_hint()) {
return;
}

Transform2D xform = get_global_transform();

if (stretch) {
Transform2D scale_xf;
scale_xf.scale(Vector2(shrink, shrink));
xform *= scale_xf;
}

Ref<InputEvent> ev = p_event;

for (int i = 0; i < get_child_count(); i++) {
Viewport *c = Object::cast_to<Viewport>(get_child(i));
if (!c || c->is_input_disabled()) {
continue;
}

c->gui_input(ev);
}
}

void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Expand Down Expand Up @@ -195,6 +222,7 @@ void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {

void ViewportContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input);
ClassDB::bind_method(D_METHOD("_gui_input", "event"), &ViewportContainer::_gui_input);
ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input);
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
Expand Down
1 change: 1 addition & 0 deletions scene/gui/viewport_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ViewportContainer : public Container {
bool is_stretch_enabled() const;

void _input(const Ref<InputEvent> &p_event);
void _gui_input(const Ref<InputEvent> &p_event);
void _unhandled_input(const Ref<InputEvent> &p_event);
void set_stretch_shrink(int p_shrink);
int get_stretch_shrink() const;
Expand Down
13 changes: 11 additions & 2 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ void Viewport::_vp_input(const Ref<InputEvent> &p_ev) {

Ref<InputEvent> ev = _make_input_local(p_ev);
input(ev);
gui_input(ev);
}

void Viewport::_vp_unhandled_input(const Ref<InputEvent> &p_ev) {
Expand Down Expand Up @@ -2801,13 +2802,20 @@ void Viewport::input(const Ref<InputEvent> &p_event) {
local_input_handled = false;

if (!is_input_handled()) {
get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input
get_tree()->_call_input_pause(input_group, "_input", p_event);
}

//get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check
}

void Viewport::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(!is_inside_tree());

local_input_handled = false;

if (!is_input_handled()) {
_gui_input_event(p_event);
}
//get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check
}

void Viewport::unhandled_input(const Ref<InputEvent> &p_event) {
Expand Down Expand Up @@ -3178,6 +3186,7 @@ void Viewport::_bind_methods() {

ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid);
ClassDB::bind_method(D_METHOD("input", "local_event"), &Viewport::input);
ClassDB::bind_method(D_METHOD("gui_input", "local_event"), &Viewport::gui_input);
ClassDB::bind_method(D_METHOD("unhandled_input", "local_event"), &Viewport::unhandled_input);

ClassDB::bind_method(D_METHOD("update_worlds"), &Viewport::update_worlds);
Expand Down
1 change: 1 addition & 0 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ class Viewport : public Node {
bool is_using_own_world() const;

void input(const Ref<InputEvent> &p_event);
void gui_input(const Ref<InputEvent> &p_event);
void unhandled_input(const Ref<InputEvent> &p_event);

void set_disable_input(bool p_disable);
Expand Down