From 5ccbdcd759c4a2c1074405652d81accc36b1e7e1 Mon Sep 17 00:00:00 2001 From: aXu-AP <1621768+aXu-AP@users.noreply.github.com> Date: Sun, 8 Sep 2024 21:05:49 +0300 Subject: [PATCH] Fix tooltip appearing in old place, on movement Fixes tooltip appearing in editor on old position of mouse. Fixes tooltip appearing even if mouse is in steady motion (now accepts max 5 px movement). --- scene/main/viewport.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0cdb23618f85..139ccbc4685b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1933,19 +1933,18 @@ void Viewport::_gui_input_event(Ref p_event) { // If the tooltip timer isn't running, start it. // Otherwise, only reset the timer if the mouse has moved more than 5 pixels. - if (!is_tooltip_shown && over->can_process() && - (gui.tooltip_timer.is_null() || - Math::is_zero_approx(gui.tooltip_timer->get_time_left()) || - mm->get_relative().length() > 5.0)) { - if (gui.tooltip_timer.is_valid()) { - gui.tooltip_timer->release_connections(); - gui.tooltip_timer = Ref(); + if (!is_tooltip_shown && over->can_process()) { + Vector2 new_tooltip_pos = over->get_screen_transform().xform(pos); + if (gui.tooltip_pos.distance_squared_to(new_tooltip_pos) > 25 || over != gui.tooltip_control) { + if (gui.tooltip_timer.is_valid()) { + gui.tooltip_timer->release_connections(); + } + gui.tooltip_control = over; + gui.tooltip_pos = new_tooltip_pos; + gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay); + gui.tooltip_timer->set_ignore_time_scale(true); + gui.tooltip_timer->connect("timeout", callable_mp(this, &Viewport::_gui_show_tooltip)); } - gui.tooltip_control = over; - gui.tooltip_pos = over->get_screen_transform().xform(pos); - gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay); - gui.tooltip_timer->set_ignore_time_scale(true); - gui.tooltip_timer->connect("timeout", callable_mp(this, &Viewport::_gui_show_tooltip)); } }