diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-02 13:33:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-02 14:10:07 +0400 |
commit | 1815225faa75eb64e83fdc9f066fcd6339502d52 (patch) | |
tree | 6558780d85792c9c41fcf280069870fae70eed7a /source/blender/blenkernel/intern/image.c | |
parent | f64ae4cbe5a724496624de9e479c04f325613be5 (diff) |
Blender Font (BLF): add length argument to string width/height functions
This also fixes a crash editing buttons longer then UI_MAX_DRAW_STR
Diffstat (limited to 'source/blender/blenkernel/intern/image.c')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index e4278bae293..d59a23c1c30 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1636,6 +1636,9 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* 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))))) + #define BUFF_MARGIN_X 2 #define BUFF_MARGIN_Y 1 @@ -1665,9 +1668,8 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x = 0; y = height; - if (stamp_data.file[0]) { + if (TEXT_SIZE_CHECK(stamp_data.file, w, h)) { /* Top left corner */ - BLF_width_and_height(mono, stamp_data.file, &w, &h); h = h_fixed; y -= h; /* also a little of space to the background. */ @@ -1683,8 +1685,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Top left corner, below File */ - if (stamp_data.note[0]) { - BLF_width_and_height(mono, stamp_data.note, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.note, w, h)) { y -= h; /* and space for background. */ @@ -1699,8 +1700,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Top left corner, below File (or Note) */ - if (stamp_data.date[0]) { - BLF_width_and_height(mono, stamp_data.date, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) { y -= h; /* and space for background. */ @@ -1715,8 +1715,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Top left corner, below File, Date or Note */ - if (stamp_data.rendertime[0]) { - BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) { y -= h; /* and space for background. */ @@ -1731,8 +1730,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec y = 0; /* Bottom left corner, leaving space for timing */ - if (stamp_data.marker[0]) { - BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.marker, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1747,8 +1745,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Left bottom corner */ - if (stamp_data.time[0]) { - BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.time, w, h)) { /* extra space for background */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1762,8 +1759,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x += w + pad; } - if (stamp_data.frame[0]) { - BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.frame, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1777,8 +1773,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x += w + pad; } - if (stamp_data.camera[0]) { - BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.camera, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1790,8 +1785,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x += w + pad; } - if (stamp_data.cameralens[0]) { - BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.cameralens, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1800,8 +1794,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec BLF_draw_buffer(mono, stamp_data.cameralens); } - if (stamp_data.scene[0]) { - BLF_width_and_height(mono, stamp_data.scene, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { /* Bottom right corner, with an extra space because blenfont is too strict! */ x = width - w - 2; @@ -1815,8 +1808,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec BLF_draw_buffer(mono, stamp_data.scene); } - if (stamp_data.strip[0]) { - BLF_width_and_height(mono, stamp_data.strip, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { /* Top right corner, with an extra space because blenfont is too strict! */ x = width - w - pad; @@ -1833,6 +1825,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* cleanup the buffer. */ BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL); +#undef TEXT_SIZE_CHECK #undef BUFF_MARGIN_X #undef BUFF_MARGIN_Y } |