WIP: Indeterminate Progress Indicators #111096
|
@ -1448,6 +1448,8 @@ enum {
|
|||
enum eButProgressType {
|
||||
UI_BUT_PROGRESS_TYPE_BAR = 0,
|
||||
UI_BUT_PROGRESS_TYPE_RING = 1,
|
||||
UI_BUT_PROGRESS_TYPE_INDETERMINATE_BAR = 3,
|
||||
UI_BUT_PROGRESS_TYPE_INDETERMINATE_RING = 4,
|
||||
};
|
||||
|
||||
/***************************** ID Utilities *******************************/
|
||||
|
|
|
@ -3487,7 +3487,7 @@ void uiItemProgressIndicator(uiLayout *layout,
|
|||
uiBlock *block = layout->root->block;
|
||||
short width;
|
||||
|
||||
if (progress_type == UI_BUT_PROGRESS_TYPE_BAR) {
|
||||
if (ELEM(progress_type, UI_BUT_PROGRESS_TYPE_BAR, UI_BUT_PROGRESS_TYPE_INDETERMINATE_BAR)) {
|
||||
width = UI_UNIT_X * 5;
|
||||
}
|
||||
else if (has_text) {
|
||||
|
@ -3513,8 +3513,10 @@ void uiItemProgressIndicator(uiLayout *layout,
|
|||
0,
|
||||
"");
|
||||
|
||||
if (has_text && (progress_type == UI_BUT_PROGRESS_TYPE_RING)) {
|
||||
/* For progress bar, centered is okay, left aligned for ring/pie. */
|
||||
if (has_text &&
|
||||
(ELEM(progress_type, UI_BUT_PROGRESS_TYPE_RING, UI_BUT_PROGRESS_TYPE_INDETERMINATE_RING)))
|
||||
{
|
||||
/* For progress bar, centered is okay, left aligned for rings. */
|
||||
but->drawflag |= UI_BUT_TEXT_LEFT;
|
||||
}
|
||||
|
||||
|
|
|
@ -3655,11 +3655,8 @@ static void widget_scroll(uiBut *but,
|
|||
UI_draw_widget_scroll(wcol, rect, &rect1, (state->but_flag & UI_SELECT) ? UI_SCROLL_PRESSED : 0);
|
||||
}
|
||||
|
||||
static void widget_progress_type_bar(uiButProgress *but_progress,
|
||||
uiWidgetColors *wcol,
|
||||
rcti *rect,
|
||||
int roundboxalign,
|
||||
const float zoom)
|
||||
static void widget_progress_type_bar(
|
||||
float start, float end, uiWidgetColors *wcol, rcti *rect, int roundboxalign, const float zoom)
|
||||
{
|
||||
rcti rect_prog = *rect, rect_bar = *rect;
|
||||
|
||||
|
@ -3668,14 +3665,16 @@ static void widget_progress_type_bar(uiButProgress *but_progress,
|
|||
widget_init(&wtb_bar);
|
||||
|
||||
/* round corners */
|
||||
const float factor = but_progress->progress_factor;
|
||||
const float ofs = widget_radius_from_zoom(zoom, wcol);
|
||||
float w = factor * BLI_rcti_size_x(&rect_prog);
|
||||
|
||||
start *= BLI_rcti_size_x(&rect_prog);
|
||||
end *= BLI_rcti_size_x(&rect_prog);
|
||||
|
||||
/* Ensure minimum size. */
|
||||
w = MAX2(w, ofs);
|
||||
end = MAX2(end, ofs);
|
||||
|
||||
rect_bar.xmax = rect_bar.xmin + w;
|
||||
rect_bar.xmin = rect_prog.xmin + start;
|
||||
rect_bar.xmax = rect_prog.xmin + end;
|
||||
|
||||
round_box_edges(&wtb, roundboxalign, &rect_prog, ofs);
|
||||
round_box_edges(&wtb_bar, roundboxalign, &rect_bar, ofs);
|
||||
|
@ -3689,19 +3688,17 @@ static void widget_progress_type_bar(uiButProgress *but_progress,
|
|||
}
|
||||
|
||||
/**
|
||||
* Used for both ring & pie types.
|
||||
* Used for both determinate and indeterminate ring types.
|
||||
*/
|
||||
static void widget_progress_type_ring(uiButProgress *but_progress,
|
||||
uiWidgetColors *wcol,
|
||||
rcti *rect)
|
||||
static void widget_progress_type_ring(float start, float end, uiWidgetColors *wcol, rcti *rect)
|
||||
{
|
||||
const float ring_width = 0.6; /* 0.0 would be a pie. */
|
||||
const float outer_rad = (rect->ymax - rect->ymin) / 2.0f;
|
||||
const float inner_rad = outer_rad * ring_width;
|
||||
const float x = rect->xmin + outer_rad;
|
||||
const float y = rect->ymin + outer_rad;
|
||||
const float start = 0.0f;
|
||||
const float end = but_progress->progress_factor * 360.0f;
|
||||
start *= 360.0f;
|
||||
end *= 360.0f;
|
||||
GPUVertFormat *format = immVertexFormat();
|
||||
const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
|
@ -3716,13 +3713,9 @@ static void widget_progress_type_ring(uiButProgress *but_progress,
|
|||
outer_rad,
|
||||
48,
|
||||
start,
|
||||
end);
|
||||
end - start);
|
||||
}
|
||||
immUnbindProgram();
|
||||
|
||||
if (but_progress->drawstr[0]) {
|
||||
rect->xmin += UI_UNIT_X;
|
||||
}
|
||||
}
|
||||
|
||||
static void widget_progress_indicator(uiBut *but,
|
||||
|
@ -3735,11 +3728,30 @@ static void widget_progress_indicator(uiBut *but,
|
|||
uiButProgress *but_progress = static_cast<uiButProgress *>(but);
|
||||
switch (but_progress->progress_type) {
|
||||
case UI_BUT_PROGRESS_TYPE_BAR: {
|
||||
widget_progress_type_bar(but_progress, wcol, rect, roundboxalign, zoom);
|
||||
widget_progress_type_bar(
|
||||
0.0f, MIN2(but_progress->progress_factor, 1.0f), wcol, rect, roundboxalign, zoom);
|
||||
break;
|
||||
}
|
||||
case UI_BUT_PROGRESS_TYPE_INDETERMINATE_BAR: {
|
||||
float end = fmod(but_progress->progress_factor, 1.0f);
|
||||
float start = MAX2(end - (1 - end), 0.0f);
|
||||
widget_progress_type_bar(start, end, wcol, rect, roundboxalign, zoom);
|
||||
break;
|
||||
}
|
||||
case UI_BUT_PROGRESS_TYPE_RING: {
|
||||
widget_progress_type_ring(but_progress, wcol, rect);
|
||||
widget_progress_type_ring(0.0f, MIN2(but_progress->progress_factor, 1.0f), wcol, rect);
|
||||
if (but_progress->drawstr[0]) {
|
||||
rect->xmin += UI_UNIT_X;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UI_BUT_PROGRESS_TYPE_INDETERMINATE_RING: {
|
||||
float end = fmod(but_progress->progress_factor, 1.0f);
|
||||
float start = MAX2(end - (1 - end), 0.0f);
|
||||
widget_progress_type_ring(start, end, wcol, rect);
|
||||
if (but_progress->drawstr[0]) {
|
||||
rect->xmin += UI_UNIT_X;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -987,6 +987,8 @@ void RNA_api_ui_layout(StructRNA *srna)
|
|||
static const EnumPropertyItem progress_type_items[] = {
|
||||
{UI_BUT_PROGRESS_TYPE_BAR, "BAR", 0, "Bar", ""},
|
||||
{UI_BUT_PROGRESS_TYPE_RING, "RING", 0, "Ring", ""},
|
||||
{UI_BUT_PROGRESS_TYPE_INDETERMINATE_BAR, "INDETERMINATE_BAR", 0, "Indeterminate Bar", ""},
|
||||
{UI_BUT_PROGRESS_TYPE_INDETERMINATE_RING, "INDETERMINATE_RING", 0, "Indeterminate Ring", ""},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue