diff options
author | Matt Ebb <matt@mke3.net> | 2007-08-20 05:02:12 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2007-08-20 05:02:12 +0400 |
commit | 21c567854a35588aef445495d17706ff6c7d2245 (patch) | |
tree | 14bbfe1afaac5d2eb8660e7b0c46c2dec61ba548 /source/blender | |
parent | 4ef547a79d0bf4282c72b61b87e46dd148640f13 (diff) |
Patch #6770 by James C (sheep)
Tooltip getStringSize and getBoundingBox correction
Not really any user-visible changes here, but a nice clean-up of
internal font drawing functions, in this case used in tooltips.
Thanks!
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/ftfont/FTF_Api.h | 12 | ||||
-rw-r--r-- | source/blender/ftfont/intern/FTF_TTFont.h | 11 | ||||
-rw-r--r-- | source/blender/include/BIF_language.h | 3 | ||||
-rw-r--r-- | source/blender/src/interface.c | 41 | ||||
-rw-r--r-- | source/blender/src/language.c | 16 |
5 files changed, 47 insertions, 36 deletions
diff --git a/source/blender/ftfont/FTF_Api.h b/source/blender/ftfont/FTF_Api.h index b370c18f89e..0793c4b6dfb 100644 --- a/source/blender/ftfont/FTF_Api.h +++ b/source/blender/ftfont/FTF_Api.h @@ -106,12 +106,12 @@ FTF_EXPORT float FTF_GetStringWidth(char* str, unsigned int flag); /** * Get Bounding Box - * @param llx - * @param lly - * @param llz - * @param urx - * @param ury - * @param urz + * @param llx Lower left near x coord + * @param lly Lower left near y coord + * @param llz Lower left near z coord + * @param urx Upper right far x coord + * @param ury Upper right far y coord + * @param urz Upper right far z coord * @param mode flag to forward to FTF_TransConvString() * not test yet. */ diff --git a/source/blender/ftfont/intern/FTF_TTFont.h b/source/blender/ftfont/intern/FTF_TTFont.h index c4dee93c5dc..b5ff1cc54bf 100644 --- a/source/blender/ftfont/intern/FTF_TTFont.h +++ b/source/blender/ftfont/intern/FTF_TTFont.h @@ -78,6 +78,17 @@ public: float GetStringWidth(char* str, unsigned int flag); + /** + * Get the bounding box for a string. + * + * @param str The string + * @param llx Lower left near x coord + * @param lly Lower left near y coord + * @param llz Lower left near z coord + * @param urx Upper right far x coord + * @param ury Upper right far y coord + * @param urz Upper right far z coord + */ void GetBoundingBox(char* str, float *llx, float *lly, float *llz, float *urx, float *ury, float *urz, unsigned int flag); /** diff --git a/source/blender/include/BIF_language.h b/source/blender/include/BIF_language.h index 9a6ddfc7fc5..6ed8a8d1574 100644 --- a/source/blender/include/BIF_language.h +++ b/source/blender/include/BIF_language.h @@ -33,6 +33,8 @@ #ifndef BIF_LANGUAGE_H #define BIF_LANGUAGE_H +#include "DNA_vec_types.h" + struct BMF_Font; int read_languagefile(void); /* usiblender.c */ @@ -47,6 +49,7 @@ char *fontsize_pup(void); int BIF_DrawString(struct BMF_Font* font, char *str, int translate); float BIF_GetStringWidth(struct BMF_Font* font, char *str, int translate); +void BIF_GetBoundingBox(struct BMF_Font* font, char* str, int translate, rctf* bbox); void BIF_RasterPos(float x, float y); void BIF_SetScale(float aspect); diff --git a/source/blender/src/interface.c b/source/blender/src/interface.c index 56e2c6326b7..0eb018522bf 100644 --- a/source/blender/src/interface.c +++ b/source/blender/src/interface.c @@ -4805,30 +4805,15 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but) { uiOverDraw *od; float x1, x2, y1, y2; + rctf tip_bbox; -#ifdef INTERNATIONAL - if(G.ui_international == TRUE) { - float llx,lly,llz,urx,ury,urz; //for FTF_GetBoundingBox() - - if(U.transopts & USER_TR_TOOLTIPS) { - FTF_GetBoundingBox(but->tip, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8); - - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_USE_GETTEXT | FTF_INPUT_UTF8); //BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12; - } else { - FTF_GetBoundingBox(but->tip, &llx,&lly,&llz,&urx,&ury,&urz, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); + BIF_GetBoundingBox(but->font, but->tip, (U.transopts & USER_TR_TOOLTIPS), &tip_bbox); + + x1= (but->x1+but->x2)/2; + x2= x1+but->aspect*((tip_bbox.xmax-tip_bbox.xmin) + 8); + y2= but->y1-10; + y1= y2-but->aspect*((tip_bbox.ymax+(tip_bbox.ymax-tip_bbox.ymin))); - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); //BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12; - } - } else { - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-30; y2= but->y1-12; - } -#else - x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*BMF_GetStringWidth(but->font, but->tip); - y1= but->y1-30; y2= but->y1-12; -#endif /* for pulldown menus it doesnt work */ if(mywinget()==G.curscreen->mainwin); @@ -4846,13 +4831,6 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but) y2 += 36; } - // adjust tooltip heights - if(mywinget()==G.curscreen->mainwin) - y2 -= G.ui_international ? 4:1; //tip is from pulldownmenu - else if(curarea->win != mywinget()) - y2 -= G.ui_international ? 5:1; //tip is from a windowheader -// else y2 += 1; //tip is from button area - od= ui_begin_overdraw((int)(x1-1), (int)(y1-2), (int)(x2+4), (int)(y2+4)); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -4874,7 +4852,10 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but) glRectf(x1, y1, x2, y2); glColor3ub(0,0,0); - ui_rasterpos_safe( x1+3, y1+5.0/but->aspect, but->aspect); + /* set the position for drawing text +4 in from the left edge, and leaving an equal gap between the top of the background box + * and the top of the string's tip_bbox, and the bottom of the background box, and the bottom of the string's tip_bbox + */ + ui_rasterpos_safe(x1+4, ((y2-tip_bbox.ymax)+(y1+tip_bbox.ymin))/2 - tip_bbox.ymin, but->aspect); BIF_SetScale(1.0); BIF_DrawString(but->font, but->tip, (U.transopts & USER_TR_TOOLTIPS)); diff --git a/source/blender/src/language.c b/source/blender/src/language.c index bdf0dfa3baf..7864468287e 100644 --- a/source/blender/src/language.c +++ b/source/blender/src/language.c @@ -33,6 +33,7 @@ #include "DNA_listBase.h" #include "DNA_userdef_types.h" +#include "DNA_vec_types.h" #include "BKE_global.h" /* G */ #include "BKE_utildefines.h" @@ -169,6 +170,21 @@ float BIF_GetStringWidth(BMF_Font* font, char *str, int translate) return rt; } +void BIF_GetBoundingBox(struct BMF_Font* font, char* str, int translate, rctf *bbox){ + float dummy; +#ifdef INTERNATIONAL + if(G.ui_international == TRUE) + if(translate && (U.transopts & USER_TR_BUTTONS)) + FTF_GetBoundingBox(str, &bbox->xmin, &bbox->ymin, &dummy, &bbox->xmax, &bbox->ymax, &dummy, FTF_USE_GETTEXT | FTF_INPUT_UTF8); + else + FTF_GetBoundingBox(str, &bbox->xmin, &bbox->ymin, &dummy, &bbox->xmax, &bbox->ymax, &dummy, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); + else + BMF_GetStringBoundingBox(font, str, &bbox->xmin, &bbox->ymin, &bbox->xmax, &bbox->ymax); +#else + BMF_GetStringBoundingBox(font, str, &bbox->xmin, &bbox->ymin, &bbox->xmax, &bbox->ymax); +#endif +} + #ifdef INTERNATIONAL |