summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2020-03-12 09:37:40 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-03-26 15:49:42 +0100
commit441f1a5fe9a3bf0e4e5dab578f793500b1ff6e3d (patch)
tree6421bcc3235e6fdcd726244ac7d455886e17734b /scene/main
parent543fb1c4dadd75914d595b089820aef42e691075 (diff)
Popups are now windows also (broken!)
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/viewport.cpp36
-rw-r--r--scene/main/window.cpp98
-rw-r--r--scene/main/window.h18
3 files changed, 115 insertions, 37 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 4fbb1cb870..50d0520d4b 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1309,7 +1309,7 @@ Transform2D Viewport::_get_input_pre_xform() const {
Transform2D pre_xf;
- if (to_screen_rect != Rect2i()) {
+ if (to_screen_rect.size.x != 0 && to_screen_rect.size.y != 0) {
pre_xf.elements[2] = -to_screen_rect.position;
pre_xf.scale(size / to_screen_rect.size);
@@ -1460,7 +1460,7 @@ void Viewport::_gui_show_tooltip() {
gui.tooltip_label = memnew(TooltipLabel);
gui.tooltip_popup->add_child(gui.tooltip_label);
- Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel");
+ Ref<StyleBox> ttp = gui.tooltip_label->get_theme_stylebox("panel", "TooltipPanel");
gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT));
gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP));
@@ -1995,37 +1995,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *top = gui.modal_stack.back()->get();
if (over != top && !top->is_a_parent_of(over)) {
-
- PopupMenu *popup_menu = Object::cast_to<PopupMenu>(top);
- MenuButton *popup_menu_parent = NULL;
- MenuButton *menu_button = Object::cast_to<MenuButton>(over);
-
- if (popup_menu) {
- popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent());
- if (!popup_menu_parent) {
- // Go through the parents to see if there's a MenuButton at the end.
- while (Object::cast_to<PopupMenu>(popup_menu->get_parent())) {
- popup_menu = Object::cast_to<PopupMenu>(popup_menu->get_parent());
- }
- 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->is_switch_on_hover() &&
- !menu_button->is_disabled() && menu_button->is_switch_on_hover() &&
- (popup_menu_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
}
}
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 61817f086c..6d61f3f0a8 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -394,7 +394,7 @@ void Window::_make_transient() {
if (window) {
transient_parent = window;
window->transient_children.insert(this);
- if (exclusive) {
+ if (is_inside_tree() && is_visible() && exclusive) {
if (transient_parent->exclusive_child == nullptr) {
transient_parent->exclusive_child = this;
} else if (transient_parent->exclusive_child != this) {
@@ -439,9 +439,9 @@ void Window::set_exclusive(bool p_exclusive) {
exclusive = p_exclusive;
if (transient_parent) {
- if (p_exclusive) {
+ if (p_exclusive && is_inside_tree() && is_visible()) {
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
- transient_parent->exclusive_child = nullptr;
+ transient_parent->exclusive_child = this;
} else {
if (transient_parent->exclusive_child == this) {
transient_parent->exclusive_child = nullptr;
@@ -762,8 +762,10 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) {
if (exclusive_child != nullptr) {
exclusive_child->grab_focus();
+ print_line("drop because of exclusive");
return; //has an exclusive child, can't get events until child is closed
}
+
emit_signal(SceneStringNames::get_singleton()->window_input, p_ev);
input(p_ev);
if (!is_input_handled()) {
@@ -897,6 +899,8 @@ void Window::popup_centered_ratio(float p_ratio) {
}
void Window::popup(const Rect2 &p_screen_rect) {
+
+ emit_signal("about_to_popup");
if (p_screen_rect != Rect2()) {
set_position(p_screen_rect.position);
set_size(p_screen_rect.size);
@@ -908,6 +912,10 @@ void Window::popup(const Rect2 &p_screen_rect) {
notification(NOTIFICATION_POST_POPUP);
}
+Size2 Window::get_contents_minimum_size() const {
+ return _get_contents_minimum_size();
+}
+
void Window::grab_focus() {
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
DisplayServer::get_singleton()->window_move_to_foreground(window_id);
@@ -979,6 +987,74 @@ Ref<Theme> Window::get_theme() const {
return theme;
}
+Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_type) const {
+ return Control::get_icons(theme_owner, theme_owner_window, p_name, p_type);
+}
+Ref<Shader> Window::get_theme_shader(const StringName &p_name, const StringName &p_type) const {
+ return Control::get_shaders(theme_owner, theme_owner_window, p_name, p_type);
+}
+Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
+ return Control::get_styleboxs(theme_owner, theme_owner_window, p_name, p_type);
+}
+Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_type) const {
+ return Control::get_fonts(theme_owner, theme_owner_window, p_name, p_type);
+}
+Color Window::get_theme_color(const StringName &p_name, const StringName &p_type) const {
+ return Control::get_colors(theme_owner, theme_owner_window, p_name, p_type);
+}
+int Window::get_theme_constant(const StringName &p_name, const StringName &p_type) const {
+ return Control::get_constants(theme_owner, theme_owner_window, p_name, p_type);
+}
+
+bool Window::has_theme_icon(const StringName &p_name, const StringName &p_type) const {
+ return Control::has_icons(theme_owner, theme_owner_window, p_name, p_type);
+}
+bool Window::has_theme_shader(const StringName &p_name, const StringName &p_type) const {
+ return Control::has_shaders(theme_owner, theme_owner_window, p_name, p_type);
+}
+bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
+ return Control::has_styleboxs(theme_owner, theme_owner_window, p_name, p_type);
+}
+bool Window::has_theme_font(const StringName &p_name, const StringName &p_type) const {
+ return Control::has_fonts(theme_owner, theme_owner_window, p_name, p_type);
+}
+bool Window::has_theme_color(const StringName &p_name, const StringName &p_type) const {
+ return Control::has_colors(theme_owner, theme_owner_window, p_name, p_type);
+}
+bool Window::has_theme_constant(const StringName &p_name, const StringName &p_type) const {
+ return Control::has_constants(theme_owner, theme_owner_window, p_name, p_type);
+}
+
+Rect2i Window::get_screen_rect() const {
+ if (is_embedded()) {
+ //viewport
+ return Rect2i();
+ } else {
+ int x = get_position().x;
+ int closest_dist = 0x7FFFFFFF;
+ Rect2i closest_rect;
+ for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
+ Rect2i s(DisplayServer::get_singleton()->screen_get_position(i), DisplayServer::get_singleton()->screen_get_size(i));
+ int d;
+ if (x >= s.position.x && x < s.size.x) {
+ //contained
+ closest_rect = s;
+ break;
+ } else if (x < s.position.x) {
+ d = s.position.x - x;
+ } else {
+ d = x - (s.position.x + s.size.x);
+ }
+
+ if (d < closest_dist) {
+ closest_dist = d;
+ closest_rect = s;
+ }
+ }
+ return closest_rect;
+ }
+}
+
void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
@@ -1055,6 +1131,18 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme);
+ ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "type"), &Window::get_theme_icon, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "type"), &Window::get_theme_stylebox, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("get_theme_font", "name", "type"), &Window::get_theme_font, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("get_theme_color", "name", "type"), &Window::get_theme_color, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "type"), &Window::get_theme_constant, DEFVAL(""));
+
+ ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "type"), &Window::has_theme_icon, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "type"), &Window::has_theme_stylebox, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("has_theme_font", "name", "type"), &Window::has_theme_font, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("has_theme_color", "name", "type"), &Window::has_theme_color, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "type"), &Window::has_theme_constant, DEFVAL(""));
+
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "position"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size"), "set_size", "get_size");
@@ -1080,7 +1168,7 @@ void Window::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
- ADD_SIGNAL(MethodInfo("files_dropped"));
+ ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
ADD_SIGNAL(MethodInfo("focus_entered"));
@@ -1088,6 +1176,8 @@ void Window::_bind_methods() {
ADD_SIGNAL(MethodInfo("close_requested"));
ADD_SIGNAL(MethodInfo("go_back_requested"));
ADD_SIGNAL(MethodInfo("visibility_changed"));
+ ADD_SIGNAL(MethodInfo("files_dropped"));
+ ADD_SIGNAL(MethodInfo("about_to_popup"));
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
}
diff --git a/scene/main/window.h b/scene/main/window.h
index acc3e11fdc..298a611575 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -224,9 +224,27 @@ public:
void set_theme(const Ref<Theme> &p_theme);
Ref<Theme> get_theme() const;
+ Size2 get_contents_minimum_size() const;
+
void grab_focus();
bool has_focus() const;
+ Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const;
+ Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const;
+ Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const;
+ Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const;
+ Color get_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const;
+ int get_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const;
+
+ bool has_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const;
+ bool has_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const;
+ bool has_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const;
+ bool has_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const;
+ bool has_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const;
+ bool has_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const;
+
+ Rect2i get_screen_rect() const;
+
Window();
~Window();
};