Skip to content

Commit

Permalink
Merge pull request #92506 from bruvzg/win_pos_preview
Browse files Browse the repository at this point in the history
Fix Window position preview in the editor.
  • Loading branch information
akien-mga committed May 29, 2024
2 parents 219af36 + 19839d9 commit 8bf8f41
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 33 additions & 2 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,21 @@ String Window::get_title() const {
return title;
}

void Window::_settings_changed() {
if (visible && initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE && is_in_edited_scene_root()) {
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
position = (screen_size - size) / 2;
if (embedder) {
embedder->_sub_window_update(this);
}
}
}

void Window::set_initial_position(Window::WindowInitialPosition p_initial_position) {
ERR_MAIN_THREAD_GUARD;

initial_position = p_initial_position;
_settings_changed();
notify_property_list_changed();
}

Expand Down Expand Up @@ -829,7 +840,12 @@ void Window::set_visible(bool p_visible) {
if (visible) {
embedder = embedder_vp;
if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
position = (embedder->get_visible_rect().size - size) / 2;
if (is_in_edited_scene_root()) {
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
position = (screen_size - size) / 2;
} else {
position = (embedder->get_visible_rect().size - size) / 2;
}
}
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
Expand Down Expand Up @@ -1265,6 +1281,12 @@ void Window::_notification(int p_what) {
} break;

case NOTIFICATION_ENTER_TREE: {
if (is_in_edited_scene_root()) {
if (!ProjectSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &Window::_settings_changed))) {
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Window::_settings_changed));
}
}

bool embedded = false;
{
embedder = get_embedder();
Expand All @@ -1280,7 +1302,12 @@ void Window::_notification(int p_what) {
// Create as embedded.
if (embedder) {
if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
position = (embedder->get_visible_rect().size - size) / 2;
if (is_in_edited_scene_root()) {
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
position = (screen_size - size) / 2;
} else {
position = (embedder->get_visible_rect().size - size) / 2;
}
}
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
Expand Down Expand Up @@ -1377,6 +1404,10 @@ void Window::_notification(int p_what) {
} break;

case NOTIFICATION_EXIT_TREE: {
if (ProjectSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &Window::_settings_changed))) {
ProjectSettings::get_singleton()->disconnect("settings_changed", callable_mp(this, &Window::_settings_changed));
}

set_theme_context(nullptr, false);

if (transient) {
Expand Down
2 changes: 2 additions & 0 deletions scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class Window : public Viewport {
int resize_margin = 0;
} theme_cache;

void _settings_changed();

Viewport *embedder = nullptr;

Transform2D window_transform;
Expand Down

0 comments on commit 8bf8f41

Please sign in to comment.