Merge pull request #85966 from Kimau/claire/expose_mouseover

Expose a method to get hovered Control in Viewport
This commit is contained in:
Yuri Sizov 2023-12-18 18:17:57 +01:00
commit a4d789370f
3 changed files with 14 additions and 0 deletions

View File

@ -128,6 +128,13 @@
Returns the [Control] having the focus within this viewport. If no [Control] has the focus, returns null. Returns the [Control] having the focus within this viewport. If no [Control] has the focus, returns null.
</description> </description>
</method> </method>
<method name="gui_get_hovered_control" qualifiers="const">
<return type="Control" />
<description>
Returns the [Control] that the mouse is currently hovering over in this viewport. If no [Control] has the cursor, returns null.
Typically the leaf [Control] node or deepest level of the subtree which claims hover. This is very useful when used together with [method Node.is_ancestor_of] to find if the mouse is within a control tree.
</description>
</method>
<method name="gui_is_drag_successful" qualifiers="const"> <method name="gui_is_drag_successful" qualifiers="const">
<return type="bool" /> <return type="bool" />
<description> <description>

View File

@ -3518,6 +3518,11 @@ Control *Viewport::gui_get_focus_owner() const {
return gui.key_focus; return gui.key_focus;
} }
Control *Viewport::gui_get_hovered_control() const {
ERR_READ_THREAD_GUARD_V(nullptr);
return gui.mouse_over;
}
void Viewport::set_msaa_2d(MSAA p_msaa) { void Viewport::set_msaa_2d(MSAA p_msaa) {
ERR_MAIN_THREAD_GUARD; ERR_MAIN_THREAD_GUARD;
ERR_FAIL_INDEX(p_msaa, MSAA_MAX); ERR_FAIL_INDEX(p_msaa, MSAA_MAX);
@ -4557,6 +4562,7 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("gui_release_focus"), &Viewport::gui_release_focus); ClassDB::bind_method(D_METHOD("gui_release_focus"), &Viewport::gui_release_focus);
ClassDB::bind_method(D_METHOD("gui_get_focus_owner"), &Viewport::gui_get_focus_owner); ClassDB::bind_method(D_METHOD("gui_get_focus_owner"), &Viewport::gui_get_focus_owner);
ClassDB::bind_method(D_METHOD("gui_get_hovered_control"), &Viewport::gui_get_hovered_control);
ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input); ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled); ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);

View File

@ -610,6 +610,7 @@ public:
void gui_release_focus(); void gui_release_focus();
Control *gui_get_focus_owner() const; Control *gui_get_focus_owner() const;
Control *gui_get_hovered_control() const;
PackedStringArray get_configuration_warnings() const override; PackedStringArray get_configuration_warnings() const override;