diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-03-14 13:06:39 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-03-26 15:49:43 +0100 |
commit | c7b4dcae2f3b75ad7146e36f196893731f403144 (patch) | |
tree | d6223521b246aa36d0e0b78d6ed626fa2a0e3769 /scene/gui | |
parent | 441f1a5fe9a3bf0e4e5dab578f793500b1ff6e3d (diff) |
Open sub-windows as embedded if the OS does not support them
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/base_button.cpp | 3 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 5 | ||||
-rw-r--r-- | scene/gui/control.cpp | 189 | ||||
-rw-r--r-- | scene/gui/control.h | 19 | ||||
-rw-r--r-- | scene/gui/menu_button.cpp | 14 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 11 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 11 |
7 files changed, 67 insertions, 185 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 07bc91e7e7..a05ac08e9d 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -357,9 +357,6 @@ void BaseButton::_unhandled_input(Ref<InputEvent> p_event) { if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { - if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) - return; //ignore because of modal window - on_action_event(p_event); } } diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 2a3f7467dc..948e46b649 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -620,7 +620,10 @@ void ColorPicker::_screen_pick_pressed() { screen->call_deferred("connect", "hide", Callable(btn_pick, "set_pressed"), varray(false)); } screen->raise(); - screen->show_modal(); +#ifndef _MSC_VER +#warning show modal no longer works, needs to be converted to a popup +#endif + //screen->show_modal(); } void ColorPicker::_focus_enter() { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 062d15c05b..bfaace69d7 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -494,76 +494,54 @@ void Control::_notification(int p_notification) { data.parent = Object::cast_to<Control>(get_parent()); - if (is_set_as_toplevel()) { - data.SI = get_viewport()->_gui_add_subwindow_control(this); + Node *parent = this; //meh + Control *parent_control = NULL; + bool subwindow = false; - if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) { - data.theme_owner = data.parent->data.theme_owner; - notification(NOTIFICATION_THEME_CHANGED); - } - - } else { - - Node *parent = this; //meh - Control *parent_control = NULL; - bool subwindow = false; - - while (parent) { - - parent = parent->get_parent(); - - if (!parent) - break; - - CanvasItem *ci = Object::cast_to<CanvasItem>(parent); - if (ci && ci->is_set_as_toplevel()) { - subwindow = true; - break; - } + while (parent) { - parent_control = Object::cast_to<Control>(parent); + parent = parent->get_parent(); - if (parent_control) { - break; - } else if (ci) { + if (!parent) + break; - } else { - break; - } + CanvasItem *ci = Object::cast_to<CanvasItem>(parent); + if (ci && ci->is_set_as_toplevel()) { + subwindow = true; + break; } - if (parent_control) { - //do nothing, has a parent control - if (data.theme.is_null() && parent_control->data.theme_owner) { - data.theme_owner = parent_control->data.theme_owner; - notification(NOTIFICATION_THEME_CHANGED); - } - } else if (subwindow) { - //is a subwindow (process input before other controls for that canvas) - data.SI = get_viewport()->_gui_add_subwindow_control(this); - } else { - //is a regular root control - data.RI = get_viewport()->_gui_add_root_control(this); - } - - data.parent_canvas_item = get_parent_item(); + parent_control = Object::cast_to<Control>(parent); - if (data.parent_canvas_item) { + if (parent_control) { + break; + } else if (ci) { - data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); } else { - //connect viewport - get_viewport()->connect("size_changed", callable_mp(this, &Control::_size_changed)); + break; } } - /* - if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) { - data.theme_owner=data.parent->data.theme_owner; - notification(NOTIFICATION_THEME_CHANGED); + if (parent_control && !subwindow) { + //do nothing, has a parent control and not toplevel + if (data.theme.is_null() && parent_control->data.theme_owner) { + data.theme_owner = parent_control->data.theme_owner; + notification(NOTIFICATION_THEME_CHANGED); + } + } else { + //is a regular root control or toplevel + data.RI = get_viewport()->_gui_add_root_control(this); } - */ + data.parent_canvas_item = get_parent_item(); + + if (data.parent_canvas_item) { + + data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); + } else { + //connect viewport + get_viewport()->connect("size_changed", callable_mp(this, &Control::_size_changed)); + } } break; case NOTIFICATION_EXIT_CANVAS: { @@ -576,16 +554,6 @@ void Control::_notification(int p_notification) { get_viewport()->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); } - if (data.MI) { - get_viewport()->_gui_remove_modal_control(data.MI); - data.MI = NULL; - } - - if (data.SI) { - get_viewport()->_gui_remove_subwindow_control(data.SI); - data.SI = NULL; - } - if (data.RI) { get_viewport()->_gui_remove_root_control(data.RI); data.RI = NULL; @@ -608,9 +576,6 @@ void Control::_notification(int p_notification) { data.parent->update(); update(); - if (data.SI) { - get_viewport()->_gui_set_subwindow_order_dirty(); - } if (data.RI) { get_viewport()->_gui_set_root_order_dirty(); } @@ -652,10 +617,6 @@ void Control::_notification(int p_notification) { minimum_size_changed(); update(); } break; - case NOTIFICATION_MODAL_CLOSE: { - - emit_signal("modal_closed"); - } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible_in_tree()) { @@ -663,10 +624,6 @@ void Control::_notification(int p_notification) { if (get_viewport() != NULL) get_viewport()->_gui_hid_control(this); - if (is_inside_tree()) { - _modal_stack_remove(); - } - //remove key focus //remove modalness } else { @@ -790,19 +747,6 @@ void Control::set_drag_preview(Control *p_control) { get_viewport()->_gui_set_drag_preview(this, p_control); } -bool Control::is_window_modal_on_top() const { - - if (!is_inside_tree()) - return false; - - return get_viewport()->_gui_is_modal_on_top(this); -} - -uint64_t Control::get_modal_frame() const { - - return data.modal_frame; -} - Size2 Control::get_minimum_size() const { ScriptInstance *si = const_cast<Control *>(this)->get_script_instance(); @@ -1720,7 +1664,7 @@ Point2 Control::get_screen_position() const { ERR_FAIL_COND_V(!is_inside_tree(), Point2()); Point2 global_pos = get_global_position(); Window *w = Object::cast_to<Window>(get_viewport()); - if (w) { + if (w && !w->is_embedding_subwindows()) { global_pos += w->get_position(); } @@ -1828,7 +1772,7 @@ Rect2 Control::get_screen_rect() const { Rect2 r(get_global_position(), get_size()); Window *w = Object::cast_to<Window>(get_viewport()); - if (w) { + if (w && !w->is_embedding_subwindows()) { r.position += w->get_position(); } @@ -2021,7 +1965,7 @@ Control *Control::find_next_valid_focus() const { next_child = const_cast<Control *>(this); while (next_child) { - if (next_child->data.SI || next_child->data.RI) + if (next_child->data.RI) break; next_child = next_child->get_parent_control(); } @@ -2164,41 +2108,6 @@ bool Control::is_toplevel_control() const { return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel()); } -void Control::show_modal(bool p_exclusive) { - - ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.SI); - - if (is_visible_in_tree()) - hide(); - - ERR_FAIL_COND(data.MI != NULL); - show(); - raise(); - data.modal_exclusive = p_exclusive; - data.MI = get_viewport()->_gui_show_modal(this); - data.modal_frame = Engine::get_singleton()->get_frames_drawn(); -} - -void Control::_modal_set_prev_focus_owner(ObjectID p_prev) { - data.modal_prev_focus_owner = p_prev; -} - -void Control::_modal_stack_remove() { - - ERR_FAIL_COND(!is_inside_tree()); - - if (!data.MI) - return; - - List<Control *>::Element *element = data.MI; - data.MI = NULL; - - get_viewport()->_gui_remove_from_modal_stack(element, data.modal_prev_focus_owner); - - data.modal_prev_focus_owner = ObjectID(); -} - void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) { Control *c = Object::cast_to<Control>(p_at); @@ -2444,8 +2353,6 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { Control *c = Object::cast_to<Control>(base); if (c) { - if (c->data.SI) - break; if (c->data.RI) break; } @@ -2515,7 +2422,7 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con Node *child = p_at->get_child(i); Control *childc = Object::cast_to<Control>(child); - if (childc && childc->data.SI) + if (childc && childc->data.RI) continue; //subwindow, ignore _window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest); } @@ -2609,16 +2516,6 @@ Control::MouseFilter Control::get_mouse_filter() const { return data.mouse_filter; } -void Control::set_pass_on_modal_close_click(bool p_pass_on) { - - data.pass_on_modal_close_click = p_pass_on; -} - -bool Control::pass_on_modal_close_click() const { - - return data.pass_on_modal_close_click; -} - Control *Control::get_focus_owner() const { ERR_FAIL_COND_V(!is_inside_tree(), NULL); @@ -2712,7 +2609,7 @@ Control *Control::get_root_parent_control() const { if (c) { root = c; - if (c->data.RI || c->data.MI || c->is_toplevel_control()) + if (c->data.RI || c->is_toplevel_control()) break; } @@ -2864,7 +2761,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); - ClassDB::bind_method(D_METHOD("show_modal", "exclusive"), &Control::show_modal, DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode); ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode); ClassDB::bind_method(D_METHOD("has_focus"), &Control::has_focus); @@ -3024,7 +2920,6 @@ void Control::_bind_methods() { BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER); BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT); BIND_CONSTANT(NOTIFICATION_THEME_CHANGED); - BIND_CONSTANT(NOTIFICATION_MODAL_CLOSE); BIND_CONSTANT(NOTIFICATION_SCROLL_BEGIN); BIND_CONSTANT(NOTIFICATION_SCROLL_END); @@ -3093,7 +2988,6 @@ void Control::_bind_methods() { ADD_SIGNAL(MethodInfo("focus_exited")); ADD_SIGNAL(MethodInfo("size_flags_changed")); ADD_SIGNAL(MethodInfo("minimum_size_changed")); - ADD_SIGNAL(MethodInfo("modal_closed")); ADD_SIGNAL(MethodInfo("theme_changed")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point"))); @@ -3103,14 +2997,10 @@ Control::Control() { data.parent = NULL; data.mouse_filter = MOUSE_FILTER_STOP; - data.pass_on_modal_close_click = true; - data.SI = NULL; - data.MI = NULL; data.RI = NULL; data.theme_owner = NULL; data.theme_owner_window = NULL; - data.modal_exclusive = false; data.default_cursor = CURSOR_ARROW; data.h_size_flags = SIZE_FILL; data.v_size_flags = SIZE_FILL; @@ -3119,7 +3009,6 @@ Control::Control() { data.parent_canvas_item = NULL; data.scale = Vector2(1, 1); - data.modal_frame = 0; data.block_minimum_size_adjust = false; data.disable_visibility_clip = false; data.h_grow = GROW_DIRECTION_END; diff --git a/scene/gui/control.h b/scene/gui/control.h index 22839df712..c52e80fa70 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -168,8 +168,6 @@ private: float expand; Point2 custom_minimum_size; - bool pass_on_modal_close_click; - MouseFilter mouse_filter; bool clip_contents; @@ -179,22 +177,16 @@ private: Control *parent; ObjectID drag_owner; - bool modal_exclusive; - uint64_t modal_frame; //frame used to put something as modal Ref<Theme> theme; Control *theme_owner; Window *theme_owner_window; String tooltip; CursorShape default_cursor; - List<Control *>::Element *MI; //modal item - List<Control *>::Element *SI; List<Control *>::Element *RI; CanvasItem *parent_canvas_item; - ObjectID modal_prev_focus_owner; - NodePath focus_neighbour[4]; NodePath focus_next; NodePath focus_prev; @@ -240,8 +232,6 @@ private: Transform2D _get_internal_transform() const; friend class Viewport; - void _modal_stack_remove(); - void _modal_set_prev_focus_owner(ObjectID p_prev); void _update_minimum_size_cache(); friend class Window; @@ -293,7 +283,6 @@ public: NOTIFICATION_FOCUS_ENTER = 43, NOTIFICATION_FOCUS_EXIT = 44, NOTIFICATION_THEME_CHANGED = 45, - NOTIFICATION_MODAL_CLOSE = 46, NOTIFICATION_SCROLL_BEGIN = 47, NOTIFICATION_SCROLL_END = 48, @@ -341,9 +330,6 @@ public: void set_custom_minimum_size(const Size2 &p_custom); Size2 get_custom_minimum_size() const; - bool is_window_modal_on_top() const; - uint64_t get_modal_frame() const; //frame in which this was made modal - Control *get_parent_control() const; /* POSITIONING */ @@ -398,8 +384,6 @@ public: void set_scale(const Vector2 &p_scale); Vector2 get_scale() const; - void show_modal(bool p_exclusive = false); - void set_theme(const Ref<Theme> &p_theme); Ref<Theme> get_theme() const; @@ -438,9 +422,6 @@ public: void set_mouse_filter(MouseFilter p_filter); MouseFilter get_mouse_filter() const; - void set_pass_on_modal_close_click(bool p_pass_on); - bool pass_on_modal_close_click() const; - /* SKINNING */ void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 4cae7b8f40..61441ff958 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -43,20 +43,24 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { if (!get_parent() || !is_visible_in_tree() || is_disabled()) return; - bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)); - - if (popup->activate_item_by_event(p_event, global_only)) + //bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)); + //if (popup->activate_item_by_event(p_event, global_only)) + // accept_event(); + if (popup->activate_item_by_event(p_event, false)) accept_event(); } } void MenuButton::pressed() { - emit_signal("about_to_popup"); Size2 size = get_size(); Point2 gp = get_screen_position(); - popup->set_position(gp + Size2(0, size.height * get_global_transform().get_scale().y)); + + gp.y += get_size().y; + + popup->set_position(gp); + popup->set_size(Size2(size.width, 0)); popup->set_parent_rect(Rect2(Point2(gp - popup->get_position()), get_size())); popup->popup(); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 6951026dec..e325f2661a 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -163,7 +163,7 @@ void PopupMenu::_activate_submenu(int over) { Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y); Size2 size = pm->get_size(); // fix pos - if (pos.x + size.width > get_screen_rect().size.width) + if (pos.x + size.width > get_parent_rect().size.width) pos.x = p.x - size.width; pm->set_position(pos); @@ -203,7 +203,7 @@ void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { dy = MIN(dy, limit); } else if (dy < 0) { const float global_bottom = get_position().y + get_size().y; - const float viewport_height = get_screen_rect().size.y; + const float viewport_height = get_parent_rect().size.y; const float limit = global_bottom > viewport_height ? global_bottom - viewport_height : 0; dy = -MIN(-dy, limit); } @@ -295,7 +295,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { case BUTTON_WHEEL_DOWN: { - if (get_position().y + get_size().y > get_screen_rect().size.y) { + if (get_position().y + get_size().y > get_parent_rect().size.y) { _scroll(-b->get_factor(), b->get_position()); } } break; @@ -382,7 +382,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (get_position().y + get_size().y > get_screen_rect().size.y || get_position().y < 0) { + if (get_position().y + get_size().y > get_parent_rect().size.y || get_position().y < 0) { _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position()); } } @@ -592,6 +592,9 @@ void PopupMenu::_notification(int p_what) { initial_button_mask = InputFilter::get_singleton()->get_mouse_button_mask(); during_grabbed_click = (bool)initial_button_mask; } break; + case NOTIFICATION_WM_SIZE_CHANGED: { + + } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 7bac82bf63..38ae1f36bc 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2819,7 +2819,10 @@ bool Tree::edit_selected() { value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height)); value_editor->set_size(Size2(rect.size.width, 1)); - value_editor->show_modal(); +#ifndef _MSC_VER +#warning show modal no longer works, need to replace by a popup +#endif + value_editor->show(); updating_value_editor = true; value_editor->set_min(c.min); value_editor->set_max(c.max); @@ -2828,8 +2831,10 @@ bool Tree::edit_selected() { value_editor->set_exp_ratio(c.expr); updating_value_editor = false; } - - text_editor->show_modal(); +#ifndef _MSC_VER +#warning show modal no longer works, need to replace by a popup +#endif + text_editor->show(); text_editor->grab_focus(); return true; } |