[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11725] trunk/blender: Patch #6770 by James C (sheep)
Matt Ebb
matt at mke3.net
Mon Aug 20 03:02:13 CEST 2007
Revision: 11725
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11725
Author: broken
Date: 2007-08-20 03:02:12 +0200 (Mon, 20 Aug 2007)
Log Message:
-----------
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!
Modified Paths:
--------------
trunk/blender/intern/bmfont/BMF_Api.h
trunk/blender/intern/bmfont/intern/BMF_Api.cpp
trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp
trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h
trunk/blender/source/blender/ftfont/FTF_Api.h
trunk/blender/source/blender/ftfont/intern/FTF_TTFont.h
trunk/blender/source/blender/include/BIF_language.h
trunk/blender/source/blender/src/interface.c
trunk/blender/source/blender/src/language.c
Modified: trunk/blender/intern/bmfont/BMF_Api.h
===================================================================
--- trunk/blender/intern/bmfont/BMF_Api.h 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/intern/bmfont/BMF_Api.h 2007-08-20 01:02:12 UTC (rev 11725)
@@ -89,13 +89,25 @@
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
Modified: trunk/blender/intern/bmfont/intern/BMF_Api.cpp
===================================================================
--- trunk/blender/intern/bmfont/intern/BMF_Api.cpp 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/intern/bmfont/intern/BMF_Api.cpp 2007-08-20 01:02:12 UTC (rev 11725)
@@ -150,11 +150,18 @@
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) {
Modified: trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp
===================================================================
--- trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp 2007-08-20 01:02:12 UTC (rev 11725)
@@ -107,7 +107,7 @@
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 @@
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;
Modified: trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h
===================================================================
--- trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h 2007-08-20 01:02:12 UTC (rev 11725)
@@ -76,8 +76,20 @@
* 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
* ID of the texture. If the texture ID is bound, text can
Modified: trunk/blender/source/blender/ftfont/FTF_Api.h
===================================================================
--- trunk/blender/source/blender/ftfont/FTF_Api.h 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/source/blender/ftfont/FTF_Api.h 2007-08-20 01:02:12 UTC (rev 11725)
@@ -106,12 +106,12 @@
/**
* 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.
*/
Modified: trunk/blender/source/blender/ftfont/intern/FTF_TTFont.h
===================================================================
--- trunk/blender/source/blender/ftfont/intern/FTF_TTFont.h 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/source/blender/ftfont/intern/FTF_TTFont.h 2007-08-20 01:02:12 UTC (rev 11725)
@@ -78,6 +78,17 @@
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);
/**
Modified: trunk/blender/source/blender/include/BIF_language.h
===================================================================
--- trunk/blender/source/blender/include/BIF_language.h 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/source/blender/include/BIF_language.h 2007-08-20 01:02:12 UTC (rev 11725)
@@ -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 @@
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);
Modified: trunk/blender/source/blender/src/interface.c
===================================================================
--- trunk/blender/source/blender/src/interface.c 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/source/blender/src/interface.c 2007-08-20 01:02:12 UTC (rev 11725)
@@ -4805,31 +4805,16 @@
{
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()
+ 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)));
- 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);
-
- 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);
else {
@@ -4846,13 +4831,6 @@
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 @@
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));
Modified: trunk/blender/source/blender/src/language.c
===================================================================
--- trunk/blender/source/blender/src/language.c 2007-08-20 00:07:25 UTC (rev 11724)
+++ trunk/blender/source/blender/src/language.c 2007-08-20 01:02:12 UTC (rev 11725)
@@ -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,7 +170,22 @@
return rt;
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list