[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32269] trunk/blender/source/blender/ editors/space_console: python console prompt + edit line is how selectable.

Campbell Barton ideasman42 at gmail.com
Sun Oct 3 00:31:48 CEST 2010


Revision: 32269
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32269
Author:   campbellbarton
Date:     2010-10-03 00:31:48 +0200 (Sun, 03 Oct 2010)

Log Message:
-----------
python console prompt + edit line is how selectable.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_console/console_draw.c
    trunk/blender/source/blender/editors/space_console/console_ops.c

Modified: trunk/blender/source/blender/editors/space_console/console_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_draw.c	2010-10-02 21:02:40 UTC (rev 32268)
+++ trunk/blender/source/blender/editors/space_console/console_draw.c	2010-10-02 22:31:48 UTC (rev 32269)
@@ -45,6 +45,8 @@
 #include "BKE_report.h"
 #include "BKE_utildefines.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
@@ -329,7 +331,8 @@
 	cdc.draw= draw;
 
 	if(sc->type==CONSOLE_TYPE_PYTHON) {
-		int prompt_len;
+		ConsoleLine cl_dummy= {0};
+		int prompt_len= strlen(sc->prompt);
 		
 		if(sc->sel_start != sc->sel_end) {
 			sel[0]= sc->sel_start;
@@ -338,28 +341,24 @@
 		
 		/* text */
 		if(draw) {
-			prompt_len= strlen(sc->prompt);
-			console_line_color(fg, CONSOLE_LINE_INPUT);
-			glColor3ubv(fg);
-
-			/* command line */
-			if(prompt_len) {
-				BLF_position(mono, xy[0], xy[1], 0); xy[0] += cwidth * prompt_len;
-				BLF_draw(mono, sc->prompt);
-			}
-			BLF_position(mono, xy[0], xy[1], 0);
-			BLF_draw(mono, cl->line);
-
 			/* cursor */
 			UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
 			glColor3ubv(fg);
-			glRecti(xy[0]+(cwidth*cl->cursor) -1, xy[1]-2, xy[0]+(cwidth*cl->cursor) +1, xy[1]+sc->lheight-2);
+			glRecti(xy[0]+(cwidth*(cl->cursor+prompt_len)) -1, xy[1]-2, xy[0]+(cwidth*(cl->cursor+prompt_len)) +1, xy[1]+sc->lheight-2);
 
 			xy[0]= x_orig; /* remove prompt offset */
 		}
-		
-		xy[1] += sc->lheight;
-		
+
+		/* fake the edit line being in the scroll buffer */
+		cl_dummy.type= CONSOLE_LINE_INPUT;
+		cl_dummy.len= cl_dummy.len_alloc= prompt_len + 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);
+
+
 		for(cl= sc->scrollback.last; cl; cl= cl->prev) {
 			y_prev= xy[1];
 
@@ -378,6 +377,10 @@
 				break;
 			}
 		}
+
+		/* temp line end */
+		MEM_freeN(cl_dummy.line);
+		BLI_remlink(&sc->scrollback, &cl_dummy);
 	}
 	else { 
 		Report *report;

Modified: trunk/blender/source/blender/editors/space_console/console_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_ops.c	2010-10-02 21:02:40 UTC (rev 32268)
+++ trunk/blender/source/blender/editors/space_console/console_ops.c	2010-10-02 22:31:48 UTC (rev 32269)
@@ -52,6 +52,12 @@
 
 #include "console_intern.h"
 
+static void console_select_offset(SpaceConsole *sc, const int offset)
+{
+	sc->sel_start += offset;
+	sc->sel_end += offset;
+}
+
 void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
 {
 	BLI_remlink(&sc->history, cl);
@@ -207,8 +213,7 @@
 {
 	SpaceConsole *sc= CTX_wm_space_console(C);
 	ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, C, str, own);
-	sc->sel_start += ci->len + 1;
-	sc->sel_end   += ci->len + 1;
+	console_select_offset(sc, ci->len + 1);
 	return ci;
 }
 
@@ -383,8 +388,13 @@
 	
 	MEM_freeN(str);
 	
-	if(len==0)
+	if(len==0) {
 		return OPERATOR_CANCELLED;
+	}
+	else {
+		SpaceConsole *sc= CTX_wm_space_console(C);
+		console_select_offset(sc, len);
+	}
 		
 	ED_area_tag_redraw(CTX_wm_area(C));
 	
@@ -456,8 +466,13 @@
 		break;
 	}
 	
-	if(!done)
+	if(!done) {
 		return OPERATOR_CANCELLED;
+	}
+	else {
+		SpaceConsole *sc= CTX_wm_space_console(C);
+		console_select_offset(sc, -1);
+	}
 	
 	ED_area_tag_redraw(CTX_wm_area(C));
 	
@@ -529,8 +544,8 @@
 {
 	SpaceConsole *sc= CTX_wm_space_console(C);
 	ConsoleLine *ci= console_history_verify(C); /* TODO - stupid, just prevernts crashes when no command line */
-	
 	short reverse= RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
+	int prev_len= ci->len;
 
 	/* keep a copy of the line above so when history is cycled
 	 * this is the only function that needs to know about the double-up */
@@ -559,6 +574,9 @@
 
 		console_history_add(C, (ConsoleLine *)sc->history.last);
 	}
+	
+	ci= sc->history.last;
+	console_select_offset(sc, ci->len - prev_len);
 
 	ED_area_tag_redraw(CTX_wm_area(C));
 
@@ -584,10 +602,12 @@
 /* the python exec operator uses this */
 static int history_append_exec(bContext *C, wmOperator *op)
 {
+	SpaceConsole *sc= CTX_wm_space_console(C);
 	ConsoleLine *ci= console_history_verify(C);
 	char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
 	int cursor= RNA_int_get(op->ptr, "current_character");
 	short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
+	int prev_len= ci->len;
 
 	if(rem_dupes) {
 		SpaceConsole *sc= CTX_wm_space_console(C);
@@ -603,6 +623,7 @@
 	}
 
 	ci= console_history_add_str(C, str, 1); /* own the string */
+	console_select_offset(sc, ci->len - prev_len);
 	console_line_cursor_set(ci, cursor);
 	
 	ED_area_tag_redraw(CTX_wm_area(C));





More information about the Bf-blender-cvs mailing list