diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2016-01-18 03:39:09 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2016-01-18 03:39:09 +0300 |
commit | c6bc2363e5ec96d1aba36f1e7b4d321076d3f465 (patch) | |
tree | a09fa844a679328a72c3dc3e00d8a1a9bf26a6cd /source/blender/editors/interface/interface_templates.c | |
parent | c4c2bd1350a52e18f973bba7e52e929f94ff6496 (diff) |
UI: redesign of the progress bar.
A picture is worth a thousand words: http://wiki.blender.org/index.php/
File:UI_progress_bar.png
Reviewers: #user_interface, brecht, dingto
Reviewed by: brecht, dingto
Differential Revision: https://developer.blender.org/D1727
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index ccb0c9f508d..a97f55d4749 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -45,6 +45,7 @@ #include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_fnmatch.h" +#include "BLI_timecode.h" #include "BLF_api.h" #include "BLT_translation.h" @@ -81,6 +82,8 @@ #include "UI_interface_icons.h" #include "interface_intern.h" +#include "PIL_time.h" + void UI_template_fix_linking(void) { } @@ -3383,7 +3386,7 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) ScrArea *sa = CTX_wm_area(C); uiBlock *block; void *owner = NULL; - int handle_event; + int handle_event, icon = 0; block = uiLayoutGetBlock(layout); UI_block_layout_set_current(block, layout); @@ -3394,17 +3397,20 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) if (WM_jobs_test(wm, sa, WM_JOB_TYPE_ANY)) owner = sa; handle_event = B_STOPSEQ; + icon = ICON_SEQUENCE; } else if (sa->spacetype == SPACE_CLIP) { if (WM_jobs_test(wm, sa, WM_JOB_TYPE_ANY)) owner = sa; handle_event = B_STOPCLIP; + icon = ICON_CLIP; } else if (sa->spacetype == SPACE_FILE) { if (WM_jobs_test(wm, sa, WM_JOB_TYPE_FILESEL_READDIR)) { owner = sa; } handle_event = B_STOPFILE; + icon = ICON_FILESEL; } else { Scene *scene; @@ -3412,10 +3418,12 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) for (scene = CTX_data_main(C)->scene.first; scene; scene = scene->id.next) { if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER)) { handle_event = B_STOPRENDER; + icon = ICON_SCENE; break; } else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_COMPOSITE)) { handle_event = B_STOPCOMPO; + icon = ICON_RENDERLAYERS; break; } else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_OBJECT_BAKE_TEXTURE) || @@ -3427,11 +3435,33 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) */ if (sa->spacetype != SPACE_NODE) { handle_event = B_STOPOTHER; + icon = ICON_IMAGE_COL; break; } } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_DPAINT_BAKE)) { + handle_event = B_STOPOTHER; + icon = ICON_MOD_DYNAMICPAINT; + break; + } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_POINTCACHE)) { + handle_event = B_STOPOTHER; + icon = ICON_PHYSICS; + break; + } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_OBJECT_SIM_FLUID)) { + handle_event = B_STOPOTHER; + icon = ICON_MOD_FLUIDSIM; + break; + } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_OBJECT_SIM_OCEAN)) { + handle_event = B_STOPOTHER; + icon = ICON_MOD_OCEAN; + break; + } else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) { handle_event = B_STOPOTHER; + icon = ICON_NONE; break; } } @@ -3439,18 +3469,52 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) } if (owner) { - uiLayout *ui_abs; - - ui_abs = uiLayoutAbsolute(layout, false); - (void)ui_abs; /* UNUSED */ + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + bool active = !(WM_jobs_is_stopped(wm, owner) || G.is_break); - uiDefIconBut(block, UI_BTYPE_BUT, handle_event, ICON_PANEL_CLOSE, 0, UI_UNIT_Y * 0.1, UI_UNIT_X * 0.8, UI_UNIT_Y * 0.8, - NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop this job")); - uiDefBut(block, UI_BTYPE_PROGRESS_BAR, 0, WM_jobs_name(wm, owner), - UI_UNIT_X, 0, UI_UNIT_X * 5.0f, UI_UNIT_Y, NULL, 0.0f, 0.0f, WM_jobs_progress(wm, owner), 0, TIP_("Progress")); + uiLayout *row = uiLayoutRow(layout, false); + block = uiLayoutGetBlock(row); + + /* get percentage done and set it as the UI text */ + const float progress = WM_jobs_progress(wm, owner); + char text[8]; + BLI_snprintf(text, 8, "%d%%", (int)(progress * 100)); - uiLayoutRow(layout, false); + /* create tooltip text and associate it with the job */ + + const double elapsed = PIL_check_seconds_timer() - WM_jobs_starttime(wm, owner); + const double remaining = (elapsed / progress) - elapsed; + + char remaining_str[32], elapsed_str[32]; + BLI_timecode_string_from_time_simple(remaining_str, sizeof(remaining_str), remaining); + BLI_timecode_string_from_time_simple(elapsed_str, sizeof(remaining_str), elapsed); + + char tooltip[128]; + BLI_snprintf(tooltip, sizeof(tooltip), "Time Remaining: %s\nTime Elapsed: %s", remaining_str, elapsed_str); + + WM_jobs_set_tooltip(wm, owner, tooltip); + + const char *name = active ? WM_jobs_name(wm, owner) : "Canceling..."; + + /* job name and icon */ + const int textwidth = UI_fontstyle_string_width(fstyle, name); + uiDefIconTextBut(block, UI_BTYPE_LABEL, 0, icon, name, 0, 0, + textwidth + UI_UNIT_X * 1.5f, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0.0f, 0.0f, ""); + + /* stick progress bar and cancel button together */ + row = uiLayoutRow(layout, true); + uiLayoutSetActive(row, active); + block = uiLayoutGetBlock(row); + + uiDefIconTextBut(block, UI_BTYPE_PROGRESS_BAR, 0, 0, text, + UI_UNIT_X, 0, UI_UNIT_X * 6.0f, UI_UNIT_Y, NULL, 0.0f, 0.0f, + progress, 0, WM_jobs_tooltip(wm, owner)); + + uiDefIconTextBut(block, UI_BTYPE_BUT, handle_event, ICON_PANEL_CLOSE, + "", 0, 0, UI_UNIT_X, UI_UNIT_Y, + NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop this job")); } + if (WM_jobs_test(wm, screen, WM_JOB_TYPE_SCREENCAST)) uiDefIconTextBut(block, UI_BTYPE_BUT, B_STOPCAST, ICON_CANCEL, IFACE_("Capture"), 0, 0, UI_UNIT_X * 4.25f, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop screencast")); |