Merge pull request #50961 from YeldhamDev/embed_windows_fixes

Multiple cosmetic fixes for embedded windows
This commit is contained in:
Rémi Verschelde 2021-07-28 18:24:07 +02:00 committed by GitHub
commit 60eb508fbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 99 additions and 92 deletions

View File

@ -105,4 +105,9 @@
</signals>
<constants>
</constants>
<theme_items>
<theme_item name="panel" type="StyleBox">
Panel that fills up the background of the window.
</theme_item>
</theme_items>
</class>

View File

@ -469,11 +469,11 @@
</theme_item>
<theme_item name="close_h_ofs" type="int" default="18">
</theme_item>
<theme_item name="close_highlight" type="Texture2D">
<theme_item name="close_pressed" type="Texture2D">
</theme_item>
<theme_item name="close_v_ofs" type="int" default="18">
</theme_item>
<theme_item name="panel" type="StyleBox">
<theme_item name="embedded_border" type="StyleBox">
</theme_item>
<theme_item name="resize_margin" type="int" default="4">
</theme_item>
@ -494,7 +494,5 @@
<theme_item name="title_outline_size" type="int" default="0">
The size of the title outline.
</theme_item>
<theme_item name="window_panel" type="StyleBox">
</theme_item>
</theme_items>
</class>

View File

@ -1086,17 +1086,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
style_window_title->set_corner_radius(CORNER_TOP_RIGHT, 0);
// Prevent visible line between window title and body.
style_window_title->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE);
theme->set_stylebox("panel", "Window", style_window_title);
Ref<StyleBoxFlat> style_window = style_popup->duplicate();
style_window->set_border_color(base_color);
style_window->set_border_width(SIDE_TOP, 24 * EDSCALE);
style_window->set_expand_margin_size(SIDE_TOP, 24 * EDSCALE);
theme->set_stylebox("panel_window", "Window", style_window);
theme->set_stylebox("embedded_border", "Window", style_window);
theme->set_color("title_color", "Window", font_color);
theme->set_icon("close", "Window", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_icon("close_highlight", "Window", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_icon("close_pressed", "Window", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_constant("close_h_ofs", "Window", 22 * EDSCALE);
theme->set_constant("close_v_ofs", "Window", 20 * EDSCALE);
theme->set_constant("title_height", "Window", 24 * EDSCALE);
@ -1112,6 +1111,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window);
theme->set_stylebox("panel", "EditorAbout", style_complex_window);
// AcceptDialog
theme->set_stylebox("panel", "AcceptDialog", style_window_title);
// HScrollBar
Ref<Texture2D> empty_icon = memnew(ImageTexture);

View File

@ -72,13 +72,10 @@ void AcceptDialog::_notification(int p_what) {
parent_visible = nullptr;
}
}
} break;
case NOTIFICATION_THEME_CHANGED: {
bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog")));
} break;
case NOTIFICATION_EXIT_TREE: {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));

View File

@ -249,7 +249,7 @@ void Viewport::_sub_window_update(Window *p_window) {
Rect2i r = Rect2i(p_window->get_position(), sw.window->get_size());
if (!p_window->get_flag(Window::FLAG_BORDERLESS)) {
Ref<StyleBox> panel = p_window->get_theme_stylebox(SNAME("panel_window"));
Ref<StyleBox> panel = p_window->get_theme_stylebox(SNAME("embedded_border"));
panel->draw(sw.canvas_item, r);
// Draw the title bar text.
@ -273,9 +273,8 @@ void Viewport::_sub_window_update(Window *p_window) {
}
title_text.draw(sw.canvas_item, r.position + Point2(x, y), title_color);
bool hl = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside;
Ref<Texture2D> close_icon = p_window->get_theme_icon(hl ? "close_highlight" : "close");
bool pressed = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside;
Ref<Texture2D> close_icon = p_window->get_theme_icon(pressed ? "close_pressed" : "close");
close_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_h_ofs, -close_v_ofs));
}

View File

@ -700,93 +700,92 @@ Viewport *Window::_get_embedder() const {
}
void Window::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
bool embedded = false;
{
embedder = _get_embedder();
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
bool embedded = false;
{
embedder = _get_embedder();
if (embedder) {
embedded = true;
if (embedder) {
embedded = true;
if (!visible) {
embedder = nullptr; //not yet since not visible
if (!visible) {
embedder = nullptr; //not yet since not visible
}
}
}
}
if (embedded) {
//create as embedded
if (embedder) {
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
_update_window_size();
}
} else {
if (get_parent() == nullptr) {
//it's the root window!
visible = true; //always visible
window_id = DisplayServer::MAIN_WINDOW_ID;
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
_update_from_window();
//since this window already exists (created on start), we must update pos and size from it
{
position = DisplayServer::get_singleton()->window_get_position(window_id);
size = DisplayServer::get_singleton()->window_get_size(window_id);
if (embedded) {
//create as embedded
if (embedder) {
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
_update_window_size();
}
_update_viewport_size(); //then feed back to the viewport
_update_window_callbacks();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
} else {
//create
if (visible) {
_make_window();
if (get_parent() == nullptr) {
//it's the root window!
visible = true; //always visible
window_id = DisplayServer::MAIN_WINDOW_ID;
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
_update_from_window();
//since this window already exists (created on start), we must update pos and size from it
{
position = DisplayServer::get_singleton()->window_get_position(window_id);
size = DisplayServer::get_singleton()->window_get_size(window_id);
}
_update_viewport_size(); //then feed back to the viewport
_update_window_callbacks();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
} else {
//create
if (visible) {
_make_window();
}
}
}
}
if (transient) {
_make_transient();
}
if (visible) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
}
}
if (transient) {
_make_transient();
}
if (visible) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
}
} break;
case NOTIFICATION_READY: {
if (wrap_controls) {
_update_child_controls();
}
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
child_controls_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
if (transient) {
_clear_transient();
}
if (p_what == NOTIFICATION_READY) {
if (wrap_controls) {
_update_child_controls();
}
}
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
child_controls_changed();
}
if (p_what == NOTIFICATION_EXIT_TREE) {
if (transient) {
_clear_transient();
}
if (!is_embedded() && window_id != DisplayServer::INVALID_WINDOW_ID) {
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
_update_window_callbacks();
if (!is_embedded() && window_id != DisplayServer::INVALID_WINDOW_ID) {
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
_update_window_callbacks();
} else {
_clear_window();
}
} else {
_clear_window();
if (embedder) {
embedder->_sub_window_remove(this);
embedder = nullptr;
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
}
_update_viewport_size(); //called by clear and make, which does not happen here
}
} else {
if (embedder) {
embedder->_sub_window_remove(this);
embedder = nullptr;
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
}
_update_viewport_size(); //called by clear and make, which does not happen here
}
RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
} break;
}
}

View File

@ -571,10 +571,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
empty.instantiate();
theme->set_stylebox("bg", "ScrollContainer", empty);
// WindowDialog
// Window
theme->set_stylebox("panel", "Window", default_style);
theme->set_stylebox("window_panel", "Window", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6));
theme->set_stylebox("embedded_border", "Window", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6));
theme->set_constant("scaleborder_size", "Window", 4 * scale);
theme->set_font("title_font", "Window", large_font);
@ -588,10 +587,14 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("resize_margin", "Window", 4 * scale);
theme->set_icon("close", "Window", make_icon(close_png));
theme->set_icon("close_highlight", "Window", make_icon(close_hl_png));
theme->set_icon("close_pressed", "Window", make_icon(close_hl_png));
theme->set_constant("close_h_ofs", "Window", 18 * scale);
theme->set_constant("close_v_ofs", "Window", 18 * scale);
// AcceptDialog
theme->set_stylebox("panel", "AcceptDialog", make_stylebox(dialog_bg_png, 0, 0, 0, 0));
// File Dialog
theme->set_icon("parent_folder", "FileDialog", make_icon(icon_parent_folder_png));

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 B

After

Width:  |  Height:  |  Size: 921 B

File diff suppressed because one or more lines are too long