[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33528] trunk/blender/source/blender/ editors: 2D text drawing

Campbell Barton ideasman42 at gmail.com
Tue Dec 7 08:02:48 CET 2010


Revision: 33528
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33528
Author:   campbellbarton
Date:     2010-12-07 08:02:47 +0100 (Tue, 07 Dec 2010)

Log Message:
-----------
2D text drawing
- with the NLA on a small strip text was drawn under the scroll bar, now draw with same alignment as rectangle constrained text.
- single alloc per text item.
- was using opengl context rather then passing color value.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_view2d.h
    trunk/blender/source/blender/editors/interface/view2d.c
    trunk/blender/source/blender/editors/space_nla/nla_draw.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c

Modified: trunk/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_view2d.h	2010-12-07 06:47:40 UTC (rev 33527)
+++ trunk/blender/source/blender/editors/include/UI_view2d.h	2010-12-07 07:02:47 UTC (rev 33528)
@@ -191,8 +191,8 @@
 short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
 
 /* 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_add(struct View2D *v2d, float x, float y, const char *str, const char col[4]);
+void UI_view2d_text_cache_rectf(struct View2D *v2d, struct rctf *rect, const char *str, const char col[4]);
 void UI_view2d_text_cache_draw(struct ARegion *ar);
 
 /* operators */

Modified: trunk/blender/source/blender/editors/interface/view2d.c
===================================================================
--- trunk/blender/source/blender/editors/interface/view2d.c	2010-12-07 06:47:40 UTC (rev 33527)
+++ trunk/blender/source/blender/editors/interface/view2d.c	2010-12-07 07:02:47 UTC (rev 33528)
@@ -2006,42 +2006,48 @@
 
 typedef struct View2DString {
 	struct View2DString *next, *prev;
-	float col[4];
-	char str[128]; 
+	GLbyte col[4];
 	short mval[2];
 	rcti rect;
 } View2DString;
 
 
-void UI_view2d_text_cache_add(View2D *v2d, float x, float y, char *str)
+void UI_view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, const char col[4])
 {
 	int mval[2];
 	
 	UI_view2d_view_to_region(v2d, x, y, mval, mval+1);
 	
 	if(mval[0]!=V2D_IS_CLIPPED && mval[1]!=V2D_IS_CLIPPED) {
+		int len= strlen(str)+1;
 		/* use calloc, rect has to be zeroe'd */
-		View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
-		
+		View2DString *v2s= MEM_callocN(sizeof(View2DString)+len, "View2DString");
+		char *v2s_str= (char *)(v2s+1);
+		memcpy(v2s_str, str, len);
+
 		BLI_addtail(&strings, v2s);
-		BLI_strncpy(v2s->str, str, 128);
 		v2s->mval[0]= mval[0];
 		v2s->mval[1]= mval[1];
-		glGetFloatv(GL_CURRENT_COLOR, v2s->col);
+		QUATCOPY(v2s->col, col);
 	}
 }
 
 /* no clip (yet) */
-void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, char *str)
+void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, const char *str, const char col[4])
 {
-	View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
-	
+	int len= strlen(str)+1;
+	View2DString *v2s= MEM_callocN(sizeof(View2DString)+len, "View2DString");
+	char *v2s_str= (char *)(v2s+1);
+	memcpy(v2s_str, str, len);
+
 	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);
-	
+
+	v2s->mval[0]= v2s->rect.xmin;
+	v2s->mval[1]= v2s->rect.ymin;
+
 	BLI_addtail(&strings, v2s);
-	BLI_strncpy(v2s->str, str, 128);
-	glGetFloatv(GL_CURRENT_COLOR, v2s->col);
+	QUATCOPY(v2s->col, col);
 }
 
 
@@ -2056,18 +2062,20 @@
 	ED_region_pixelspace(ar);
 	
 	for(v2s= strings.first; v2s; v2s= v2s->next) {
-		glColor3fv(v2s->col);
-		if(v2s->rect.xmin==v2s->rect.xmax)
-			BLF_draw_default((float)v2s->mval[0], (float)v2s->mval[1], 0.0, v2s->str, sizeof(v2s->str)-1);
+		const char *str= (const char *)(v2s+1);
+		int xofs=0, yofs;
+
+		yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28")));
+		if(yofs<1) yofs= 1;
+
+		glColor3bv(v2s->col);
+
+		if(v2s->rect.xmin >= v2s->rect.xmax)
+			BLF_draw_default((float)v2s->mval[0]+xofs, (float)v2s->mval[1]+yofs, 0.0, str, 65535);
 		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_default(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4);
 			BLF_enable_default(BLF_CLIPPING);
-			BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, v2s->str, sizeof(v2s->str)-1);
+			BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, str, 65535);
 			BLF_disable_default(BLF_CLIPPING);
 		}
 	}

Modified: trunk/blender/source/blender/editors/space_nla/nla_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_nla/nla_draw.c	2010-12-07 06:47:40 UTC (rev 33527)
+++ trunk/blender/source/blender/editors/space_nla/nla_draw.c	2010-12-07 07:02:47 UTC (rev 33528)
@@ -417,6 +417,7 @@
 static void nla_draw_strip_text (NlaTrack *UNUSED(nlt), NlaStrip *strip, int UNUSED(index), View2D *v2d, float yminc, float ymaxc)
 {
 	char str[256], dir[3];
+	char col[4];
 	rctf rect;
 	
 	/* 'dir' - direction that strip is played in */
@@ -432,11 +433,14 @@
 		sprintf(str, "%s | %.2f %s %.2f", strip->name, strip->start, dir, strip->end);
 	
 	/* set text color - if colors (see above) are light, draw black text, otherwise draw white */
-	if (strip->flag & (NLASTRIP_FLAG_ACTIVE|NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_TWEAKUSER))
-		glColor3f(0.0f, 0.0f, 0.0f);
-	else
-		glColor3f(1.0f, 1.0f, 1.0f);
-	
+	if (strip->flag & (NLASTRIP_FLAG_ACTIVE|NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_TWEAKUSER)) {
+		col[0]= col[1]= col[2]= 0;
+	}
+	else {
+		col[0]= col[1]= col[2]= 255;
+	}
+	col[3]= 1.0;
+
 	/* set bounding-box for text 
 	 *	- padding of 2 'units' on either side
 	 */
@@ -447,7 +451,8 @@
 	rect.ymax= ymaxc;
 	
 	/* add this string to the cache of texts to draw*/
-	UI_view2d_text_cache_rectf(v2d, &rect, str);
+
+	UI_view2d_text_cache_rectf(v2d, &rect, str, col);
 }
 
 /* ---------------------- */

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-12-07 06:47:40 UTC (rev 33527)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-12-07 07:02:47 UTC (rev 33528)
@@ -343,7 +343,7 @@
 	}
 	
 	if(G.moving || (seq->flag & whichsel)) {
-		cpack(0xFFFFFF);
+		const char col[4]= {255, 255, 255, 255};
 		if (direction == SEQ_LEFTHANDLE) {
 			sprintf(str, "%d", seq->startdisp);
 			x1= rx1;
@@ -353,7 +353,7 @@
 			x1= x2 - handsize*0.75;
 			y1= y2 + 0.05;
 		}
-		UI_view2d_text_cache_add(v2d, x1, y1, str);
+		UI_view2d_text_cache_add(v2d, x1, y1, str, col);
 	}	
 }
 
@@ -467,6 +467,7 @@
 	rctf rect;
 	char str[32 + FILE_MAXDIR+FILE_MAXFILE];
 	const char *name= seq->name+2;
+	char col[4];
 	
 	if(name[0]=='\0')
 		name= give_seqname(seq);
@@ -511,18 +512,19 @@
 	}
 	
 	if(seq->flag & SELECT){
-		cpack(0xFFFFFF);
+		col[0]= col[1]= col[2]= 255;
 	}else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50){
-		cpack(0x505050); /* use lighter text color for dark background */
+		col[0]= col[1]= col[2]= 80; /* use lighter text color for dark background */
 	}else{
-		cpack(0);
+		col[0]= col[1]= col[2]= 0;
 	}
-	
+	col[3]= 255;
+
 	rect.xmin= x1;
 	rect.ymin= y1;
 	rect.xmax= x2;
 	rect.ymax= y2;
-	UI_view2d_text_cache_rectf(v2d, &rect, str);
+	UI_view2d_text_cache_rectf(v2d, &rect, str, col);
 }
 
 /* draws a shaded strip, made from gradient + flat color + gradient */





More information about the Bf-blender-cvs mailing list