new BLF functions
authorCampbell Barton <ideasman42@gmail.com>
Wed, 4 May 2011 15:09:48 +0000 (15:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 4 May 2011 15:09:48 +0000 (15:09 +0000)
- BLF_height_max
- BLF_width_max
- BLF_descender
- BLF_ascender

use for tooltip and image stamp.

source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf.c
source/blender/blenkernel/intern/image.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/editors/interface/interface_regions.c

index 44d3cf2c61bdc874253e10dbe84462a569d85f8a..57f8c83eda61963661a2820cb9d2e7ecaa65b022 100644 (file)
@@ -90,6 +90,14 @@ void BLF_boundbox(int fontid, const char *str, struct rctf *box);
 float BLF_width(int fontid, const char *str);
 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.
index 5db71948024987837688670125a4a7a480d92947..c0e62b1c0c70340d72bcf2b58efbebc2ecc8c33d 100644 (file)
@@ -580,6 +580,54 @@ float BLF_height(int fontid, const char *str)
        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;
index 5b230ad70236503ca937fbba333430bda145ae76..22d19c5484f349802b0545075ad90f5308261908 100644 (file)
@@ -1011,7 +1011,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
        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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
        
        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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
                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 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
 
        /* 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)
index 216935a2bf46716b0c1b5e430d9c34308abbb937..5763fcde7057443c5a4598adfab448cf0454871b 100644 (file)
@@ -1144,16 +1144,9 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode)
                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]);
index c3ecbd6929cb8ab7eeb2739b5e344360226d1d70..a4c2dbb99437c0b82e8285e52a1ee697a6d2b77f 100644 (file)
@@ -485,18 +485,17 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
        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 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
        data->toth= fonth;
        data->lineh= h;
-       data->spaceh= 5;
+       data->spaceh= TIP_MARGIN_Y;
+
 
        /* compute position */
        ofsx= (but->block->panel)? but->block->panel->ofsx: 0;
        ofsy= (but->block->panel)? but->block->panel->ofsy: 0;
 
-       x1f= (but->x1+but->x2)/2.0f + ofsx - 16.0f*aspect;
-       x2f= x1f + fontw + 16.0f*aspect;
-       y2f= but->y1 + ofsy - 15.0f*aspect;
-       y1f= y2f - fonth*aspect - 15.0f*aspect;
+       x1f= (but->x1 + but->x2) * 0.5f + ofsx - (TIP_BORDER_X * aspect);
+       x2f= x1f + fontw + (TIP_BORDER_X * aspect);
+       y2f= but->y1 + ofsy - (TIP_BORDER_Y * aspect);
+       y1f= y2f - fonth*aspect - (TIP_BORDER_Y * aspect);
        
+#undef TIP_MARGIN_Y
+#undef TIP_BORDER_X
+#undef TIP_BORDER_Y
+
        /* copy to int, gets projected if possible too */
        x1= x1f; y1= y1f; x2= x2f; y2= y2f;