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

Ton Roosendaal ton at blender.org
Mon Jun 1 18:22:53 CEST 2009


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

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

Added support for cached text drawing in View2D. Cache is needed to
prevent the viewmatrix being set/restored on each text drawing.

Adding a string:
void UI_view2d_text_cache_add(View2D *v2d, float x, float y, char *str)

Drawing:
void UI_view2d_text_cache_draw(ARegion *ar)

Nothing else needed; just make sure cache-draw is always called at end
of a view2d drawing function, to clear cache memory.

On todo for next: a version with a rectf boundary to clip text within.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
    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 14:57:45 UTC (rev 20557)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2009-06-01 16:22:53 UTC (rev 20558)
@@ -129,6 +129,7 @@
 struct wmWindowManager;
 struct bScreen;
 struct ScrArea;
+struct ARegion;
 struct bContext;
 struct rctf;
 
@@ -181,6 +182,9 @@
 
 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_draw(struct ARegion *ar);
 
 /* operators */
 void ui_view2d_operatortypes(void);

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2009-06-01 14:57:45 UTC (rev 20557)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2009-06-01 16:22:53 UTC (rev 20558)
@@ -1939,3 +1939,55 @@
 	return 0;
 }
 
+/* ******************* view2d text drawing cache ******************** */
+
+/* assumes caches are used correctly, so for time being no local storage in v2d */
+static ListBase strings= {NULL, NULL};
+
+typedef struct View2DString {
+	struct View2DString *next, *prev;
+	float col[4];
+	char str[128]; 
+	short mval[2];
+} View2DString;
+
+
+void UI_view2d_text_cache_add(View2D *v2d, float x, float y, char *str)
+{
+	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) {
+		View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
+		
+		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);
+	}
+}
+
+void UI_view2d_text_cache_draw(ARegion *ar)
+{
+	View2DString *v2s;
+	
+	//	wmPushMatrix();
+	ED_region_pixelspace(ar);
+	
+	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);
+	}
+	
+	//	wmPopMatrix();
+	
+	if(strings.first) 
+		BLI_freelistN(&strings);
+}
+
+
+/* ******************************************************** */
+
+

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 14:57:45 UTC (rev 20557)
+++ branches/blender2.5/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2009-06-01 16:22:53 UTC (rev 20558)
@@ -55,7 +55,6 @@
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
-#include "BLF_api.h"
 
 #include "ED_anim_api.h"
 #include "ED_space_api.h"
@@ -72,6 +71,7 @@
 #define SEQ_LEFTHANDLE		1
 #define SEQ_RIGHTHANDLE	2
 
+
 /* Note, Dont use WHILE_SEQ while drawing! - it messes up transform, - Campbell */
 
 int no_rightbox=0, no_leftbox= 0;
@@ -329,7 +329,7 @@
 }
 
 /* draw a handle, for each end of a sequence strip */
-static void draw_seq_handle(SpaceSeq *sseq, Sequence *seq, float pixelx, short direction)
+static void draw_seq_handle(View2D *v2d, Sequence *seq, float pixelx, short direction)
 {
 	float v1[2], v2[2], v3[2], rx1=0, rx2=0; //for triangles and rect
 	float x1, x2, y1, y2;
@@ -337,7 +337,6 @@
 	float minhandle, maxhandle;
 	char str[32];
 	unsigned int whichsel=0;
-	View2D *v2d;
 	
 	x1= seq->startdisp;
 	x2= seq->enddisp;
@@ -345,8 +344,6 @@
 	y1= seq->machine+SEQ_STRIP_OFSBOTTOM;
 	y2= seq->machine+SEQ_STRIP_OFSTOP;
 	
-	v2d = &sseq->v2d;
-	
 	/* clamp handles to defined size in pixel space */
 	handsize = seq->handsize;
 	minhandle = 7;
@@ -404,13 +401,13 @@
 		if (direction == SEQ_LEFTHANDLE) {
 			sprintf(str, "%d", seq->startdisp);
 			x1= rx1;
-			y1 -= 0.15;
+			y1 -= 0.45;
 		} else {
 			sprintf(str, "%d", seq->enddisp - 1);
-			x1= x2 - BLF_width_default(str) * pixelx;
+			x1= x2 - handsize*0.75;
 			y1= y2 + 0.05;
 		}
-		BLF_draw_default(x1, y1, 0.0f, str);
+		UI_view2d_text_cache_add(v2d, x1, y1, str);
 	}	
 }
 
@@ -520,25 +517,12 @@
 /* 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)
 {
-	float v1[2], v2[2];
-	int len, size;
-	char str[32 + FILE_MAXDIR+FILE_MAXFILE], *strp;
-	int mval[2];
+	char str[32 + FILE_MAXDIR+FILE_MAXFILE];
 	
-	v1[1]= y1;
-	v2[1]= y2;
-	
-	v1[0]= x1;
-	UI_view2d_to_region_no_clip(v2d, v1[0], v1[1], mval, mval+1);
-	x1= mval[0];
-	v2[0]= x2;
-	UI_view2d_to_region_no_clip(v2d, v2[0], v2[1], mval, mval+1);
-	x2= mval[0];
-	size= x2-x1;
-	
 	if(seq->name[2]) {
 		sprintf(str, "%d | %s: %s", seq->len, give_seqname(seq), seq->name+2);
-	}else{
+	}
+	else{
 		if(seq->type == SEQ_META) {
 			sprintf(str, "%d | %s", seq->len, give_seqname(seq));
 		}
@@ -572,19 +556,6 @@
 		}
 	}
 	
-	strp= str;
-	// XXX
-	/* The correct thing is used a Styla and set the clipping region. */
-	while( (len= BLF_width_default(strp)) > size) {
-		if(len < 10) break;
-		if(strp[1]==0) break;
-		strp++;
-	}
-	
-	mval[0]= (x1+x2-len+1)/2;
-	mval[1]= 1;
-	UI_view2d_region_to_view(v2d, mval[0], mval[1], &x1, &x2);
-	
 	if(seq->flag & SELECT){
 		cpack(0xFFFFFF);
 	}else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50){
@@ -592,7 +563,8 @@
 	}else{
 		cpack(0);
 	}
-	BLF_draw_default(x1,  y1+SEQ_STRIP_OFSBOTTOM, 0.0, strp);
+	
+	UI_view2d_text_cache_add(v2d, x1, y1+SEQ_STRIP_OFSBOTTOM, str);
 }
 
 /* draws a shaded strip, made from gradient + flat color + gradient */
@@ -693,8 +665,8 @@
 	if (!is_single_image)
 		draw_seq_extensions(scene, sseq, seq);
 	
-	draw_seq_handle(sseq, seq, pixelx, SEQ_LEFTHANDLE);
-	draw_seq_handle(sseq, seq, pixelx, SEQ_RIGHTHANDLE);
+	draw_seq_handle(v2d, seq, pixelx, SEQ_LEFTHANDLE);
+	draw_seq_handle(v2d, seq, pixelx, SEQ_RIGHTHANDLE);
 	
 	/* draw the strip outline */
 	x1= seq->startdisp;
@@ -994,8 +966,6 @@
 	float col[3];
 	int i;
 
-	
-
 	if(sseq->mainb != SEQ_DRAW_SEQUENCE) {
 		draw_image_seq(scene, ar, sseq);
 		return;
@@ -1082,6 +1052,9 @@
 		}
 	}
 
+	/* text draw cached, in pixelspace now */
+	UI_view2d_text_cache_draw(ar);
+
 	/* Draw markers */
 //	draw_markers_timespace(SCE_MARKERS, DRAW_MARKERS_LINES);
 	





More information about the Bf-blender-cvs mailing list