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

Proposal for SubViewportContainer input handling #57687

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
49 changes: 26 additions & 23 deletions scene/gui/subviewport_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,46 @@ void SubViewportContainer::_notification(int p_what) {
}
}
}
}

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

if (Engine::get_singleton()->is_editor_hint()) {
return;
if (p_what == NOTIFICATION_MOUSE_ENTER) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
if (!c) {
continue;
}
c->notification(NOTIFICATION_WM_MOUSE_ENTER);
}
}

Transform2D xform = get_global_transform();

if (stretch) {
Transform2D scale_xf;
scale_xf.scale(Vector2(shrink, shrink));
xform *= scale_xf;
if (p_what == NOTIFICATION_MOUSE_EXIT) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
if (!c) {
continue;
}
c->notification(NOTIFICATION_WM_MOUSE_EXIT);
}
}

Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());

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

c->push_input(ev);
}
}

void SubViewportContainer::unhandled_input(const Ref<InputEvent> &p_event) {
void SubViewportContainer::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();
Transform2D xform = get_viewport()->get_global_canvas_transform();

if (stretch) {
Transform2D scale_xf;
Expand All @@ -190,7 +193,7 @@ void SubViewportContainer::unhandled_input(const Ref<InputEvent> &p_event) {
continue;
}

c->push_unhandled_input(ev);
c->push_input(ev);
}
}

Expand Down
3 changes: 1 addition & 2 deletions scene/gui/subviewport_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ class SubViewportContainer : public Container {
protected:
void _notification(int p_what);
static void _bind_methods();
virtual void gui_input(const Ref<InputEvent> &p_event) override;

public:
void set_stretch(bool p_enable);
bool is_stretch_enabled() const;

virtual void input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void set_stretch_shrink(int p_shrink);
int get_stretch_shrink() const;

Expand Down
12 changes: 10 additions & 2 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) {
}

Control *Viewport::gui_find_control(const Point2 &p_global) {
// Handle subwindows.
// Handle child Control nodes.
_gui_sort_roots();

for (List<Control *>::Element *E = gui.roots.back(); E; E = E->prev()) {
Expand Down Expand Up @@ -2155,7 +2155,7 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
// No need for change.
return;
}
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window());
gui_release_focus();
gui.key_focus = p_control;
emit_signal(SNAME("gui_focus_changed"), p_control);
p_control->notification(Control::NOTIFICATION_FOCUS_ENTER);
Expand Down Expand Up @@ -2687,6 +2687,10 @@ void Viewport::push_input(const Ref<InputEvent> &p_event, bool p_local_coords) {
_gui_input_event(ev);
}

if (!is_input_handled()) {
push_unhandled_input(p_event, p_local_coords);
}

event_count++;
}

Expand Down Expand Up @@ -2728,6 +2732,7 @@ void Viewport::push_unhandled_input(const Ref<InputEvent> &p_event, bool p_local

)) {
physics_picking_events.push_back(ev);
_set_input_as_handled_keep_physics();
}
}
}
Expand Down Expand Up @@ -2910,7 +2915,10 @@ bool Viewport::gui_is_drag_successful() const {

void Viewport::set_input_as_handled() {
_drop_physics_mouseover();
_set_input_as_handled_keep_physics();
}

void Viewport::_set_input_as_handled_keep_physics() {
if (!handle_input_locally) {
ERR_FAIL_COND(!is_inside_tree());
Viewport *vp = this;
Expand Down
2 changes: 2 additions & 0 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ class Viewport : public Node {
virtual bool _can_consume_input_events() const { return true; }
uint64_t event_count = 0;

void _set_input_as_handled_keep_physics();

protected:
void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated);

Expand Down
3 changes: 0 additions & 3 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,6 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) {
emit_signal(SceneStringNames::get_singleton()->window_input, p_ev);

push_input(p_ev);
if (!is_input_handled()) {
push_unhandled_input(p_ev);
}
}

void Window::_window_input_text(const String &p_text) {
Expand Down