[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20561] branches/blender2.5/blender/source /blender/editors: 2.5

Ton Roosendaal ton at blender.org
Mon Jun 1 19:21:03 CEST 2009


Revision: 20561
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20561
Author:   ton
Date:     2009-06-01 19:21:03 +0200 (Mon, 01 Jun 2009)

Log Message:
-----------
2.5

- Fix: text draw in fonts was slightly too low; it didn't calculate offset
  correctly. Now it is aligned to have number characters in center.

- Fix: text clip was too wide, giving errors on extreme zoom in.

- Added boundbox-clipped default text drawing for view2d:

  void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, char *str)

  (Note; also for previous commit, this cache immediately projects, so if
   you change view2d while drawing, text is still on correct positions)

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
    branches/blender2.5/blender/source/blender/editors/interface/view2d.c
    branches/blender2.5/blender/source/blender/editors/space_sequencer/sequencer_draw.c

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2009-06-01 17:17:21 UTC (rev 20560)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2009-06-01 17:21:03 UTC (rev 20561)
@@ -184,6 +184,7 @@
 
 /* cached text drawing in v2d, to allow pixel-aligned draw as post process */
 void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y, char *str);
+void UI_view2d_text_cache_rectf(struct View2D *v2d, struct rctf *rect, char *str);
 void UI_view2d_text_cache_draw(struct ARegion *ar);
 
 /* operators */

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_style.c	2009-06-01 17:17:21 UTC (rev 20560)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_style.c	2009-06-01 17:21:03 UTC (rev 20561)
@@ -164,7 +164,7 @@
 	
 	uiStyleFontSet(fs);
 	
-	height= BLF_height("A");
+	height= BLF_height("2");	/* correct offset is on baseline, the j is below that */
 	yofs= floor( 0.5f*(rect->ymax - rect->ymin - height));
 
 	if(fs->align==UI_STYLE_TEXT_CENTER)
@@ -173,7 +173,7 @@
 		xofs= rect->xmax - rect->xmin - BLF_width(str);
 	
 	/* clip is very strict, so we give it some space */
-	BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4);
+	BLF_clipping(rect->xmin-1, rect->ymin-4, rect->xmax+1, rect->ymax+4);
 	BLF_enable(BLF_CLIPPING);
 	
 	if(fs->shadow) 

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2009-06-01 17:17:21 UTC (rev 20560)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2009-06-01 17:21:03 UTC (rev 20561)
@@ -1949,6 +1949,7 @@
 	float col[4];
 	char str[128]; 
 	short mval[2];
+	rcti rect;
 } View2DString;
 
 
@@ -1959,6 +1960,7 @@
 	UI_view2d_view_to_region(v2d, x, y, mval, mval+1);
 	
 	if(mval[0]!=V2D_IS_CLIPPED && mval[1]!=V2D_IS_CLIPPED) {
+		/* use calloc, rect has to be zeroe'd */
 		View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
 		
 		BLI_addtail(&strings, v2s);
@@ -1969,6 +1971,20 @@
 	}
 }
 
+/* no clip (yet) */
+void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, char *str)
+{
+	View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
+	
+	UI_view2d_to_region_no_clip(v2d, rect->xmin, rect->ymin, &v2s->rect.xmin, &v2s->rect.ymin);
+	UI_view2d_to_region_no_clip(v2d, rect->xmax, rect->ymax, &v2s->rect.xmax, &v2s->rect.ymax);
+	
+	BLI_addtail(&strings, v2s);
+	BLI_strncpy(v2s->str, str, 128);
+	glGetFloatv(GL_CURRENT_COLOR, v2s->col);
+}
+
+
 void UI_view2d_text_cache_draw(ARegion *ar)
 {
 	View2DString *v2s;
@@ -1978,7 +1994,21 @@
 	
 	for(v2s= strings.first; v2s; v2s= v2s->next) {
 		glColor3fv(v2s->col);
-		BLF_draw_default((float)v2s->mval[0], (float)v2s->mval[1], 0.0, v2s->str);
+		if(v2s->rect.xmin==v2s->rect.xmax)
+			BLF_draw_default((float)v2s->mval[0], (float)v2s->mval[1], 0.0, v2s->str);
+		else {
+			int xofs=0, yofs;
+			
+			yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28")));
+			if(yofs<1) yofs= 1;
+			
+			BLF_clipping(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4);
+			BLF_enable(BLF_CLIPPING);
+			
+			BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, v2s->str);
+
+			BLF_disable(BLF_CLIPPING);
+		}
 	}
 	
 	//	wmPopMatrix();

Modified: branches/blender2.5/blender/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2009-06-01 17:17:21 UTC (rev 20560)
+++ branches/blender2.5/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2009-06-01 17:21:03 UTC (rev 20561)
@@ -517,6 +517,7 @@
 /* draw info text on a sequence strip */
 static void draw_seq_text(View2D *v2d, Sequence *seq, float x1, float x2, float y1, float y2, char *background_col)
 {
+	rctf rect;
 	char str[32 + FILE_MAXDIR+FILE_MAXFILE];
 	
 	if(seq->name[2]) {
@@ -564,7 +565,11 @@
 		cpack(0);
 	}
 	
-	UI_view2d_text_cache_add(v2d, x1, y1+SEQ_STRIP_OFSBOTTOM, str);
+	rect.xmin= x1;
+	rect.ymin= y1;
+	rect.xmax= x2;
+	rect.ymax= y2;
+	UI_view2d_text_cache_rectf(v2d, &rect, str);
 }
 
 /* draws a shaded strip, made from gradient + flat color + gradient */





More information about the Bf-blender-cvs mailing list