[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16054] branches/soc-2008-quorn/source/ blender: Suggestion list scrolling and selection made independent for easier use.

Ian Thompson quornian at googlemail.com
Mon Aug 11 13:10:16 CEST 2008


Revision: 16054
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16054
Author:   quorn
Date:     2008-08-11 13:10:16 +0200 (Mon, 11 Aug 2008)

Log Message:
-----------
Suggestion list scrolling and selection made independent for easier use. Selections no longer move away from the cursor.

Modified Paths:
--------------
    branches/soc-2008-quorn/source/blender/blenkernel/BKE_suggestions.h
    branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c
    branches/soc-2008-quorn/source/blender/src/drawtext.c

Modified: branches/soc-2008-quorn/source/blender/blenkernel/BKE_suggestions.h
===================================================================
--- branches/soc-2008-quorn/source/blender/blenkernel/BKE_suggestions.h	2008-08-11 06:44:15 UTC (rev 16053)
+++ branches/soc-2008-quorn/source/blender/blenkernel/BKE_suggestions.h	2008-08-11 11:10:16 UTC (rev 16054)
@@ -60,6 +60,7 @@
 	SuggItem *first, *last;
 	SuggItem *firstmatch, *lastmatch;
 	SuggItem *selected;
+	int top;
 } SuggList;
 
 /* Free all text tool memory */
@@ -78,6 +79,7 @@
 SuggItem *texttool_suggest_last();
 void texttool_suggest_select(SuggItem *sel);
 SuggItem *texttool_suggest_selected();
+int *texttool_suggest_top();
 
 /* Documentation */
 void texttool_docs_show(const char *docs);

Modified: branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c
===================================================================
--- branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c	2008-08-11 06:44:15 UTC (rev 16053)
+++ branches/soc-2008-quorn/source/blender/blenkernel/intern/suggestions.c	2008-08-11 11:10:16 UTC (rev 16054)
@@ -65,6 +65,7 @@
 	suggestions.first = suggestions.last = NULL;
 	suggestions.firstmatch = suggestions.lastmatch = NULL;
 	suggestions.selected = NULL;
+	suggestions.top = 0;
 }
 
 static void txttl_free_docs() {
@@ -149,11 +150,12 @@
 		}
 	}
 	suggestions.firstmatch = suggestions.lastmatch = suggestions.selected = NULL;
+	suggestions.top= 0;
 }
 
 void texttool_suggest_prefix(const char *prefix) {
 	SuggItem *match, *first, *last;
-	int cmp, len = strlen(prefix);
+	int cmp, len = strlen(prefix), top = 0;
 
 	if (!suggestions.first) return;
 	if (len==0) {
@@ -166,14 +168,17 @@
 	for (match=suggestions.first; match; match=match->next) {
 		cmp = txttl_cmp(prefix, match->name, len);
 		if (cmp==0) {
-			if (!first)
+			if (!first) {
 				first = match;
+				suggestions.top = top;
+			}
 		} else if (cmp<0) {
 			if (!last) {
 				last = match->prev;
 				break;
 			}
 		}
+		top++;
 	}
 	if (first) {
 		if (!last) last = suggestions.last;
@@ -184,6 +189,7 @@
 		suggestions.firstmatch = NULL;
 		suggestions.lastmatch = NULL;
 		suggestions.selected = NULL;
+		suggestions.top = 0;
 	}
 }
 
@@ -207,6 +213,10 @@
 	return suggestions.selected;
 }
 
+int *texttool_suggest_top() {
+	return &suggestions.top;
+}
+
 /*************************/
 /* Documentation methods */
 /*************************/

Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-08-11 06:44:15 UTC (rev 16053)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-08-11 11:10:16 UTC (rev 16054)
@@ -1202,7 +1202,7 @@
 	short mval[2];
 	TextLine *tmp;
 	int l, x, y, w, h, i;
-	int seli, tgti;
+	int tgti, *top;
 	
 	if (!st || !st->text) return 0;
 	if (!texttool_text_is_active(st->text)) return 0;
@@ -1210,6 +1210,7 @@
 	first = texttool_suggest_first();
 	last = texttool_suggest_last();
 	sel = texttool_suggest_selected();
+	top = texttool_suggest_top();
 
 	if (!last || !first)
 		return 0;
@@ -1233,26 +1234,39 @@
 	if (mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
 		return 0;
 
-	/* Work out which of the visible SUGG_LIST_SIZE items is selected */
-	for (seli=0, item=sel; seli<3 && item && item!=first; seli++, item=item->prev);
+	/* Work out which of the items is at the top of the visible list */
+	for (i=0, item=first; i<*top && item->next; i++, item=item->next);
 
 	/* Work out the target item index in the visible list */
 	tgti = (y-mval[1]-4) / st->lheight;
 	if (tgti<0 || tgti>SUGG_LIST_SIZE)
 		return 1;
 
-	if (seli<tgti) {
-		for (i=seli; i<tgti && sel && sel!=last; i++, sel=sel->next);
-		if (sel)
-			texttool_suggest_select(sel);
-	} else {
-		for (i=seli; i>tgti && sel && sel!=first; i--, sel=sel->prev);
-		if (sel)
-			texttool_suggest_select(sel);
-	}
+	for (i=tgti; i>0 && item->next; i--, item=item->next);
+	if (item)
+		texttool_suggest_select(item);
 	return 1;
 }
 
+static void pop_suggest_list() {
+	SuggItem *item, *sel;
+	int *top, i;
+
+	item= texttool_suggest_first();
+	sel= texttool_suggest_selected();
+	top= texttool_suggest_top();
+
+	i= 0;
+	while (item && item != sel) {
+		item= item->next;
+		i++;
+	}
+	if (i > *top+SUGG_LIST_SIZE-1)
+		*top= i-SUGG_LIST_SIZE+1;
+	else if (i < *top)
+		*top= i;
+}
+
 void draw_documentation(SpaceText *st)
 {
 	TextLine *tmp;
@@ -1343,7 +1357,7 @@
 	SuggItem *item, *first, *last, *sel;
 	TextLine *tmp;
 	char str[SUGG_LIST_WIDTH+1];
-	int w, boxw=0, boxh, i, l, x, y, b;
+	int w, boxw=0, boxh, i, l, x, y, b, *top;
 	
 	if (!st || !st->text) return;
 	if (!texttool_text_is_active(st->text)) return;
@@ -1353,7 +1367,9 @@
 
 	if (!first || !last) return;
 
+	pop_suggest_list();
 	sel = texttool_suggest_selected();
+	top = texttool_suggest_top();
 
 	/* Count the visible lines to the cursor */
 	for (tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
@@ -1375,9 +1391,7 @@
 	glRecti(x, y, x+boxw, y-boxh);
 
 	/* Set the top 'item' of the visible list */
-	for (i=0, item=sel; i<3 && item && item!=first; i++, item=item->prev);
-	if (!item)
-		item = first;
+	for (i=0, item=first; i<*top && item->next; i++, item=item->next);
 
 	for (i=0; i<SUGG_LIST_SIZE && item; i++, item=item->next) {
 
@@ -2261,6 +2275,7 @@
 				if (st->showsyntax) txt_format_line(st, st->text->curl, 1);
 			} else if ((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
 				get_suggest_prefix(st->text, 0);
+				pop_suggest_list();
 				swallow= 1;
 				draw= 1;
 			}
@@ -2313,8 +2328,10 @@
 						/* Work out which char we are about to delete/pass */
 						if (st->text->curl && st->text->curc > 0) {
 							char ch= st->text->curl->line[st->text->curc-1];
-							if ((ch=='_' || !ispunct(ch)) && !check_whitespace(ch))
+							if ((ch=='_' || !ispunct(ch)) && !check_whitespace(ch)) {
 								get_suggest_prefix(st->text, -1);
+								pop_suggest_list();
+							}
 							else
 								texttool_suggest_clear();
 						} else
@@ -2331,8 +2348,10 @@
 						/* Work out which char we are about to pass */
 						if (st->text->curl && st->text->curc < st->text->curl->len) {
 							char ch= st->text->curl->line[st->text->curc+1];
-							if ((ch=='_' || !ispunct(ch)) && !check_whitespace(ch))
+							if ((ch=='_' || !ispunct(ch)) && !check_whitespace(ch)) {
 								get_suggest_prefix(st->text, 1);
+								pop_suggest_list();
+							}
 							else
 								texttool_suggest_clear();
 						} else
@@ -2358,6 +2377,7 @@
 						texttool_suggest_select(sel->next);
 						sel= sel->next;
 					}
+					pop_suggest_list();
 					swallow= 1;
 					draw= 1;
 					break;
@@ -2377,6 +2397,7 @@
 						texttool_suggest_select(sel->prev);
 						sel= sel->prev;
 					}
+					pop_suggest_list();
 					swallow= 1;
 					draw= 1;
 					break;





More information about the Bf-blender-cvs mailing list