[Bf-blender-cvs] [18fe107] temp-blf-wordwrap: Multi-line tooltip support

Campbell Barton noreply at git.blender.org
Sat Aug 29 12:50:25 CEST 2015


Commit: 18fe107758e85aaed13dc74330e2dffa767c7a9f
Author: Campbell Barton
Date:   Sat Aug 29 20:44:34 2015 +1000
Branches: temp-blf-wordwrap
https://developer.blender.org/rB18fe107758e85aaed13dc74330e2dffa767c7a9f

Multi-line tooltip support

===================================================================

M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/interface/interface_style.c
M	source/blender/editors/render/render_internal.c

===================================================================

diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index c9b15f0..a76c7c4 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -148,13 +148,14 @@ static void ui_region_temp_remove(bContext *C, bScreen *sc, ARegion *ar)
 
 #define UI_TIP_PAD_FAC      1.3f
 #define UI_TIP_PADDING      (int)(UI_TIP_PAD_FAC * UI_UNIT_Y)
+#define UI_TIP_MAXWIDTH     500
 
 #define MAX_TOOLTIP_LINES 8
 typedef struct uiTooltipData {
 	rcti bbox;
 	uiFontStyle fstyle;
-	char lines[MAX_TOOLTIP_LINES][512];
-	char header[512], active_info[512];
+	char lines[MAX_TOOLTIP_LINES][2048];
+	char header[2048], active_info[2048];
 	struct {
 		enum {
 			UI_TIP_STYLE_NORMAL = 0,
@@ -170,6 +171,7 @@ typedef struct uiTooltipData {
 			UI_TIP_LC_ALERT,        /* description of why operator can't run */
 		} color_id : 4;
 		int is_pad : 1;
+		unsigned char lines_wrap;
 	} format[MAX_TOOLTIP_LINES];
 	int totline;
 	int toth, lineh;
@@ -250,12 +252,14 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 	rgb_tint(alert_color,  0.0f, 0.8f, tone_bg, 0.1f);  /* red        */
 
 	/* draw text */
+	BLF_wordwrap_width(data->fstyle.uifont_id, UI_TIP_MAXWIDTH * U.pixelsize);
+	BLF_wordwrap_width(blf_mono_font, UI_TIP_MAXWIDTH * U.pixelsize);
 
 	bbox.xmin += 0.5f * pad_px;  /* add padding to the text */
-	bbox.ymax -= 0.5f * (BLI_rcti_size_y(&bbox) - data->toth);
-	bbox.ymin = bbox.ymax - data->lineh;
+	bbox.ymax -= 0.25f * pad_px;
 
 	for (i = 0; i < data->totline; i++) {
+		bbox.ymin = bbox.ymax - (data->lineh * data->format[i].lines_wrap);
 		if (data->format[i].style == UI_TIP_STYLE_HEADER) {
 			/* draw header and active data (is done here to be able to change color) */
 			uiFontStyle fstyle_header = data->fstyle;
@@ -266,6 +270,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 			fstyle_header.shadowcolor = rgb_to_grayscale(tip_colors[UI_TIP_LC_MAIN]);
 			fstyle_header.shadx = fstyle_header.shady = 0;
 			fstyle_header.shadowalpha = 1.0f;
+			fstyle_header.word_wrap = true;
 
 			UI_fontstyle_set(&fstyle_header);
 			glColor3fv(tip_colors[UI_TIP_LC_MAIN]);
@@ -282,6 +287,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 		else if (data->format[i].style == UI_TIP_STYLE_MONO) {
 			uiFontStyle fstyle_mono = data->fstyle;
 			fstyle_mono.uifont_id = blf_mono_font;
+			fstyle_mono.word_wrap = true;
 
 			UI_fontstyle_set(&fstyle_mono);
 			/* XXX, needed because we dont have mono in 'U.uifonts' */
@@ -290,22 +296,26 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 			UI_fontstyle_draw(&fstyle_mono, &bbox, data->lines[i]);
 		}
 		else {
+			uiFontStyle fstyle_normal = data->fstyle;
 			BLI_assert(data->format[i].style == UI_TIP_STYLE_NORMAL);
+			fstyle_normal.word_wrap = true;
+
 			/* draw remaining data */
-			UI_fontstyle_set(&data->fstyle);
+			UI_fontstyle_set(&fstyle_normal);
 			glColor3fv(tip_colors[data->format[i].color_id]);
 			UI_fontstyle_draw(&data->fstyle, &bbox, data->lines[i]);
 		}
+
+		bbox.ymax -= data->lineh * data->format[i].lines_wrap;
+
 		if ((i + 1 != data->totline) && data->format[i + 1].is_pad) {
-			bbox.ymax -= data->lineh * UI_TIP_PAD_FAC;
-			bbox.ymin -= data->lineh * UI_TIP_PAD_FAC;
-		}
-		else {
-			bbox.ymax -= data->lineh;
-			bbox.ymin -= data->lineh;
+			bbox.ymax -= data->lineh * (UI_TIP_PAD_FAC - 1);
 		}
 	}
 
+	BLF_disable(data->fstyle.uifont_id, BLF_WORDWRAP);
+	BLF_disable(blf_mono_font, BLF_WORDWRAP);
+
 	if (multisample_enabled)
 		glEnable(GL_MULTISAMPLE_ARB);
 }
@@ -331,10 +341,11 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 	char buf[512];
 	/* aspect values that shrink text are likely unreadable */
 	const float aspect = min_ff(1.0f, but->block->aspect);
-	float fonth, fontw;
+	int fonth, fontw;
 	int winx, ofsx, ofsy, w = 0, h, i;
 	rctf rect_fl;
 	rcti rect_i;
+	int font_flag = 0;
 
 	uiStringInfo but_tip = {BUT_GET_TIP, NULL};
 	uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, NULL};
@@ -570,6 +581,15 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
 	UI_fontstyle_set(&data->fstyle);
 
+	font_flag |= BLF_WORDWRAP;
+	if (data->fstyle.kerning == 1) {
+		font_flag |= BLF_KERNING_DEFAULT;
+	}
+	BLF_enable(data->fstyle.uifont_id, font_flag);
+	BLF_enable(blf_mono_font, font_flag);
+	BLF_wordwrap_width(data->fstyle.uifont_id, UI_TIP_MAXWIDTH * U.pixelsize);
+	BLF_wordwrap_width(blf_mono_font, UI_TIP_MAXWIDTH * U.pixelsize);
+
 	/* these defines tweaked depending on font */
 #define TIP_BORDER_X (16.0f / aspect)
 #define TIP_BORDER_Y (6.0f / aspect)
@@ -577,33 +597,38 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 	h = BLF_height_max(data->fstyle.uifont_id);
 
 	for (i = 0, fontw = 0, fonth = 0; i < data->totline; i++) {
+		int lines_wrap = 1;
 		if (data->format[i].style == UI_TIP_STYLE_HEADER) {
-			w = BLF_width(data->fstyle.uifont_id, data->header, sizeof(data->header));
+			w = BLF_width_ex(data->fstyle.uifont_id, data->header, sizeof(data->header), &lines_wrap);
 			if (enum_label.strinfo)
 				w += BLF_width(data->fstyle.uifont_id, data->active_info, sizeof(data->active_info));
 		}
 		else if (data->format[i].style == UI_TIP_STYLE_MONO) {
 			BLF_size(blf_mono_font, data->fstyle.points * U.pixelsize, U.dpi);
 
-			w = BLF_width(blf_mono_font, data->lines[i], sizeof(data->lines[i]));
+			w = BLF_width_ex(blf_mono_font, data->lines[i], sizeof(data->lines[i]), &lines_wrap);
 		}
 		else {
 			BLI_assert(data->format[i].style == UI_TIP_STYLE_NORMAL);
-			w = BLF_width(data->fstyle.uifont_id, data->lines[i], sizeof(data->lines[i]));
+
+			w = BLF_width_ex(data->fstyle.uifont_id, data->lines[i], sizeof(data->lines[i]), &lines_wrap);
 		}
 
-		fontw = max_ff(fontw, (float)w);
+		fontw = max_ii(fontw, w);
 
+		fonth += h * lines_wrap;
 		if ((i + 1 != data->totline) && data->format[i + 1].is_pad) {
-			fonth += h * UI_TIP_PAD_FAC;
-		}
-		else {
-			fonth += h;
+			fonth += h * (UI_TIP_PAD_FAC - 1);
 		}
+
+		data->format[i].lines_wrap = lines_wrap;
 	}
 
 	//fontw *= aspect;
 
+	BLF_disable(data->fstyle.uifont_id, font_flag);
+	BLF_disable(blf_mono_font, font_flag);
+
 	ar->regiondata = data;
 
 	data->toth = fonth;
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 8b922ab..c137a03 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -152,7 +152,6 @@ void UI_fontstyle_draw_ex(
         const uiFontStyle *fs, const rcti *rect, const char *str,
         size_t len, float *r_xofs, float *r_yofs)
 {
-	float height;
 	int xofs = 0, yofs;
 	int font_flag = BLF_CLIPPING;
 	
@@ -173,8 +172,7 @@ void UI_fontstyle_draw_ex(
 
 	BLF_enable(fs->uifont_id, font_flag);
 
-	height = BLF_ascender(fs->uifont_id);
-	yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
+	yofs = ceil(BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id));
 
 	if (fs->align == UI_STYLE_TEXT_CENTER) {
 		xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len)));
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index 755b8dd..40c9a62 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -1000,7 +1000,7 @@ void RENDER_OT_render(wmOperatorType *ot)
 
 	/* identifiers */
 	ot->name = "Render";
-	ot->description = "Render active scene";
+	ot->description = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed qui [...]
 	ot->idname = "RENDER_OT_render";
 
 	/* api callbacks */




More information about the Bf-blender-cvs mailing list