From 62fa80afd7734c40aef4148d71a43cd6c52e26ab Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Sun, 13 Mar 2022 23:54:13 +0100 Subject: [PATCH] Cleanup internal GUI state, if event is accepted in _input. --- scene/main/viewport.cpp | 13 +++++++++++++ scene/main/viewport.h | 1 + 2 files changed, 14 insertions(+) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 25c3ced3da6..1c1a479b0bd 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2496,6 +2496,17 @@ void Viewport::_gui_input_event(Ref p_event) { } } +void Viewport::_gui_cleanup_internal_state(Ref p_event) { + ERR_FAIL_COND(p_event.is_null()); + + Ref mb = p_event; + if (mb.is_valid()) { + if (!mb->is_pressed()) { + gui.mouse_focus_mask &= ~(1 << (mb->get_button_index() - 1)); // Remove from mask. + } + } +} + List::Element *Viewport::_gui_add_root_control(Control *p_control) { gui.roots_order_dirty = true; return gui.roots.push_back(p_control); @@ -2851,6 +2862,8 @@ void Viewport::input(const Ref &p_event) { if (!is_input_handled()) { _gui_input_event(p_event); + } else { + _gui_cleanup_internal_state(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 } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index c7ef4834d83..a4d22805981 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -340,6 +340,7 @@ private: Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform); void _gui_input_event(Ref p_event); + void _gui_cleanup_internal_state(Ref p_event); void update_worlds();