[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36487] trunk/blender/source/blender: new BLF functions
Campbell Barton
ideasman42 at gmail.com
Wed May 4 17:09:49 CEST 2011
Revision: 36487
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36487
Author: campbellbarton
Date: 2011-05-04 15:09:48 +0000 (Wed, 04 May 2011)
Log Message:
-----------
new BLF functions
- BLF_height_max
- BLF_width_max
- BLF_descender
- BLF_ascender
use for tooltip and image stamp.
Modified Paths:
--------------
trunk/blender/source/blender/blenfont/BLF_api.h
trunk/blender/source/blender/blenfont/intern/blf.c
trunk/blender/source/blender/blenkernel/intern/image.c
trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
trunk/blender/source/blender/editors/interface/interface_regions.c
Modified: trunk/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_api.h 2011-05-04 14:01:38 UTC (rev 36486)
+++ trunk/blender/source/blender/blenfont/BLF_api.h 2011-05-04 15:09:48 UTC (rev 36487)
@@ -91,6 +91,14 @@
float BLF_height(int fontid, const char *str);
/*
+ * Return dimensions of the font without any sample text.
+ */
+float BLF_height_max(int fontid);
+float BLF_width_max(int fontid);
+float BLF_descender(int fontid);
+float BLF_ascender(int fontid);
+
+/*
* The following function return the width and height of the string, but
* just in one call, so avoid extra freetype2 stuff.
*/
Modified: trunk/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf.c 2011-05-04 14:01:38 UTC (rev 36486)
+++ trunk/blender/source/blender/blenfont/intern/blf.c 2011-05-04 15:09:48 UTC (rev 36487)
@@ -580,6 +580,54 @@
return(0.0f);
}
+float BLF_height_max(int fontid)
+{
+ FontBLF *font;
+
+ font= BLF_get(fontid);
+ if (font) {
+ if(font->glyph_cache)
+ return(font->glyph_cache->max_glyph_height);
+ }
+ return(0.0f);
+}
+
+float BLF_width_max(int fontid)
+{
+ FontBLF *font;
+
+ font= BLF_get(fontid);
+ if (font) {
+ if(font->glyph_cache)
+ return(font->glyph_cache->max_glyph_width);
+ }
+ return(0.0f);
+}
+
+float BLF_descender(int fontid)
+{
+ FontBLF *font;
+
+ font= BLF_get(fontid);
+ if (font) {
+ if(font->glyph_cache)
+ return(font->glyph_cache->descender);
+ }
+ return(0.0f);
+}
+
+float BLF_ascender(int fontid)
+{
+ FontBLF *font;
+
+ font= BLF_get(fontid);
+ if (font) {
+ if(font->glyph_cache)
+ return(font->glyph_cache->ascender);
+ }
+ return(0.0f);
+}
+
float BLF_height_default(const char *str)
{
float height;
Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c 2011-05-04 14:01:38 UTC (rev 36486)
+++ trunk/blender/source/blender/blenkernel/intern/image.c 2011-05-04 15:09:48 UTC (rev 36487)
@@ -1011,7 +1011,10 @@
int x, y, y_ofs;
float h_fixed;
const int mono= blf_mono_font_render; // XXX
-
+
+#define BUFF_MARGIN_X 2
+#define BUFF_MARGIN_Y 1
+
if (!rect && !rectf)
return;
@@ -1026,23 +1029,11 @@
BLF_buffer(mono, rectf, rect, width, height, channels);
BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0);
- pad= BLF_width(mono, "--");
+ pad= BLF_width_max(mono);
/* use 'h_fixed' rather then 'h', aligns better */
- // BLF_width_and_height(mono, "^|/_AgPpJjlYy", &w, &h_fixed);
- {
- rctf box;
- float baseline;
- BLF_boundbox(mono, "^|/_AgPpJjlYy", &box);
- h_fixed= box.ymax - box.ymin;
-
- /* crude way to get the decent line from A->j*/
- BLF_boundbox(mono, "A", &box);
- baseline= box.ymin;
- BLF_boundbox(mono, "j", &box);
- y_ofs = (int)(baseline - box.ymin);
- if(y_ofs < 0) y_ofs= 0; /* should never happen */
- }
+ h_fixed= BLF_height_max(mono);
+ y_ofs = -BLF_descender(mono);
x= 0;
y= height;
@@ -1053,14 +1044,14 @@
y -= h;
/* also a little of space to the background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, w+3, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and draw the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.file);
/* the extra pixel for background. */
- y -= 5;
+ y -= BUFF_MARGIN_Y * 2;
}
/* Top left corner, below File */
@@ -1069,13 +1060,13 @@
y -= h;
/* and space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 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);
/* the extra pixel for background. */
- y -= 5;
+ y -= BUFF_MARGIN_Y * 2;
}
/* Top left corner, below File (or Note) */
@@ -1084,13 +1075,13 @@
y -= h;
/* and space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 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);
/* the extra pixel for background. */
- y -= 5;
+ y -= BUFF_MARGIN_Y * 2;
}
/* Top left corner, below File, Date or Note */
@@ -1099,7 +1090,7 @@
y -= h;
/* and space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-3, w+3, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 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);
@@ -1113,7 +1104,7 @@
BLF_width_and_height(mono, stamp_data.marker, &w, &h); h= h_fixed;
/* extra space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, w+2, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
@@ -1128,7 +1119,7 @@
BLF_width_and_height(mono, stamp_data.time, &w, &h); h= h_fixed;
/* extra space for background */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
@@ -1142,7 +1133,7 @@
BLF_width_and_height(mono, stamp_data.frame, &w, &h); h= h_fixed;
/* extra space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
@@ -1156,7 +1147,7 @@
BLF_width_and_height(mono, stamp_data.camera, &w, &h); h= h_fixed;
/* extra space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.camera);
@@ -1168,7 +1159,7 @@
BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h= h_fixed;
/* extra space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+2, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.cameralens);
}
@@ -1180,7 +1171,7 @@
x= width - w - 2;
/* extra space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y, x+w+3, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
/* and pad the text. */
BLF_position(mono, x, y+y_ofs, 0.0);
@@ -1195,7 +1186,7 @@
y= height - h;
/* extra space for background. */
- buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x, y-3, x+w+pad, y+h+2);
+ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
BLF_draw_buffer(mono, stamp_data.strip);
@@ -1203,6 +1194,9 @@
/* cleanup the buffer. */
BLF_buffer(mono, NULL, NULL, 0, 0, 0);
+
+#undef BUFF_MARGIN_X
+#undef BUFF_MARGIN_Y
}
void BKE_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf)
Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c 2011-05-04 14:01:38 UTC (rev 36486)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c 2011-05-04 15:09:48 UTC (rev 36487)
@@ -1144,16 +1144,9 @@
switch (p->sa->spacetype) {
case SPACE_VIEW3D:
{
- View3D *v3d= p->sa->spacedata.first;
RegionView3D *rv3d= p->ar->regiondata;
float rvec[3];
- /* for camera view set the subrect */
- if (rv3d->persp == RV3D_CAMOB) {
- view3d_calc_camera_border(p->scene, p->ar, NULL, v3d, &p->subrect_data, -1); /* negative shift */
- p->subrect= &p->subrect_data;
- }
-
/* get reference point for 3d space placement */
gp_get_3d_reference(p, rvec);
initgrabz(rv3d, rvec[0], rvec[1], rvec[2]);
Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c 2011-05-04 14:01:38 UTC (rev 36486)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c 2011-05-04 15:09:48 UTC (rev 36487)
@@ -485,18 +485,17 @@
data->fstyle.align= UI_STYLE_TEXT_CENTER;
uiStyleFontSet(&data->fstyle);
- /* clipping is very strict & gives problems in some cases [#27218]
- * use the tallest line height. */
- h= 0;
- for(a=0; a<data->totline; a++) {
- int h_tmp= BLF_height(data->fstyle.uifont_id, data->lines[a]);
- h= MAX2(h, h_tmp);
- }
+ /* these defines may need to be tweaked depending on font */
+#define TIP_MARGIN_Y 2
+#define TIP_BORDER_X 16.0f
+#define TIP_BORDER_Y 6.0f
+ h= BLF_height_max(data->fstyle.uifont_id);
+
for(a=0, fontw=0, fonth=0; a<data->totline; a++) {
w= BLF_width(data->fstyle.uifont_id, data->lines[a]);
fontw= MAX2(fontw, w);
- fonth += (a == 0)? h: h+5;
+ fonth += (a == 0)? h: h+TIP_MARGIN_Y;
}
fontw *= aspect;
@@ -505,17 +504,22 @@
data->toth= fonth;
data->lineh= h;
- data->spaceh= 5;
+ data->spaceh= TIP_MARGIN_Y;
+
/* compute position */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list