[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51277] trunk/blender/source/blender: get the width and height of the font at once when drawing auto-key,

Campbell Barton ideasman42 at gmail.com
Fri Oct 12 01:42:27 CEST 2012


Revision: 51277
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51277
Author:   campbellbarton
Date:     2012-10-11 23:42:26 +0000 (Thu, 11 Oct 2012)
Log Message:
-----------
get the width and height of the font at once when drawing auto-key,
also move BLF'g global font init into its own static function.

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/BLF_api.h
    trunk/blender/source/blender/blenfont/intern/blf.c
    trunk/blender/source/blender/editors/transform/transform.c

Modified: trunk/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_api.h	2012-10-11 18:41:07 UTC (rev 51276)
+++ trunk/blender/source/blender/blenfont/BLF_api.h	2012-10-11 23:42:26 UTC (rev 51277)
@@ -109,6 +109,7 @@
  * of the string, using the default font and both value
  * are multiplied by the aspect of the font.
  */
+void  BLF_width_and_height_default(const char *str, float *width, float *height);
 float BLF_width_default(const char *str);
 float BLF_height_default(const char *str);
 

Modified: trunk/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf.c	2012-10-11 18:41:07 UTC (rev 51276)
+++ trunk/blender/source/blender/blenfont/intern/blf.c	2012-10-11 23:42:26 UTC (rev 51277)
@@ -69,7 +69,7 @@
 int blf_mono_font = -1;
 int blf_mono_font_render = -1;
 
-static FontBLF *BLF_get(int fontid)
+static FontBLF *blf_get(int fontid)
 {
 	if (fontid >= 0 && fontid < BLF_MAX_FONT)
 		return global_font[fontid];
@@ -141,6 +141,21 @@
 	return -1;
 }
 
+static int blf_global_font_init(void)
+{
+	if (global_font_default == -1) {
+		global_font_default = blf_search("default");
+	}
+
+	if (global_font_default == -1) {
+		printf("Warning: Can't find default font!\n");
+		return 0;
+	}
+	else {
+		return 1;
+	}
+}
+
 int BLF_load(const char *name)
 {
 	FontBLF *font;
@@ -219,7 +234,7 @@
 
 void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		blf_font_attach_from_mem(font, mem, mem_size);
@@ -311,7 +326,7 @@
 
 void BLF_enable(int fontid, int option)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->flags |= option;
@@ -320,7 +335,7 @@
 
 void BLF_disable(int fontid, int option)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->flags &= ~option;
@@ -329,7 +344,7 @@
 
 void BLF_enable_default(int option)
 {
-	FontBLF *font = BLF_get(global_font_default);
+	FontBLF *font = blf_get(global_font_default);
 
 	if (font) {
 		font->flags |= option;
@@ -338,7 +353,7 @@
 
 void BLF_disable_default(int option)
 {
-	FontBLF *font = BLF_get(global_font_default);
+	FontBLF *font = blf_get(global_font_default);
 
 	if (font) {
 		font->flags &= ~option;
@@ -347,7 +362,7 @@
 
 void BLF_aspect(int fontid, float x, float y, float z)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->aspect[0] = x;
@@ -358,7 +373,7 @@
 
 void BLF_matrix(int fontid, const double m[16])
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		memcpy(font->m, m, sizeof(font->m));
@@ -367,7 +382,7 @@
 
 void BLF_position(int fontid, float x, float y, float z)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		float xa, ya, za;
@@ -416,7 +431,7 @@
 
 void BLF_size(int fontid, int size, int dpi)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		blf_font_size(font, size, dpi);
@@ -425,7 +440,7 @@
 
 void BLF_blur(int fontid, int size)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->blur = size;
@@ -437,13 +452,8 @@
 	if (!str)
 		return;
 
-	if (global_font_default == -1)
-		global_font_default = blf_search("default");
-
-	if (global_font_default == -1) {
-		printf("Warning: Can't found default font!!\n");
+	if (!blf_global_font_init())
 		return;
-	}
 
 	BLF_size(global_font_default, global_font_points, global_font_dpi);
 	BLF_position(global_font_default, x, y, z);
@@ -456,13 +466,8 @@
 	if (!str)
 		return;
 
-	if (global_font_default == -1)
-		global_font_default = blf_search("default");
-
-	if (global_font_default == -1) {
-		printf("Warning: Can't found default font!!\n");
+	if (!blf_global_font_init())
 		return;
-	}
 
 	BLF_size(global_font_default, global_font_points, global_font_dpi);
 	BLF_position(global_font_default, x, y, z);
@@ -471,7 +476,7 @@
 
 void BLF_rotation_default(float angle)
 {
-	FontBLF *font = BLF_get(global_font_default);
+	FontBLF *font = blf_get(global_font_default);
 
 	if (font) {
 		font->angle = angle;
@@ -543,7 +548,7 @@
 
 void BLF_draw(int fontid, const char *str, size_t len)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 	GLint mode, param;
 
 	if (font && font->glyph_cache) {
@@ -555,7 +560,7 @@
 
 void BLF_draw_ascii(int fontid, const char *str, size_t len)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 	GLint mode, param;
 
 	if (font && font->glyph_cache) {
@@ -567,7 +572,7 @@
 
 void BLF_boundbox(int fontid, const char *str, rctf *box)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		blf_font_boundbox(font, str, box);
@@ -576,16 +581,29 @@
 
 void BLF_width_and_height(int fontid, const char *str, float *width, float *height)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		blf_font_width_and_height(font, str, width, height);
 	}
+	else {
+		*width = *height = 0.0f;
+	}
 }
 
+void BLF_width_and_height_default(const char *str, float *width, float *height)
+{
+	if (!blf_global_font_init()) {
+		*width = *height = 0.0f;
+		return;
+	}
+
+	BLF_width_and_height(global_font_default, str, width, height);
+}
+
 float BLF_width(int fontid, const char *str)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return blf_font_width(font, str);
@@ -596,7 +614,7 @@
 
 float BLF_fixed_width(int fontid)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return blf_font_fixed_width(font);
@@ -607,13 +625,8 @@
 
 float BLF_width_default(const char *str)
 {
-	if (global_font_default == -1)
-		global_font_default = blf_search("default");
-
-	if (global_font_default == -1) {
-		printf("Error: Can't found default font!!\n");
+	if (!blf_global_font_init())
 		return 0.0f;
-	}
 
 	BLF_size(global_font_default, global_font_points, global_font_dpi);
 	return BLF_width(global_font_default, str);
@@ -621,7 +634,7 @@
 
 float BLF_height(int fontid, const char *str)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return blf_font_height(font, str);
@@ -632,7 +645,7 @@
 
 float BLF_height_max(int fontid)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return font->glyph_cache->max_glyph_height;
@@ -643,7 +656,7 @@
 
 float BLF_width_max(int fontid)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return font->glyph_cache->max_glyph_width;
@@ -654,7 +667,7 @@
 
 float BLF_descender(int fontid)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return font->glyph_cache->descender;
@@ -665,7 +678,7 @@
 
 float BLF_ascender(int fontid)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache) {
 		return font->glyph_cache->ascender;
@@ -676,13 +689,8 @@
 
 float BLF_height_default(const char *str)
 {
-	if (global_font_default == -1)
-		global_font_default = blf_search("default");
-
-	if (global_font_default == -1) {
-		printf("Error: Can't found default font!!\n");
+	if (!blf_global_font_init())
 		return 0.0f;
-	}
 
 	BLF_size(global_font_default, global_font_points, global_font_dpi);
 
@@ -691,7 +699,7 @@
 
 void BLF_rotation(int fontid, float angle)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->angle = angle;
@@ -700,7 +708,7 @@
 
 void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->clip_rec.xmin = xmin;
@@ -712,7 +720,7 @@
 
 void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
 {
-	FontBLF *font = BLF_get(global_font_default);
+	FontBLF *font = blf_get(global_font_default);
 
 	if (font) {
 		font->clip_rec.xmin = xmin;
@@ -724,7 +732,7 @@
 
 void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->shadow = level;
@@ -737,7 +745,7 @@
 
 void BLF_shadow_offset(int fontid, int x, int y)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->shadow_x = x;
@@ -747,7 +755,7 @@
 
 void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->buf_info.fbuf = fbuf;
@@ -761,7 +769,7 @@
 
 void BLF_buffer_col(int fontid, float r, float g, float b, float a)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font) {
 		font->buf_info.col[0] = r;
@@ -773,7 +781,7 @@
 
 void BLF_draw_buffer(int fontid, const char *str)
 {
-	FontBLF *font = BLF_get(fontid);
+	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache && (font->buf_info.fbuf || font->buf_info.cbuf)) {
 		blf_font_buffer(font, str);

Modified: trunk/blender/source/blender/editors/transform/transform.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform.c	2012-10-11 18:41:07 UTC (rev 51276)
+++ trunk/blender/source/blender/editors/transform/transform.c	2012-10-11 23:42:26 UTC (rev 51277)
@@ -1561,13 +1561,16 @@
 }
 
 /* just draw a little warning message in the top-right corner of the viewport to warn that autokeying is enabled */
-static void drawAutoKeyWarning(TransInfo *t, ARegion *ar)
+static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
 {
 	const char printable[] = "Auto Keying On";
+	float      printable_size[2];
 	int xco, yco;
+
+	BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]);
 	
-	xco = ar->winx - BLF_width_default(printable)  - 10;
-	yco = ar->winy - BLF_height_default(printable) - 10;
+	xco = ar->winx - (int)printable_size[0] - 10;
+	yco = ar->winy - (int)printable_size[1] - 10;
 	
 	/* warning text (to clarify meaning of overlays)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list