[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32157] trunk/blender/source/blender/ editors/space_console: minor console fixes

Campbell Barton ideasman42 at gmail.com
Mon Sep 27 19:22:59 CEST 2010


Revision: 32157
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32157
Author:   campbellbarton
Date:     2010-09-27 19:22:59 +0200 (Mon, 27 Sep 2010)

Log Message:
-----------
minor console fixes
- selection doesnt mess up alignment when text is added to the buffer.
- tab key is now alligned to 4 (rather then adding 4 spaces).

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

Modified: trunk/blender/source/blender/editors/space_console/console_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_draw.c	2010-09-27 16:35:14 UTC (rev 32156)
+++ trunk/blender/source/blender/editors/space_console/console_draw.c	2010-09-27 17:22:59 UTC (rev 32157)
@@ -207,11 +207,11 @@
 		cdc->sel[1] = str_len - sel_orig[0];
 		
 		if(bg) {
-			glColor3ub(bg[0], bg[1], bg[2]);
+			glColor3ubv(bg);
 			glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, (cdc->xy[1]+(cdc->lheight*tot_lines))+rct_ofs);
 		}
 
-		glColor3ub(fg[0], fg[1], fg[2]);
+		glColor3ubv(fg);
 
 		/* last part needs no clipping */
 		BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
@@ -222,7 +222,7 @@
 			// glColor4ub(255, 0, 0, 96); // debug
 			console_draw_sel(cdc->sel, cdc->xy, str_len % cdc->console_width, cdc->cwidth, cdc->console_width, cdc->lheight);
 			STEP_SEL(cdc->console_width);
-			glColor3ub(fg[0], fg[1], fg[2]);
+			glColor3ubv(fg);
 		}
 
 		cdc->xy[1] += cdc->lheight;
@@ -240,7 +240,7 @@
 				// glColor4ub(0, 255, 0, 96); // debug
 				console_draw_sel(cdc->sel, cdc->xy, cdc->console_width, cdc->cwidth, cdc->console_width, cdc->lheight);
 				STEP_SEL(cdc->console_width);
-				glColor3ub(fg[0], fg[1], fg[2]);
+				glColor3ubv(fg);
 			}
 
 			cdc->xy[1] += cdc->lheight;
@@ -258,11 +258,11 @@
 	else { /* simple, no wrap */
 
 		if(bg) {
-			glColor3ub(bg[0], bg[1], bg[2]);
+			glColor3ubv(bg);
 			glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, cdc->xy[1]+cdc->lheight-rct_ofs);
 		}
 
-		glColor3ub(fg[0], fg[1], fg[2]);
+		glColor3ubv(fg);
 
 		BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
 		BLF_draw(mono, str);
@@ -334,14 +334,13 @@
 		if(sc->sel_start != sc->sel_end) {
 			sel[0]= sc->sel_start;
 			sel[1]= sc->sel_end;
-			// printf("%d %d\n", sel[0], sel[1]);
 		}
 		
 		/* text */
 		if(draw) {
 			prompt_len= strlen(sc->prompt);
 			console_line_color(fg, CONSOLE_LINE_INPUT);
-			glColor3ub(fg[0], fg[1], fg[2]);
+			glColor3ubv(fg);
 
 			/* command line */
 			if(prompt_len) {
@@ -353,7 +352,7 @@
 
 			/* cursor */
 			UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
-			glColor3ub(fg[0], fg[1], fg[2]);
+			glColor3ubv(fg);
 			glRecti(xy[0]+(cwidth*cl->cursor) -1, xy[1]-2, xy[0]+(cwidth*cl->cursor) +1, xy[1]+sc->lheight-2);
 
 			xy[0]= x_orig; /* remove prompt offset */
@@ -443,11 +442,15 @@
 	return (void *)mouse_pick;
 }
 
-// XXX - breaks with line wrap
 int console_char_pick(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int mval[2])
 {
 	int pos_pick= 0;
 	void *mouse_pick= NULL;
-	console_text_main__internal(sc, ar, reports, 0, mval, &mouse_pick, &pos_pick);
+	int mval_clamp[2];
+
+	mval_clamp[0]= CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx-(CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN));
+	mval_clamp[1]= CLAMPIS(mval[1], CONSOLE_DRAW_MARGIN, ar->winy-CONSOLE_DRAW_MARGIN);
+
+	console_text_main__internal(sc, ar, reports, 0, mval_clamp, &mouse_pick, &pos_pick);
 	return pos_pick;
 }

Modified: trunk/blender/source/blender/editors/space_console/console_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_ops.c	2010-09-27 16:35:14 UTC (rev 32156)
+++ trunk/blender/source/blender/editors/space_console/console_ops.c	2010-09-27 17:22:59 UTC (rev 32157)
@@ -205,7 +205,11 @@
 }
 ConsoleLine *console_scrollback_add_str(const bContext *C, char *str, int own)
 {
-	return console_lb_add_str__internal(&CTX_wm_space_console(C)->scrollback, C, str, own);
+	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;
+	return ci;
 }
 
 ConsoleLine *console_history_verify(const bContext *C)
@@ -359,14 +363,24 @@
 	RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to.");
 }
 
-
+#define TAB_LENGTH 4
 static int insert_exec(bContext *C, wmOperator *op)
 {
 	ConsoleLine *ci= console_history_verify(C);
 	char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+	int len;
+
+	// XXX, alligned tab key hack
+	if(str[0]=='\t' && str[1]=='\0') {
+		int len= TAB_LENGTH - (ci->cursor % TAB_LENGTH);
+		MEM_freeN(str);
+		MEM_mallocN(len + 1, "insert_exec");
+		memset(str, ' ', len);
+		str[len]= '\0';
+	}
+
+	len= console_line_insert(ci, str);
 	
-	int len= console_line_insert(ci, str);
-	
 	MEM_freeN(str);
 	
 	if(len==0)

Modified: trunk/blender/source/blender/editors/space_console/space_console.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/space_console.c	2010-09-27 16:35:14 UTC (rev 32156)
+++ trunk/blender/source/blender/editors/space_console/space_console.c	2010-09-27 17:22:59 UTC (rev 32157)
@@ -354,7 +354,7 @@
 	
 	WM_keymap_add_item(keymap, "CONSOLE_OT_select_set", LEFTMOUSE, KM_PRESS, 0, 0);
 
-	RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", "    "); /* fake tabs */
+	RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", "\t"); /* fake tabs */
 	WM_keymap_add_item(keymap, "CONSOLE_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
 }
 





More information about the Bf-blender-cvs mailing list