diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-08-11 15:10:16 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-08-11 15:10:16 +0400 |
commit | d90d413421a39e6c5b96fbe483090a13bc9a4569 (patch) | |
tree | 308abe4066ec06da5f9e53845cffd248cddbbdf3 /source/blender | |
parent | a5d955632f40f4a1abee4928c5068968b35a757e (diff) |
Suggestion list scrolling and selection made independent for easier use. Selections no longer move away from the cursor.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_suggestions.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/suggestions.c | 14 | ||||
-rw-r--r-- | source/blender/src/drawtext.c | 57 |
3 files changed, 53 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_suggestions.h b/source/blender/blenkernel/BKE_suggestions.h index 41a87aaa05e..d58b8f58bf5 100644 --- a/source/blender/blenkernel/BKE_suggestions.h +++ b/source/blender/blenkernel/BKE_suggestions.h @@ -60,6 +60,7 @@ typedef struct SuggList { SuggItem *first, *last; SuggItem *firstmatch, *lastmatch; SuggItem *selected; + int top; } SuggList; /* Free all text tool memory */ @@ -78,6 +79,7 @@ SuggItem *texttool_suggest_first(); 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); diff --git a/source/blender/blenkernel/intern/suggestions.c b/source/blender/blenkernel/intern/suggestions.c index edccc0886f6..54ce425a04a 100644 --- a/source/blender/blenkernel/intern/suggestions.c +++ b/source/blender/blenkernel/intern/suggestions.c @@ -65,6 +65,7 @@ static void txttl_free_suggest() { 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 @@ void texttool_suggest_add(const char *name, char type) { } } 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 @@ void texttool_suggest_prefix(const char *prefix) { 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 @@ void texttool_suggest_prefix(const char *prefix) { suggestions.firstmatch = NULL; suggestions.lastmatch = NULL; suggestions.selected = NULL; + suggestions.top = 0; } } @@ -207,6 +213,10 @@ SuggItem *texttool_suggest_selected() { return suggestions.selected; } +int *texttool_suggest_top() { + return &suggestions.top; +} + /*************************/ /* Documentation methods */ /*************************/ diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c index 997fb01cab8..80233c8295f 100644 --- a/source/blender/src/drawtext.c +++ b/source/blender/src/drawtext.c @@ -1202,7 +1202,7 @@ static int do_suggest_select(SpaceText *st) 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 @@ static int do_suggest_select(SpaceText *st) 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 @@ static int do_suggest_select(SpaceText *st) 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 @@ void draw_suggestion_list(SpaceText *st) 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 @@ void draw_suggestion_list(SpaceText *st) 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 @@ void draw_suggestion_list(SpaceText *st) 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 @@ static short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short 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 @@ static short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short /* 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 @@ static short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short /* 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 @@ static short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short texttool_suggest_select(sel->next); sel= sel->next; } + pop_suggest_list(); swallow= 1; draw= 1; break; @@ -2377,6 +2397,7 @@ static short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short texttool_suggest_select(sel->prev); sel= sel->prev; } + pop_suggest_list(); swallow= 1; draw= 1; break; |