[Bf-blender-cvs] [129355c80a5] blender2.8: Multiline support for ED_region_info_draw
Dalai Felinto
noreply at git.blender.org
Thu May 4 22:28:56 CEST 2017
Commit: 129355c80a5eac7c48f3f61fe5a2a7f94ab836f0
Author: Dalai Felinto
Date: Thu May 4 21:56:34 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB129355c80a5eac7c48f3f61fe5a2a7f94ab836f0
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.
===================================================================
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/include/ED_screen.h
M source/blender/editors/screen/area.c
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index dd2ebea59ae..3aa3eb20b90 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -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");
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 74cfe13e1dc..1208b1f31b6 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -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);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 51dcdf2e999..3b933b0182a 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -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[] =
More information about the Bf-blender-cvs
mailing list