Opens the menu with the same parent on mouse focus
This commit is contained in:
parent
62f2a8aadb
commit
d1f5deabd8
@ -2972,7 +2972,6 @@ Control::Control() {
|
|||||||
data.SI = NULL;
|
data.SI = NULL;
|
||||||
data.MI = NULL;
|
data.MI = NULL;
|
||||||
data.RI = NULL;
|
data.RI = NULL;
|
||||||
data.modal = false;
|
|
||||||
data.theme_owner = NULL;
|
data.theme_owner = NULL;
|
||||||
data.modal_exclusive = false;
|
data.modal_exclusive = false;
|
||||||
data.default_cursor = CURSOR_ARROW;
|
data.default_cursor = CURSOR_ARROW;
|
||||||
|
@ -182,7 +182,6 @@ private:
|
|||||||
|
|
||||||
Control *parent;
|
Control *parent;
|
||||||
ObjectID drag_owner;
|
ObjectID drag_owner;
|
||||||
bool modal;
|
|
||||||
bool modal_exclusive;
|
bool modal_exclusive;
|
||||||
uint64_t modal_frame; //frame used to put something as modal
|
uint64_t modal_frame; //frame used to put something as modal
|
||||||
Ref<Theme> theme;
|
Ref<Theme> theme;
|
||||||
|
@ -43,7 +43,6 @@ class MenuButton : public Button {
|
|||||||
bool clicked;
|
bool clicked;
|
||||||
bool disable_shortcuts;
|
bool disable_shortcuts;
|
||||||
PopupMenu *popup;
|
PopupMenu *popup;
|
||||||
virtual void pressed();
|
|
||||||
|
|
||||||
void _unhandled_key_input(Ref<InputEvent> p_event);
|
void _unhandled_key_input(Ref<InputEvent> p_event);
|
||||||
Array _get_items() const;
|
Array _get_items() const;
|
||||||
@ -55,6 +54,8 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual void pressed();
|
||||||
|
|
||||||
PopupMenu *get_popup() const;
|
PopupMenu *get_popup() const;
|
||||||
void set_disable_shortcuts(bool p_disabled);
|
void set_disable_shortcuts(bool p_disabled);
|
||||||
|
|
||||||
|
@ -41,7 +41,10 @@
|
|||||||
#include "scene/3d/spatial.h"
|
#include "scene/3d/spatial.h"
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
#include "scene/gui/label.h"
|
#include "scene/gui/label.h"
|
||||||
|
#include "scene/gui/menu_button.h"
|
||||||
|
#include "scene/gui/panel.h"
|
||||||
#include "scene/gui/panel_container.h"
|
#include "scene/gui/panel_container.h"
|
||||||
|
#include "scene/gui/popup_menu.h"
|
||||||
#include "scene/main/timer.h"
|
#include "scene/main/timer.h"
|
||||||
#include "scene/resources/mesh.h"
|
#include "scene/resources/mesh.h"
|
||||||
#include "scene/scene_string_names.h"
|
#include "scene/scene_string_names.h"
|
||||||
@ -1853,10 +1856,34 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||||||
if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) {
|
if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) {
|
||||||
|
|
||||||
Control *top = gui.modal_stack.back()->get();
|
Control *top = gui.modal_stack.back()->get();
|
||||||
|
|
||||||
if (over != top && !top->is_a_parent_of(over)) {
|
if (over != top && !top->is_a_parent_of(over)) {
|
||||||
|
|
||||||
|
PopupMenu *popup_menu = Object::cast_to<PopupMenu>(top);
|
||||||
|
MenuButton *popup_menu_parent;
|
||||||
|
MenuButton *menu_button = Object::cast_to<MenuButton>(over);
|
||||||
|
|
||||||
|
if (popup_menu)
|
||||||
|
popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent());
|
||||||
|
|
||||||
|
// If the mouse is over a menu button, this menu will open automatically
|
||||||
|
// if there is already a pop-up menu open at the same hierarchical level.
|
||||||
|
if (popup_menu_parent && menu_button &&
|
||||||
|
popup_menu_parent->get_icon().is_null() &&
|
||||||
|
menu_button->get_icon().is_null() &&
|
||||||
|
(popup_menu->get_parent()->get_parent()->is_a_parent_of(menu_button) ||
|
||||||
|
menu_button->get_parent()->is_a_parent_of(popup_menu))) {
|
||||||
|
|
||||||
|
popup_menu->notification(Control::NOTIFICATION_MODAL_CLOSE);
|
||||||
|
popup_menu->_modal_stack_remove();
|
||||||
|
popup_menu->hide();
|
||||||
|
|
||||||
|
menu_button->pressed();
|
||||||
|
} else {
|
||||||
over = NULL; //nothing can be found outside the modal stack
|
over = NULL; //nothing can be found outside the modal stack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (over != gui.mouse_over) {
|
if (over != gui.mouse_over) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user