mirror of
https://github.com/godotengine/godot.git
synced 2025-04-07 00:44:24 +08:00
Merge pull request #102251 from Hilderin/fix-slow-resize-embedded-game
Fix slow resize Embedded Game Window
This commit is contained in:
commit
2675997487
@ -40,20 +40,6 @@ void EmbeddedProcess::_notification(int p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
window = get_window();
|
||||
} break;
|
||||
case NOTIFICATION_PROCESS: {
|
||||
_check_focused_process_id();
|
||||
_check_mouse_over();
|
||||
|
||||
// We need to detect when the control globally changes location or size on the screen.
|
||||
// NOTIFICATION_RESIZED and NOTIFICATION_WM_POSITION_CHANGED are not enough to detect
|
||||
// resized parent to siblings controls that can affect global position.
|
||||
Rect2i new_global_rect = get_global_rect();
|
||||
if (last_global_rect != new_global_rect) {
|
||||
last_global_rect = new_global_rect;
|
||||
queue_update_embedded_process();
|
||||
}
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
_draw();
|
||||
} break;
|
||||
@ -192,7 +178,7 @@ void EmbeddedProcess::embed_process(OS::ProcessID p_pid) {
|
||||
current_process_id = p_pid;
|
||||
start_embedding_time = OS::get_singleton()->get_ticks_msec();
|
||||
embedding_grab_focus = has_focus();
|
||||
set_process(true);
|
||||
timer_update_embedded_process->start();
|
||||
set_notify_transform(true);
|
||||
|
||||
// Attempt to embed the process, but if it has just started and the window is not ready yet,
|
||||
@ -209,7 +195,7 @@ void EmbeddedProcess::reset() {
|
||||
start_embedding_time = 0;
|
||||
embedding_grab_focus = false;
|
||||
timer_embedding->stop();
|
||||
set_process(false);
|
||||
timer_update_embedded_process->stop();
|
||||
set_notify_transform(false);
|
||||
queue_redraw();
|
||||
}
|
||||
@ -242,18 +228,31 @@ bool EmbeddedProcess::_is_embedded_process_updatable() {
|
||||
}
|
||||
|
||||
void EmbeddedProcess::queue_update_embedded_process() {
|
||||
if (updated_embedded_process_queued || !_is_embedded_process_updatable()) {
|
||||
return;
|
||||
updated_embedded_process_queued = true;
|
||||
}
|
||||
|
||||
void EmbeddedProcess::_timer_update_embedded_process_timeout() {
|
||||
_check_focused_process_id();
|
||||
_check_mouse_over();
|
||||
|
||||
if (!updated_embedded_process_queued) {
|
||||
// We need to detect when the control globally changes location or size on the screen.
|
||||
// NOTIFICATION_RESIZED and NOTIFICATION_WM_POSITION_CHANGED are not enough to detect
|
||||
// resized parent to siblings controls that can affect global position.
|
||||
Rect2i new_global_rect = get_global_rect();
|
||||
if (last_global_rect != new_global_rect) {
|
||||
last_global_rect = new_global_rect;
|
||||
queue_update_embedded_process();
|
||||
}
|
||||
}
|
||||
|
||||
updated_embedded_process_queued = true;
|
||||
|
||||
callable_mp(this, &EmbeddedProcess::_update_embedded_process).call_deferred();
|
||||
if (updated_embedded_process_queued) {
|
||||
updated_embedded_process_queued = false;
|
||||
_update_embedded_process();
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedProcess::_update_embedded_process() {
|
||||
updated_embedded_process_queued = false;
|
||||
|
||||
if (!_is_embedded_process_updatable()) {
|
||||
return;
|
||||
}
|
||||
@ -352,6 +351,12 @@ EmbeddedProcess::EmbeddedProcess() {
|
||||
timer_embedding->set_one_shot(true);
|
||||
add_child(timer_embedding);
|
||||
timer_embedding->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_embedding_timeout));
|
||||
|
||||
timer_update_embedded_process = memnew(Timer);
|
||||
timer_update_embedded_process->set_wait_time(0.1);
|
||||
add_child(timer_update_embedded_process);
|
||||
timer_update_embedded_process->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_update_embedded_process_timeout));
|
||||
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ class EmbeddedProcess : public Control {
|
||||
|
||||
Window *window = nullptr;
|
||||
Timer *timer_embedding = nullptr;
|
||||
Timer *timer_update_embedded_process = nullptr;
|
||||
|
||||
const int embedding_timeout = 45000;
|
||||
|
||||
@ -61,6 +62,7 @@ class EmbeddedProcess : public Control {
|
||||
void _try_embed_process();
|
||||
void _update_embedded_process();
|
||||
void _timer_embedding_timeout();
|
||||
void _timer_update_embedded_process_timeout();
|
||||
void _draw();
|
||||
void _check_mouse_over();
|
||||
void _check_focused_process_id();
|
||||
|
@ -979,6 +979,11 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, WindowWrapper *p_wrapper) {
|
||||
game_size_label = memnew(Label());
|
||||
main_menu_hbox->add_child(game_size_label);
|
||||
game_size_label->hide();
|
||||
// Setting the minimum size prevents the game workspace from resizing indefinitely
|
||||
// due to the label size oscillating by a few pixels when the game is in stretch mode
|
||||
// and the game workspace is at its minimum size.
|
||||
game_size_label->set_custom_minimum_size(Size2(80 * EDSCALE, 0));
|
||||
game_size_label->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_RIGHT);
|
||||
|
||||
panel = memnew(Panel);
|
||||
add_child(panel);
|
||||
|
Loading…
x
Reference in New Issue
Block a user