Merge pull request #86304 from OverloadedOrama/fix-menubar-scaling
Fix `MenuBar` and `MenuButton` hover position scaling properly with the scale factor multiplier
This commit is contained in:
commit
23275074cb
4 changed files with 4 additions and 43 deletions
|
@ -181,26 +181,9 @@ void MenuBar::_popup_visibility_changed(bool p_visible) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_on_hover) {
|
if (switch_on_hover) {
|
||||||
Window *wnd = Object::cast_to<Window>(get_viewport());
|
|
||||||
if (wnd) {
|
|
||||||
mouse_pos_adjusted = wnd->get_position();
|
|
||||||
|
|
||||||
if (wnd->is_embedded()) {
|
|
||||||
Window *wnd_parent = Object::cast_to<Window>(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<Window>(wnd_parent->get_parent()->get_viewport());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool MenuBar::is_native_menu() const {
|
bool MenuBar::is_native_menu() const {
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
@ -338,8 +321,7 @@ void MenuBar::_notification(int p_what) {
|
||||||
// Handled by OS.
|
// Handled by OS.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Vector2 pos = get_local_mouse_position();
|
||||||
Vector2 pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted - get_global_position();
|
|
||||||
if (pos == old_mouse_pos) {
|
if (pos == old_mouse_pos) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,6 @@ class MenuBar : public Control {
|
||||||
int selected_menu = -1;
|
int selected_menu = -1;
|
||||||
int active_menu = -1;
|
int active_menu = -1;
|
||||||
|
|
||||||
Vector2i mouse_pos_adjusted;
|
|
||||||
Vector2i old_mouse_pos;
|
Vector2i old_mouse_pos;
|
||||||
ObjectID shortcut_context;
|
ObjectID shortcut_context;
|
||||||
|
|
||||||
|
|
|
@ -57,26 +57,9 @@ void MenuButton::_popup_visibility_changed(bool p_visible) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_on_hover) {
|
if (switch_on_hover) {
|
||||||
Window *wnd = Object::cast_to<Window>(get_viewport());
|
|
||||||
if (wnd) {
|
|
||||||
mouse_pos_adjusted = wnd->get_position();
|
|
||||||
|
|
||||||
if (wnd->is_embedded()) {
|
|
||||||
Window *wnd_parent = Object::cast_to<Window>(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<Window>(wnd_parent->get_parent()->get_viewport());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void MenuButton::pressed() {
|
void MenuButton::pressed() {
|
||||||
if (popup->is_visible()) {
|
if (popup->is_visible()) {
|
||||||
|
@ -155,8 +138,7 @@ void MenuButton::_notification(int p_what) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||||
Vector2i mouse_pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
|
MenuButton *menu_btn_other = Object::cast_to<MenuButton>(get_viewport()->gui_find_control(get_viewport()->get_mouse_position()));
|
||||||
MenuButton *menu_btn_other = Object::cast_to<MenuButton>(get_viewport()->gui_find_control(mouse_pos));
|
|
||||||
|
|
||||||
if (menu_btn_other && menu_btn_other != this && menu_btn_other->is_switch_on_hover() && !menu_btn_other->is_disabled() &&
|
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))) {
|
(get_parent()->is_ancestor_of(menu_btn_other) || menu_btn_other->get_parent()->is_ancestor_of(popup))) {
|
||||||
|
|
|
@ -42,8 +42,6 @@ class MenuButton : public Button {
|
||||||
bool disable_shortcuts = false;
|
bool disable_shortcuts = false;
|
||||||
PopupMenu *popup = nullptr;
|
PopupMenu *popup = nullptr;
|
||||||
|
|
||||||
Vector2i mouse_pos_adjusted;
|
|
||||||
|
|
||||||
void _popup_visibility_changed(bool p_visible);
|
void _popup_visibility_changed(bool p_visible);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Reference in a new issue