diff options
Diffstat (limited to 'editor/progress_dialog.cpp')
-rw-r--r-- | editor/progress_dialog.cpp | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 0665b1d013..541cba836b 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -34,9 +34,9 @@ #include "core/os/os.h" #include "editor_scale.h" #include "main/main.h" +#include "servers/display_server.h" void BackgroundProgress::_add_task(const String &p_task, const String &p_label, int p_steps) { - _THREAD_SAFE_METHOD_ ERR_FAIL_COND_MSG(tasks.has(p_task), "Task '" + p_task + "' already exists."); BackgroundProgress::Task t; @@ -61,11 +61,9 @@ void BackgroundProgress::_add_task(const String &p_task, const String &p_label, } void BackgroundProgress::_update() { - _THREAD_SAFE_METHOD_ for (Map<String, int>::Element *E = updates.front(); E; E = E->next()) { - if (tasks.has(E->key())) { _task_step(E->key(), E->get()); } @@ -75,19 +73,19 @@ void BackgroundProgress::_update() { } void BackgroundProgress::_task_step(const String &p_task, int p_step) { - _THREAD_SAFE_METHOD_ ERR_FAIL_COND(!tasks.has(p_task)); Task &t = tasks[p_task]; - if (p_step < 0) + if (p_step < 0) { t.progress->set_value(t.progress->get_value() + 1); - else + } else { t.progress->set_value(p_step); + } } -void BackgroundProgress::_end_task(const String &p_task) { +void BackgroundProgress::_end_task(const String &p_task) { _THREAD_SAFE_METHOD_ ERR_FAIL_COND(!tasks.has(p_task)); @@ -98,7 +96,6 @@ void BackgroundProgress::_end_task(const String &p_task) { } void BackgroundProgress::_bind_methods() { - ClassDB::bind_method("_add_task", &BackgroundProgress::_add_task); ClassDB::bind_method("_task_step", &BackgroundProgress::_task_step); ClassDB::bind_method("_end_task", &BackgroundProgress::_end_task); @@ -106,11 +103,10 @@ void BackgroundProgress::_bind_methods() { } void BackgroundProgress::add_task(const String &p_task, const String &p_label, int p_steps) { - MessageQueue::get_singleton()->push_call(this, "_add_task", p_task, p_label, p_steps); } -void BackgroundProgress::task_step(const String &p_task, int p_step) { +void BackgroundProgress::task_step(const String &p_task, int p_step) { //this code is weird, but it prevents deadlock. bool no_updates = true; { @@ -118,8 +114,9 @@ void BackgroundProgress::task_step(const String &p_task, int p_step) { no_updates = updates.empty(); } - if (no_updates) + if (no_updates) { MessageQueue::get_singleton()->push_call(this, "_update"); + } { _THREAD_SAFE_METHOD_ @@ -128,45 +125,32 @@ void BackgroundProgress::task_step(const String &p_task, int p_step) { } void BackgroundProgress::end_task(const String &p_task) { - MessageQueue::get_singleton()->push_call(this, "_end_task", p_task); } //////////////////////////////////////////////// -ProgressDialog *ProgressDialog::singleton = NULL; +ProgressDialog *ProgressDialog::singleton = nullptr; void ProgressDialog::_notification(int p_what) { - - switch (p_what) { - - case NOTIFICATION_DRAW: { - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - draw_style_box(style, Rect2(Point2(), get_size())); - - } break; - } } void ProgressDialog::_popup() { - Size2 ms = main->get_combined_minimum_size(); ms.width = MAX(500 * EDSCALE, ms.width); - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<StyleBox> style = main->get_theme_stylebox("panel", "PopupMenu"); ms += style->get_minimum_size(); main->set_margin(MARGIN_LEFT, style->get_margin(MARGIN_LEFT)); main->set_margin(MARGIN_RIGHT, -style->get_margin(MARGIN_RIGHT)); main->set_margin(MARGIN_TOP, style->get_margin(MARGIN_TOP)); main->set_margin(MARGIN_BOTTOM, -style->get_margin(MARGIN_BOTTOM)); - raise(); + //raise(); popup_centered(ms); } void ProgressDialog::add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { - if (MessageQueue::get_singleton()->is_flushing()) { ERR_PRINT("Do not use progress dialog (task) while flushing the message queue or using call_deferred()!"); return; @@ -201,25 +185,26 @@ void ProgressDialog::add_task(const String &p_task, const String &p_label, int p } bool ProgressDialog::task_step(const String &p_task, const String &p_state, int p_step, bool p_force_redraw) { - ERR_FAIL_COND_V(!tasks.has(p_task), cancelled); if (!p_force_redraw) { uint64_t tus = OS::get_singleton()->get_ticks_usec(); - if (tus - last_progress_tick < 200000) //200ms + if (tus - last_progress_tick < 200000) { //200ms return cancelled; + } } Task &t = tasks[p_task]; - if (p_step < 0) + if (p_step < 0) { t.progress->set_value(t.progress->get_value() + 1); - else + } else { t.progress->set_value(p_step); + } t.state->set_text(p_state); last_progress_tick = OS::get_singleton()->get_ticks_usec(); if (cancel_hb->is_visible()) { - OS::get_singleton()->force_process_input(); + DisplayServer::get_singleton()->process_events(); } Main::iteration(); // this will not work on a lot of platforms, so it's only meant for the editor @@ -227,17 +212,17 @@ bool ProgressDialog::task_step(const String &p_task, const String &p_state, int } void ProgressDialog::end_task(const String &p_task) { - ERR_FAIL_COND(!tasks.has(p_task)); Task &t = tasks[p_task]; memdelete(t.vb); tasks.erase(p_task); - if (tasks.empty()) + if (tasks.empty()) { hide(); - else + } else { _popup(); + } } void ProgressDialog::_cancel_pressed() { @@ -245,11 +230,9 @@ void ProgressDialog::_cancel_pressed() { } void ProgressDialog::_bind_methods() { - ClassDB::bind_method("_cancel_pressed", &ProgressDialog::_cancel_pressed); } ProgressDialog::ProgressDialog() { - main = memnew(VBoxContainer); add_child(main); main->set_anchors_and_margins_preset(Control::PRESET_WIDE); @@ -264,5 +247,5 @@ ProgressDialog::ProgressDialog() { cancel_hb->add_child(cancel); cancel->set_text(TTR("Cancel")); cancel_hb->add_spacer(); - cancel->connect("pressed", this, "_cancel_pressed"); + cancel->connect("pressed", callable_mp(this, &ProgressDialog::_cancel_pressed)); } |