[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32993] trunk/blender/source/blender/ editors: make console wrapped text drawing into its own function in preparation to move report view out of the console space type .

Campbell Barton ideasman42 at gmail.com
Thu Nov 11 06:46:19 CET 2010


Revision: 32993
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32993
Author:   campbellbarton
Date:     2010-11-11 06:45:55 +0100 (Thu, 11 Nov 2010)

Log Message:
-----------
make console wrapped text drawing into its own function in preparation to move report view out of the console space type. (no functional changes)
also remove incorrect messages about the original copyright in the GPL headers.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_console/console_draw.c
    trunk/blender/source/blender/editors/space_console/console_intern.h
    trunk/blender/source/blender/editors/space_console/console_ops.c
    trunk/blender/source/blender/editors/space_console/console_report.c
    trunk/blender/source/blender/editors/space_console/space_console.c
    trunk/blender/source/blender/editors/space_info/CMakeLists.txt

Added Paths:
-----------
    trunk/blender/source/blender/editors/space_info/textview.c
    trunk/blender/source/blender/editors/space_info/textview.h

Modified: trunk/blender/source/blender/editors/space_console/console_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_draw.c	2010-11-11 05:11:37 UTC (rev 32992)
+++ trunk/blender/source/blender/editors/space_console/console_draw.c	2010-11-11 05:45:55 UTC (rev 32993)
@@ -17,11 +17,6 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
  * Contributor(s): Campbell Barton
  *
  * ***** END GPL LICENSE BLOCK *****
@@ -58,19 +53,10 @@
 #include "console_intern.h"
 
 
-static int mono= -1; // XXX needs proper storage and change all the BLF_* here!
+#include "../space_info/textview.h"
 
-static void console_font_begin(SpaceConsole *sc)
+static void console_line_color(unsigned char fg[3], int type)
 {
-	if(mono == -1)
-		mono= BLF_load_mem("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
-
-	BLF_aspect(mono, 1.0);
-	BLF_size(mono, sc->lheight-2, 72);
-}
-
-static void console_line_color(unsigned char *fg, int type)
-{
 	switch(type) {
 	case CONSOLE_LINE_OUTPUT:
 		UI_GetThemeColor3ubv(TH_CONSOLE_OUTPUT, (char *)fg);
@@ -133,310 +119,203 @@
 	int draw;
 } ConsoleDrawContext;
 
-static void console_draw_sel(int sel[2], int xy[2], int str_len_draw, int cwidth, int lheight)
+void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
 {
-	if(sel[0] <= str_len_draw && sel[1] >= 0) {
-		int sta = MAX2(sel[0], 0);
-		int end = MIN2(sel[1], str_len_draw);
-
-		glEnable(GL_POLYGON_STIPPLE);
-		glPolygonStipple(stipple_halftone);
-		glEnable( GL_BLEND );
-		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-		glColor4ub(255, 255, 255, 96);
-
-		glRecti(xy[0]+(cwidth*sta), xy[1]-2 + lheight, xy[0]+(cwidth*end), xy[1]-2);
-
-		glDisable(GL_POLYGON_STIPPLE);
-		glDisable( GL_BLEND );
-	}
+	/* fake the edit line being in the scroll buffer */
+	ConsoleLine *cl= sc->history.last;
+	cl_dummy->type= CONSOLE_LINE_INPUT;
+	cl_dummy->len= cl_dummy->len_alloc= strlen(sc->prompt) + cl->len;
+	cl_dummy->len_alloc= cl_dummy->len + 1;
+	cl_dummy->line= MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
+	memcpy(cl_dummy->line, sc->prompt, (cl_dummy->len_alloc - cl->len));
+	memcpy(cl_dummy->line + ((cl_dummy->len_alloc - cl->len)) - 1, cl->line, cl->len + 1);
+	BLI_addtail(&sc->scrollback, cl_dummy);
 }
+void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy) 
+{
+	MEM_freeN(cl_dummy->line);
+	BLI_remlink(&sc->scrollback, cl_dummy);
+}
 
+#define CONSOLE_DRAW_MARGIN 4
+#define CONSOLE_DRAW_SCROLL 16
 
-/* return 0 if the last line is off the screen
- * should be able to use this for any string type */
 
-static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, unsigned char *fg, unsigned char *bg)
+
+/* console textview callbacks */
+static int console_textview_begin(TextViewContext *tvc)
 {
-#define STEP_SEL(value) cdc->sel[0] += (value); cdc->sel[1] += (value)
-	int rct_ofs= cdc->lheight/4;
-	int tot_lines = (str_len/cdc->console_width)+1; /* total number of lines for wrapping */
-	int y_next = (str_len > cdc->console_width) ? cdc->xy[1]+cdc->lheight*tot_lines : cdc->xy[1]+cdc->lheight;
+	SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+	tvc->lheight= sc->lheight;
+	tvc->sel_start= sc->sel_start;
+	tvc->sel_end= sc->sel_end;
+	
+	/* iterator */
+	tvc->iter= sc->scrollback.last;
+	
+	return (tvc->iter != NULL);
+}
 
-	/* just advance the height */
-	if(cdc->draw==0) {
-		if(cdc->pos_pick && (cdc->mval[1] != INT_MAX)) {
-			if(cdc->xy[1] <= cdc->mval[1]) {
-				if((y_next >= cdc->mval[1])) {
-					int ofs = (int)floor(((float)cdc->mval[0] / (float)cdc->cwidth));
-
-					/* wrap */
-					if(str_len > cdc->console_width)
-						ofs += (cdc->console_width * ((int)((((float)(y_next - cdc->mval[1]) / (float)(y_next-cdc->xy[1])) * tot_lines))));
+static void console_textview_end(TextViewContext *tvc)
+{
+	SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+	(void)sc;
 	
-					CLAMP(ofs, 0, str_len);
-					*cdc->pos_pick += str_len - ofs;
-				} else
-					*cdc->pos_pick += str_len + 1;
-			}
-		}
+}
 
-		cdc->xy[1]= y_next;
-		return 1;
-	}
-	else if (y_next-cdc->lheight < cdc->ymin) {
-		/* have not reached the drawable area so don't break */
-		cdc->xy[1]= y_next;
+static int console_textview_step(TextViewContext *tvc)
+{
+	return ((tvc->iter= (void *)((Link *)tvc->iter)->prev) != NULL);
+}
 
-		/* adjust selection even if not drawing */
-		if(cdc->sel[0] != cdc->sel[1]) {
-			STEP_SEL(-(str_len + 1));
-		}
+static int console_textview_line_get(struct TextViewContext *tvc, char **line, int *len)
+{
+	ConsoleLine *cl= (ConsoleLine *)tvc->iter;
+	*line= cl->line;
+	*len= cl->len;
 
-		return 1;
-	}
+	return 1;
+}
 
-	if(str_len > cdc->console_width) { /* wrap? */
-		const int initial_offset= ((tot_lines-1) * cdc->console_width);
-		char *line_stride= str + initial_offset;	/* advance to the last line and draw it first */
-		char eol;													/* baclup the end of wrapping */
-		
-		int sel_orig[2];
-		VECCOPY2D(sel_orig, cdc->sel);
+static int console_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char UNUSED(bg[3]))
+{
+	ConsoleLine *cl= (ConsoleLine *)tvc->iter;
 
-		/* invert and swap for wrapping */
-		cdc->sel[0] = str_len - sel_orig[1];
-		cdc->sel[1] = str_len - sel_orig[0];
+	/* annoying hack, to draw the prompt */
+	if(tvc->iter_index == 0) {
+		SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+		int prompt_len= strlen(sc->prompt);
+		int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
+		const int cursor = ((ConsoleLine *)sc->history.last)->cursor;
 		
-		if(bg) {
-			glColor3ubv(bg);
-			glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, (cdc->xy[1]+(cdc->lheight*tot_lines))+rct_ofs);
-		}
-
+		/* cursor */
+		UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
 		glColor3ubv(fg);
 
-		/* last part needs no clipping */
-		BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
-		BLF_draw(mono, line_stride);
+		glRecti(xy[0]+(tvc->cwidth*(cursor+prompt_len)) -1, xy[1]-2, xy[0]+(tvc->cwidth*(cursor+prompt_len)) +1, xy[1]+tvc->lheight-2);
+	}
 
-		if(cdc->sel[0] != cdc->sel[1]) {
-			STEP_SEL(-initial_offset);
-			// glColor4ub(255, 0, 0, 96); // debug
-			console_draw_sel(cdc->sel, cdc->xy, str_len % cdc->console_width, cdc->cwidth, cdc->lheight);
-			STEP_SEL(cdc->console_width);
-			glColor3ubv(fg);
-		}
+	console_line_color(fg, cl->type);
 
-		cdc->xy[1] += cdc->lheight;
+	return TVC_LINE_FG;
+}
 
-		line_stride -= cdc->console_width;
-		
-		for(; line_stride >= str; line_stride -= cdc->console_width) {
-			eol = line_stride[cdc->console_width];
-			line_stride[cdc->console_width]= '\0';
-			
-			BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
-			BLF_draw(mono, line_stride);
-			
-			if(cdc->sel[0] != cdc->sel[1]) {
-				// glColor4ub(0, 255, 0, 96); // debug
-				console_draw_sel(cdc->sel, cdc->xy, cdc->console_width, cdc->cwidth, cdc->lheight);
-				STEP_SEL(cdc->console_width);
-				glColor3ubv(fg);
-			}
 
-			cdc->xy[1] += cdc->lheight;
 
-			line_stride[cdc->console_width] = eol; /* restore */
-			
-			/* check if were out of view bounds */
-			if(cdc->xy[1] > cdc->ymax)
-				return 0;
-		}
+/* reports! */
+static int report_textview_begin(TextViewContext *tvc)
+{
+	SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+	ReportList *reports= (ReportList *)tvc->arg2;
 
-		VECCOPY2D(cdc->sel, sel_orig);
-		STEP_SEL(-(str_len + 1));
-	}
-	else { /* simple, no wrap */
+	tvc->lheight= sc->lheight;
+	tvc->sel_start= sc->sel_start;
+	tvc->sel_end= sc->sel_end;
+	
+	/* iterator */
+	tvc->iter= reports->list.last;
+	
+	glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+	
+	return (tvc->iter != NULL);
+}
 
-		if(bg) {
-			glColor3ubv(bg);
-			glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, cdc->xy[1]+cdc->lheight-rct_ofs);
-		}
+static void report_textview_end(TextViewContext *UNUSED(tvc))
+{
+	/* pass */
+}
 
-		glColor3ubv(fg);
+static int report_textview_step(TextViewContext *tvc)
+{
+	return ((tvc->iter= (void *)((Link *)tvc->iter)->prev) != NULL);
+}
 
-		BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
-		BLF_draw(mono, str);
-		
-		if(cdc->sel[0] != cdc->sel[1]) {
-			int isel[2];
+static int report_textview_line_get(struct TextViewContext *tvc, char **line, int *len)
+{
+	Report *report= (Report *)tvc->iter;
+	*line= report->message;
+	*len= report->len;
 
-			isel[0]= str_len - cdc->sel[1];
-			isel[1]= str_len - cdc->sel[0];
-
-			// glColor4ub(255, 255, 0, 96); // debug
-			console_draw_sel(isel, cdc->xy, str_len, cdc->cwidth, cdc->lheight);
-			STEP_SEL(-(str_len + 1));
-		}
-
-		cdc->xy[1] += cdc->lheight;
-
-		if(cdc->xy[1] > cdc->ymax)
-			return 0;
-	}
-
 	return 1;
-#undef STEP_SEL
 }
 
-void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
+static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
 {
-	/* fake the edit line being in the scroll buffer */
-	ConsoleLine *cl= sc->history.last;
-	cl_dummy->type= CONSOLE_LINE_INPUT;
-	cl_dummy->len= cl_dummy->len_alloc= strlen(sc->prompt) + cl->len;
-	cl_dummy->len_alloc= cl_dummy->len + 1;
-	cl_dummy->line= MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
-	memcpy(cl_dummy->line, sc->prompt, (cl_dummy->len_alloc - cl->len));
-	memcpy(cl_dummy->line + ((cl_dummy->len_alloc - cl->len)) - 1, cl->line, cl->len + 1);
-	BLI_addtail(&sc->scrollback, cl_dummy);
+	Report *report= (Report *)tvc->iter;
+	console_report_color(fg, bg, report, tvc->iter_index % 2);
+	return TVC_LINE_FG | TVC_LINE_BG;
 }
-void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy) 
-{
-	MEM_freeN(cl_dummy->line);
-	BLI_remlink(&sc->scrollback, cl_dummy);
-}
 
-#define CONSOLE_DRAW_MARGIN 4
-#define CONSOLE_DRAW_SCROLL 16
 
 static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int draw, int mval[2], void **mouse_pick, int *pos_pick)
 {
-	View2D *v2d= &ar->v2d;
-
-	ConsoleLine *cl= sc->history.last;
-	ConsoleDrawContext cdc;
+	if(sc->type==CONSOLE_TYPE_PYTHON) {
+		int ret= 0;
+		
+		View2D *v2d= &ar->v2d;
 	
-	int x_orig=CONSOLE_DRAW_MARGIN, y_orig=CONSOLE_DRAW_MARGIN;
-	int xy[2], y_prev;
-	int cwidth;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list