[Bf-blender-cvs] [8993636] temp-blf-wordwrap: Support multi-line note stamp

Campbell Barton noreply at git.blender.org
Thu Sep 17 21:57:19 CEST 2015


Commit: 8993636da86ab11ee4ee9d9bfb003ecbcf3a8d8c
Author: Campbell Barton
Date:   Fri Sep 18 05:50:16 2015 +1000
Branches: temp-blf-wordwrap
https://developer.blender.org/rB8993636da86ab11ee4ee9d9bfb003ecbcf3a8d8c

Support multi-line note stamp

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

M	source/blender/blenkernel/intern/image.c

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

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index ec80ea1..241d00d 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1872,12 +1872,24 @@ void BKE_image_stamp_buf(
 	struct ColorManagedDisplay *display;
 	const char *display_device;
 
+	/* vars for calculating wordwrap */
+	struct {
+		struct ResultBLF info;
+		rctf rect;
+	} wrap;
+
 	/* this could be an argument if we want to operate on non linear float imbuf's
 	 * for now though this is only used for renders which use scene settings */
 
 #define TEXT_SIZE_CHECK(str, w, h) \
 	((str[0]) && ((void)(h = h_fixed), (w = BLF_width(mono, str, sizeof(str)))))
 
+	/* must enable BLF_WORD_WRAP before using */
+
+#define TEXT_SIZE_CHECK_WORD_WRAP(str, w, h) \
+	((str[0]) && (BLF_boundbox_ex(mono, str, sizeof(str), &wrap.rect, &wrap.info), \
+	 (void)(h = h_fixed * wrap.info.lines), (w = BLI_rctf_size_x(&wrap.rect))))
+
 #define BUFF_MARGIN_X 2
 #define BUFF_MARGIN_Y 1
 
@@ -1924,7 +1936,7 @@ void BKE_image_stamp_buf(
 	}
 
 	/* Top left corner, below File */
-	if (TEXT_SIZE_CHECK(stamp_data.note, w, h)) {
+	if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) {
 		y -= h;
 
 		/* and space for background. */
@@ -1932,14 +1944,14 @@ void BKE_image_stamp_buf(
 		                  0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
 
 		BLF_position(mono, x, y + y_ofs, 0.0);
-		BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note));
+		BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date));
 
 		/* the extra pixel for background. */
 		y -= BUFF_MARGIN_Y * 2;
 	}
 
-	/* Top left corner, below File (or Note) */
-	if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) {
+	/* Top left corner, below File, Date */
+	if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) {
 		y -= h;
 
 		/* and space for background. */
@@ -1947,23 +1959,25 @@ void BKE_image_stamp_buf(
 		                  0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
 
 		BLF_position(mono, x, y + y_ofs, 0.0);
-		BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date));
+		BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime));
 
 		/* the extra pixel for background. */
 		y -= BUFF_MARGIN_Y * 2;
 	}
 
-	/* Top left corner, below File, Date or Note */
-	if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) {
+	/* Top left corner, below File, Date, Rendertime */
+	BLF_enable(mono, BLF_WORD_WRAP);
+	if (TEXT_SIZE_CHECK_WORD_WRAP(stamp_data.note, w, h)) {
 		y -= h;
 
 		/* and space for background. */
 		buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
 		                  0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
 
-		BLF_position(mono, x, y + y_ofs, 0.0);
-		BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime));
+		BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0);
+		BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note));
 	}
+	BLF_disable(mono, BLF_WORD_WRAP);
 
 	x = 0;
 	y = 0;
@@ -2065,6 +2079,7 @@ void BKE_image_stamp_buf(
 	BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL);
 
 #undef TEXT_SIZE_CHECK
+#undef TEXT_SIZE_CHECK_WORD_WRAP
 #undef BUFF_MARGIN_X
 #undef BUFF_MARGIN_Y
 }




More information about the Bf-blender-cvs mailing list