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:
Dalai Felinto
2017-05-04 21:56:34 +02:00
parent 6f5307e74d
commit 129355c80a
3 changed files with 70 additions and 19 deletions

View File

@@ -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");