From e864b26e540a0de18ffa4e48ee87091f94db62fa Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Mon, 18 Dec 2023 18:07:34 +0200 Subject: [PATCH] Fix `MenuBar` hover position scaling properly with the scale factor multiplier --- scene/gui/menu_bar.cpp | 22 ++-------------------- scene/gui/menu_bar.h | 1 - scene/gui/menu_button.cpp | 22 ++-------------------- scene/gui/menu_button.h | 2 -- 4 files changed, 4 insertions(+), 43 deletions(-) diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp index 7418ba73334..5112cdcfe2a 100644 --- a/scene/gui/menu_bar.cpp +++ b/scene/gui/menu_bar.cpp @@ -181,24 +181,7 @@ void MenuBar::_popup_visibility_changed(bool p_visible) { } if (switch_on_hover) { - Window *wnd = Object::cast_to(get_viewport()); - if (wnd) { - mouse_pos_adjusted = wnd->get_position(); - - if (wnd->is_embedded()) { - Window *wnd_parent = Object::cast_to(wnd->get_parent()->get_viewport()); - while (wnd_parent) { - if (!wnd_parent->is_embedded()) { - mouse_pos_adjusted += wnd_parent->get_position(); - break; - } - - wnd_parent = Object::cast_to(wnd_parent->get_parent()->get_viewport()); - } - } - - set_process_internal(true); - } + set_process_internal(true); } } @@ -334,8 +317,7 @@ void MenuBar::_notification(int p_what) { // Handled by OS. return; } - - Vector2 pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted - get_global_position(); + Vector2 pos = get_local_mouse_position(); if (pos == old_mouse_pos) { return; } diff --git a/scene/gui/menu_bar.h b/scene/gui/menu_bar.h index ba4df5f2294..8431ac958b5 100644 --- a/scene/gui/menu_bar.h +++ b/scene/gui/menu_bar.h @@ -71,7 +71,6 @@ class MenuBar : public Control { int selected_menu = -1; int active_menu = -1; - Vector2i mouse_pos_adjusted; Vector2i old_mouse_pos; ObjectID shortcut_context; diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 868383b1411..080b6873377 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -57,24 +57,7 @@ void MenuButton::_popup_visibility_changed(bool p_visible) { } if (switch_on_hover) { - Window *wnd = Object::cast_to(get_viewport()); - if (wnd) { - mouse_pos_adjusted = wnd->get_position(); - - if (wnd->is_embedded()) { - Window *wnd_parent = Object::cast_to(wnd->get_parent()->get_viewport()); - while (wnd_parent) { - if (!wnd_parent->is_embedded()) { - mouse_pos_adjusted += wnd_parent->get_position(); - break; - } - - wnd_parent = Object::cast_to(wnd_parent->get_parent()->get_viewport()); - } - } - - set_process_internal(true); - } + set_process_internal(true); } } @@ -155,8 +138,7 @@ void MenuButton::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PROCESS: { - Vector2i mouse_pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted; - MenuButton *menu_btn_other = Object::cast_to(get_viewport()->gui_find_control(mouse_pos)); + MenuButton *menu_btn_other = Object::cast_to(get_viewport()->gui_find_control(get_viewport()->get_mouse_position())); if (menu_btn_other && menu_btn_other != this && menu_btn_other->is_switch_on_hover() && !menu_btn_other->is_disabled() && (get_parent()->is_ancestor_of(menu_btn_other) || menu_btn_other->get_parent()->is_ancestor_of(popup))) { diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 95748a29f12..eea6b8e877c 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -42,8 +42,6 @@ class MenuButton : public Button { bool disable_shortcuts = false; PopupMenu *popup = nullptr; - Vector2i mouse_pos_adjusted; - void _popup_visibility_changed(bool p_visible); protected: