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 /intern | |
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 'intern')
-rw-r--r-- | intern/bmfont/BMF_Api.h | 14 | ||||
-rw-r--r-- | intern/bmfont/intern/BMF_Api.cpp | 11 | ||||
-rw-r--r-- | intern/bmfont/intern/BMF_BitmapFont.cpp | 23 | ||||
-rw-r--r-- | intern/bmfont/intern/BMF_BitmapFont.h | 14 |
4 files changed, 57 insertions, 5 deletions
diff --git a/intern/bmfont/BMF_Api.h b/intern/bmfont/BMF_Api.h index 001a9788920..5900ea85ec7 100644 --- a/intern/bmfont/BMF_Api.h +++ b/intern/bmfont/BMF_Api.h @@ -89,13 +89,25 @@ int BMF_GetCharacterWidth(BMF_Font* font, char c); int BMF_GetStringWidth(BMF_Font* font, char* str); /** + * Returns the bounding box of a string of characters. + * @param font The font to use. + * @param str The string. + * @param llx Lower left x coord + * @param lly Lower left y coord + * @param urx Upper right x coord + * @param ury Upper right y coord + */ +void BMF_GetStringBoundingBox(BMF_Font* font, char* str, float*llx, float *lly, float *urx, float *ury); + + +/** * Returns the bounding box of the font. The width and * height represent the bounding box of the union of * all glyps. The minimum and maximum values of the * box represent the extent of the font and its positioning * about the origin. */ -void BMF_GetBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r); +void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r); /** * Convert the given @a font to a texture, and return the GL texture diff --git a/intern/bmfont/intern/BMF_Api.cpp b/intern/bmfont/intern/BMF_Api.cpp index 46776b08ba0..176ef452fdc 100644 --- a/intern/bmfont/intern/BMF_Api.cpp +++ b/intern/bmfont/intern/BMF_Api.cpp @@ -150,11 +150,18 @@ int BMF_GetStringWidth(BMF_Font* font, char* str) return ((BMF_BitmapFont*)font)->GetStringWidth(str); } +void BMF_GetStringBoundingBox(BMF_Font* font, char* str, float*llx, float *lly, float *urx, float *ury){ + if (!font){ + *llx = *lly = *urx = *ury = 0; + }else{ + ((BMF_BitmapFont*)font)->GetStringBoundingBox(str, llx, lly, urx, ury); + } +} -void BMF_GetBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r) +void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r) { if (!font) return; - ((BMF_BitmapFont*)font)->GetBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r); + ((BMF_BitmapFont*)font)->GetFontBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r); } int BMF_GetFontTexture(BMF_Font* font) { diff --git a/intern/bmfont/intern/BMF_BitmapFont.cpp b/intern/bmfont/intern/BMF_BitmapFont.cpp index bbba2c978dd..8be4ff19a4f 100644 --- a/intern/bmfont/intern/BMF_BitmapFont.cpp +++ b/intern/bmfont/intern/BMF_BitmapFont.cpp @@ -107,7 +107,7 @@ int BMF_BitmapFont::GetStringWidth(char* str) return length; } -void BMF_BitmapFont::GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax) +void BMF_BitmapFont::GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax) { xMin = m_fontData->xmin; yMin = m_fontData->ymin; @@ -115,6 +115,27 @@ void BMF_BitmapFont::GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yM yMax = m_fontData->ymax; } +void BMF_BitmapFont::GetStringBoundingBox(char* str, float*llx, float *lly, float *urx, float *ury) +{ + unsigned char c; + int length = 0; + int ascent = 0; + int descent = 0; + + while ( (c = (unsigned char) *str++) ) { + length += m_fontData->chars[c].advance; + int d = m_fontData->chars[c].yorig; + int a = m_fontData->chars[c].height - m_fontData->chars[c].yorig; + if(a > ascent) ascent = a; + if(d > descent) descent = d; + } + *llx = (float)0; + *lly = (float)-descent; + *urx = (float)length; + *ury = (float)ascent; +} + + int BMF_BitmapFont::GetTexture() { int fWidth = m_fontData->xmax - m_fontData->xmin; diff --git a/intern/bmfont/intern/BMF_BitmapFont.h b/intern/bmfont/intern/BMF_BitmapFont.h index 30cfd650353..e8e0abc0561 100644 --- a/intern/bmfont/intern/BMF_BitmapFont.h +++ b/intern/bmfont/intern/BMF_BitmapFont.h @@ -76,7 +76,19 @@ public: * box represent the extent of the font and its positioning * about the origin. */ - void GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax); + void GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax); + + /** + * Returns the bounding box of a string of characters. + * @param font The font to use. + * @param str The string. + * @param llx Lower left x coord + * @param lly Lower left y coord + * @param urx Upper right x coord + * @param ury Upper right y coord + */ + void GetStringBoundingBox(char* str, float*llx, float *lly, float *urx, float *ury); + /** * Convert the font to a texture, and return the GL texture |