[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53471] trunk/blender/source/blender: text autocomplete

Campbell Barton ideasman42 at gmail.com
Mon Dec 31 17:24:53 CET 2012


Revision: 53471
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53471
Author:   campbellbarton
Date:     2012-12-31 16:24:49 +0000 (Mon, 31 Dec 2012)
Log Message:
-----------
text autocomplete
- make the popup box line up the X axis with the current word.
- add poll function for the operator

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_text.h
    trunk/blender/source/blender/blenkernel/intern/text.c
    trunk/blender/source/blender/editors/space_text/text_autocomplete.c
    trunk/blender/source/blender/editors/space_text/text_draw.c
    trunk/blender/source/blender/editors/space_text/text_intern.h
    trunk/blender/source/blender/editors/space_text/text_ops.c

Modified: trunk/blender/source/blender/blenkernel/BKE_text.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_text.h	2012-12-31 15:54:44 UTC (rev 53470)
+++ trunk/blender/source/blender/blenkernel/BKE_text.h	2012-12-31 16:24:49 UTC (rev 53471)
@@ -106,6 +106,7 @@
 int text_check_digit(const char ch);
 int text_check_identifier(const char ch);
 int text_check_whitespace(const char ch);
+int text_find_identifier_start(const char *str, int i);
 
 enum {
 	TXT_MOVE_LINE_UP   = -1,

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2012-12-31 15:54:44 UTC (rev 53470)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2012-12-31 16:24:49 UTC (rev 53471)
@@ -2936,3 +2936,14 @@
 		return 1;
 	return 0;
 }
+
+int text_find_identifier_start(const char *str, int i)
+{
+	while (i--) {
+		if (!text_check_identifier(str[i])) {
+			break;
+		}
+	}
+	i++;
+	return i;
+}

Modified: trunk/blender/source/blender/editors/space_text/text_autocomplete.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_autocomplete.c	2012-12-31 15:54:44 UTC (rev 53470)
+++ trunk/blender/source/blender/editors/space_text/text_autocomplete.c	2012-12-31 16:24:49 UTC (rev 53471)
@@ -147,13 +147,7 @@
 
 	/* first get the word we're at */
 	{
-		int i = text->curc;
-		while (i--) {
-			if (!text_check_identifier(text->curl->line[i])) {
-				break;
-			}
-		}
-		i++;
+		const int i = text_find_identifier_start(text->curl->line, text->curc);
 		seek_len = text->curc - i;
 		seek = text->curl->line + i;
 
@@ -550,7 +544,7 @@
 	ot->invoke = text_autocomplete_invoke;
 	ot->cancel = text_autocomplete_cancel;
 	ot->modal = text_autocomplete_modal;
-	//ot->poll = ED_operator_view3d_active;
+	ot->poll = text_space_edit_poll;
 
 	/* flags */
 	ot->flag = OPTYPE_BLOCKING;

Modified: trunk/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_draw.c	2012-12-31 15:54:44 UTC (rev 53470)
+++ trunk/blender/source/blender/editors/space_text/text_draw.c	2012-12-31 16:24:49 UTC (rev 53471)
@@ -958,8 +958,10 @@
 	TextLine *tmp;
 	char str[SUGG_LIST_WIDTH + 1];
 	int w, boxw = 0, boxh, i, l, x, y, b, *top;
+	const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
+	const int margin_x = 2;
 	
-	if (!st || !st->text) return;
+	if (!st->text) return;
 	if (!texttool_text_is_active(st->text)) return;
 
 	first = texttool_suggest_first();
@@ -981,14 +983,20 @@
 	else {
 		x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
 	}
-	y = ar->winy - (st->lheight_dpi + TXT_LINE_SPACING) * l - 2;
+	/* offset back so the start of the text lines up with the suggestions,
+	 * not essential but makes suggestions easier to follow */
+	x -= st->cwidth * (st->text->curc - text_find_identifier_start(st->text->curl->line, st->text->curc));
+	y = ar->winy - lheight * l - 2;
 
 	boxw = SUGG_LIST_WIDTH * st->cwidth + 20;
-	boxh = SUGG_LIST_SIZE * st->lheight_dpi + 8;
+	boxh = SUGG_LIST_SIZE * lheight + 8;
 	
+	/* not needed but stands out nicer */
+	uiDrawBoxShadow(220, x, y - boxh, x + boxw, y);
+
 	UI_ThemeColor(TH_SHADE1);
 	glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1);
-	UI_ThemeColor(TH_BACK);
+	UI_ThemeColorShade(TH_BACK, 16);
 	glRecti(x, y, x + boxw, y - boxh);
 
 	/* Set the top 'item' of the visible list */
@@ -996,7 +1004,7 @@
 
 	for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
 
-		y -= st->lheight_dpi;
+		y -= lheight;
 
 		BLI_strncpy(str, item->name, SUGG_LIST_WIDTH);
 
@@ -1004,7 +1012,7 @@
 		
 		if (item == sel) {
 			UI_ThemeColor(TH_SHADE2);
-			glRecti(x + 16, y - 3, x + 16 + w, y + st->lheight_dpi - 3);
+			glRecti(x + margin_x, y - 3, x + margin_x + w, y + lheight - 3);
 		}
 		b = 1; /* b=1 color block, text is default. b=0 no block, color text */
 		switch (item->type) {
@@ -1018,7 +1026,7 @@
 			glRecti(x + 8, y + 2, x + 11, y + 5);
 			UI_ThemeColor(TH_TEXT);
 		}
-		text_draw(st, str, 0, 0, 1, x + 16, y - 1, NULL);
+		text_draw(st, str, 0, 0, 1, x + margin_x, y - 1, NULL);
 
 		if (item == last) break;
 	}
@@ -1031,7 +1039,7 @@
 	Text *text = st->text;
 	int vcurl, vcurc, vsell, vselc, hidden = 0;
 	int x, y, w, i;
-	int lheight = st->lheight_dpi + TXT_LINE_SPACING;
+	const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
 
 	/* Draw the selection */
 	if (text->curl != text->sell || text->curc != text->selc) {

Modified: trunk/blender/source/blender/editors/space_text/text_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_intern.h	2012-12-31 15:54:44 UTC (rev 53470)
+++ trunk/blender/source/blender/editors/space_text/text_intern.h	2012-12-31 16:24:49 UTC (rev 53471)
@@ -143,6 +143,9 @@
 
 void TEXT_OT_resolve_conflict(struct wmOperatorType *ot);
 
+int text_space_edit_poll(struct bContext *C);
+
+/* text_autocomplete.c */
 void TEXT_OT_autocomplete(struct wmOperatorType *ot);
 
 /* space_text.c */

Modified: trunk/blender/source/blender/editors/space_text/text_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_ops.c	2012-12-31 15:54:44 UTC (rev 53470)
+++ trunk/blender/source/blender/editors/space_text/text_ops.c	2012-12-31 16:24:49 UTC (rev 53471)
@@ -98,7 +98,7 @@
 	return 1;
 }
 
-static int text_space_edit_poll(bContext *C)
+int text_space_edit_poll(bContext *C)
 {
 	SpaceText *st = CTX_wm_space_text(C);
 	Text *text = CTX_data_edit_text(C);




More information about the Bf-blender-cvs mailing list