Multiline support for ED_region_info_draw
Many thanks for Campbell Barton for the help here and the idea to implement the multi-line as a new function with array as arguments.
This commit is contained in:
parent
6f5307e74d
commit
129355c80a
Notes:
blender-bot
2023-02-14 07:00:21 +01:00
Referenced by issue #51391, Fix Cycles render stats on render preview
|
@ -2056,6 +2056,8 @@ static void DRW_engines_draw_text(void)
|
|||
}
|
||||
}
|
||||
|
||||
#define MAX_INFO_LINES 10
|
||||
|
||||
/**
|
||||
* Returns the offset required for the drawing of engines info.
|
||||
*/
|
||||
|
@ -2077,7 +2079,7 @@ int DRW_draw_region_engine_info_offset()
|
|||
}
|
||||
}
|
||||
}
|
||||
return lines * UI_UNIT_Y;
|
||||
return MIN2(MAX_INFO_LINES, lines) * UI_UNIT_Y;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2085,8 +2087,9 @@ int DRW_draw_region_engine_info_offset()
|
|||
*/
|
||||
void DRW_draw_region_engine_info()
|
||||
{
|
||||
char info[GPU_INFO_SIZE * 5] = {0}; /* This should be maxium number of engines running at the same time. */
|
||||
char *str_start = info;
|
||||
const char *info_array_final[MAX_INFO_LINES + 1];
|
||||
char info_array[MAX_INFO_LINES][GPU_INFO_SIZE]; /* This should be maxium number of engines running at the same time. */
|
||||
int i = 0;
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
ARegion *ar = draw_ctx->ar;
|
||||
|
@ -2100,20 +2103,40 @@ void DRW_draw_region_engine_info()
|
|||
ViewportEngineData *data = DRW_viewport_engine_data_get(engine);
|
||||
|
||||
if (data->info[0] != '\0') {
|
||||
BLI_strncpy(str_start, data->info, sizeof(info) - (str_start - info));
|
||||
str_start += BLI_strnlen(data->info, sizeof(data->info));
|
||||
*str_start++ = '\n';
|
||||
char *chr_current = data->info;
|
||||
char *chr_start = chr_current;
|
||||
int line_len = 0;
|
||||
|
||||
while (*chr_current++ != '\0') {
|
||||
line_len++;
|
||||
if (*chr_current == '\n') {
|
||||
BLI_strncpy(info_array[i++], chr_start, line_len + 1);
|
||||
/* Re-start counting. */
|
||||
chr_start = chr_current + 1;
|
||||
line_len = -1;
|
||||
}
|
||||
}
|
||||
|
||||
BLI_strncpy(info_array[i++], chr_start, line_len + 1);
|
||||
|
||||
if (i >= MAX_INFO_LINES) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (info[0] != '\0') {
|
||||
if (str_start != info) {
|
||||
*(str_start - 1) = '\0';
|
||||
}
|
||||
ED_region_info_draw(ar, info, fill_color, true);
|
||||
for (int j = 0; j < i; j++) {
|
||||
info_array_final[j] = info_array[j];
|
||||
}
|
||||
info_array_final[i] = NULL;
|
||||
|
||||
if (info_array[0] != NULL) {
|
||||
ED_region_info_draw_multiline(ar, info_array_final, fill_color, true);
|
||||
}
|
||||
}
|
||||
|
||||
#undef MAX_INFO_LINES
|
||||
|
||||
static void use_drw_engine(DrawEngineType *engine)
|
||||
{
|
||||
LinkData *ld = MEM_callocN(sizeof(LinkData), "enabled engine link data");
|
||||
|
|
|
@ -75,6 +75,7 @@ void ED_region_header(const struct bContext *C, struct ARegion *ar);
|
|||
void ED_region_cursor_set(struct wmWindow *win, struct ScrArea *sa, struct ARegion *ar);
|
||||
void ED_region_toggle_hidden(struct bContext *C, struct ARegion *ar);
|
||||
void ED_region_info_draw(struct ARegion *ar, const char *text, float fill_color[4], const bool full_redraw);
|
||||
void ED_region_info_draw_multiline(ARegion *ar, const char *text_array[], float fill_color[4], const bool full_redraw);
|
||||
void ED_region_image_metadata_draw(int x, int y, struct ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy);
|
||||
void ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
|
||||
float ED_region_blend_factor(struct ARegion *ar);
|
||||
|
|
|
@ -2119,22 +2119,37 @@ int ED_area_headersize(void)
|
|||
return (int)(HEADERY * UI_DPI_FAC);
|
||||
}
|
||||
|
||||
void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
|
||||
void ED_region_info_draw_multiline(ARegion *ar, const char *text_array[], float fill_color[4], const bool full_redraw)
|
||||
{
|
||||
const int header_height = UI_UNIT_Y;
|
||||
uiStyle *style = UI_style_get_dpi();
|
||||
int fontid = style->widget.uifont_id;
|
||||
GLint scissor[4];
|
||||
rcti rect;
|
||||
int num_lines = 0;
|
||||
|
||||
/* background box */
|
||||
ED_region_visible_rect(ar, &rect);
|
||||
rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
|
||||
|
||||
/* box fill entire width or just around text */
|
||||
if (!full_redraw)
|
||||
rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
|
||||
/* Box fill entire width or just around text. */
|
||||
if (!full_redraw) {
|
||||
const char **text = &text_array[0];
|
||||
while (*text) {
|
||||
rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, *text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
|
||||
text++;
|
||||
num_lines++;
|
||||
}
|
||||
}
|
||||
/* Just count the line number. */
|
||||
else {
|
||||
const char **text = &text_array[0];
|
||||
while (*text) {
|
||||
text++;
|
||||
num_lines++;
|
||||
}
|
||||
}
|
||||
|
||||
rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height * num_lines;
|
||||
rect.ymax = BLI_rcti_size_y(&ar->winrct);
|
||||
|
||||
/* setup scissor */
|
||||
|
@ -2156,9 +2171,16 @@ void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], con
|
|||
UI_FontThemeColor(fontid, TH_TEXT_HI);
|
||||
BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
|
||||
BLF_enable(fontid, BLF_CLIPPING);
|
||||
BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit, 0.0f);
|
||||
|
||||
BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
|
||||
int offset = num_lines - 1;
|
||||
{
|
||||
const char **text = &text_array[0];
|
||||
while (*text) {
|
||||
BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit + offset * header_height, 0.0f);
|
||||
BLF_draw(fontid, *text, BLF_DRAW_STR_DUMMY_MAX);
|
||||
text++;
|
||||
offset--;
|
||||
}
|
||||
}
|
||||
|
||||
BLF_disable(fontid, BLF_CLIPPING);
|
||||
|
||||
|
@ -2166,6 +2188,11 @@ void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], con
|
|||
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
|
||||
}
|
||||
|
||||
void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
|
||||
{
|
||||
ED_region_info_draw_multiline(ar, (const char *[2]){text, NULL}, fill_color, full_redraw);
|
||||
}
|
||||
|
||||
#define MAX_METADATA_STR 1024
|
||||
|
||||
static const char *meta_data_list[] =
|
||||
|
|
Loading…
Reference in New Issue