[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15863] branches/soc-2008-quorn/source/ blender/src/drawtext.c: Selections now draw correctly when word-wrapped.
Ian Thompson
quornian at googlemail.com
Tue Jul 29 13:37:12 CEST 2008
Revision: 15863
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15863
Author: quorn
Date: 2008-07-29 13:37:11 +0200 (Tue, 29 Jul 2008)
Log Message:
-----------
Selections now draw correctly when word-wrapped.
Modified Paths:
--------------
branches/soc-2008-quorn/source/blender/src/drawtext.c
Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c 2008-07-29 11:19:30 UTC (rev 15862)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c 2008-07-29 11:37:11 UTC (rev 15863)
@@ -580,6 +580,7 @@
TextLine *linep;
int i, start, end, taboffs, max;
+ *offl= *offc= 0;
if (!st->text) return;
if (!st->wordwrap) return;
@@ -593,9 +594,7 @@
i--;
}
- /* Calculate line offset for earlier lines */
max= get_wrap_width(st);
- *offl= 0;
while (linep) {
taboffs= start= 0;
@@ -623,102 +622,76 @@
}
}
+static int get_char_pos(SpaceText *st, char *line, int cur) {
+ int a=0, i;
+ for (i=0; i<cur && line[i]; i++) {
+ if (line[i]=='\t')
+ a += st->tabnumber-a%st->tabnumber;
+ else
+ a++;
+ }
+ return a;
+}
+
static void draw_cursor(SpaceText *st) {
- int h, x, i, w;
Text *text= st->text;
TextLine *linef, *linel;
- int charf, charl, offl, offc;
- char ch[2];
+ int vcurl, vcurc, vsell, vselc, offl, offc, x, y, w, i;
/* Draw the selection */
if (text->curl!=text->sell || text->curc!=text->selc) {
- int span= txt_get_span(text->curl, text->sell);
+
+ /* Convert all to view space character coordinates */
+ wrap_offset(st, text->curl, text->curc, &offl, &offc);
+ vcurl = txt_get_span(text->lines.first, text->curl) - st->top + offl;
+ vcurc = get_char_pos(st, text->curl->line, text->curc) + offc;
+ wrap_offset(st, text->sell, text->selc, &offl, &offc);
+ vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
+ vselc = get_char_pos(st, text->sell->line, text->selc) + offc;
- if (span<0) {
- linef= text->sell;
- charf= text->selc;
-
- linel= text->curl;
- charl= text->curc;
- } else if (span>0) {
- linef= text->curl;
- charf= text->curc;
-
- linel= text->sell;
- charl= text->selc;
+ BIF_ThemeColor(TH_SHADE2);
+ x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
+ y= curarea->winy-2;
+
+ if (vcurl==vsell) {
+ y -= vcurl*st->lheight;
+ if (vcurc < vselc)
+ glRecti(x+vcurc*spacetext_get_fontwidth(st), y, x+vselc*spacetext_get_fontwidth(st), y-st->lheight);
+ else
+ glRecti(x+vselc*spacetext_get_fontwidth(st), y, x+vcurc*spacetext_get_fontwidth(st), y-st->lheight);
} else {
- linef= linel= text->curl;
-
- if (text->curc<text->selc) {
- charf= text->curc;
- charl= text->selc;
+ int froml, fromc, tol, toc;
+ if (vcurl < vsell) {
+ froml= vcurl; tol= vsell;
+ fromc= vcurc; toc= vselc;
} else {
- charf= text->selc;
- charl= text->curc;
+ froml= vsell; tol= vcurl;
+ fromc= vselc; toc= vcurc;
}
+ y -= froml*st->lheight;
+ glRecti(x+fromc*spacetext_get_fontwidth(st), y, curarea->winx, y-st->lheight); y-=st->lheight;
+ for (i=froml+1; i<tol; i++)
+ glRecti(x-4, y, curarea->winx, y-st->lheight), y-=st->lheight;
+ glRecti(x-4, y, x+toc*spacetext_get_fontwidth(st), y-st->lheight); y-=st->lheight;
}
-
- /* Walk to the beginning of visible text */
- h= txt_get_span(text->lines.first, linef) - st->top;
- while (h++<-1 && linef!=linel) linef= linef->next;
-
- x= text_draw(st, linef->line, st->left, charf, 0, 0, 0, NULL);
-
- BIF_ThemeColor(TH_SHADE2);
-
- if(st->showlinenrs) {
- if (!x) x= TXT_OFFSET + TEXTXLOC -4;
- } else {
- if (!x) x= TXT_OFFSET - 4;
- }
-
- while (linef && linef != linel) {
- h= txt_get_span(text->lines.first, linef) - st->top;
- if (h>st->viewlines) break;
-
- glRecti(x, curarea->winy-st->lheight*(h)-2, curarea->winx, curarea->winy-st->lheight*(h+1)-2);
- if(st->showlinenrs)
- glRecti(TXT_OFFSET+TEXTXLOC-4, curarea->winy-st->lheight*(h+1)-2, TXT_OFFSET+TEXTXLOC, curarea->winy-st->lheight*(h+2)-2);
- else
- glRecti(TXT_OFFSET-4, curarea->winy-st->lheight*(h+1)-2, TXT_OFFSET, curarea->winy-st->lheight*(h+2)-2);
-
- if(st->showlinenrs)
- x= TXT_OFFSET + TEXTXLOC;
- else
- x= TXT_OFFSET;
-
- linef= linef->next;
- }
-
- h= txt_get_span(text->lines.first, linef) - st->top;
-
- i= text_draw(st, linel->line, st->left, charl, 0, 0, 0, NULL);
- if(i) glRecti(x, curarea->winy-st->lheight*(h)-2, i, curarea->winy-st->lheight*(h+1)-2);
-
+ } else {
+ wrap_offset(st, text->sell, text->selc, &offl, &offc);
+ vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
+ vselc = get_char_pos(st, text->sell->line, text->selc) + offc;
}
/* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */
- x= text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL);
+ x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
+ x += vselc*spacetext_get_fontwidth(st);
+ y= curarea->winy-2 - vsell*st->lheight;
- if (x) {
- offl= offc= 0;
- if (st->wordwrap) wrap_offset(st, text->sell, text->selc, &offl, &offc);
- x += offc*spacetext_get_fontwidth(st);
- h= txt_get_span(text->lines.first, text->sell) - st->top + offl;
-
- if (st->overwrite) {
- ch[0]= (unsigned char) text->sell->line[text->selc];
- if (ch[0]=='\0') ch[0]=' ';
- ch[1]= '\0';
- w= BMF_GetStringWidth(spacetext_get_font(st), ch);
- BIF_ThemeColor(TH_SHADE2);
- glRecti(x, curarea->winy-st->lheight*(h)-2, x+w, curarea->winy-st->lheight*(h+1)-2);
- BIF_ThemeColor(TH_HILITE);
- glRecti(x, curarea->winy-st->lheight*(h+1)-3, x+w, curarea->winy-st->lheight*(h+1)-1);
- } else {
- BIF_ThemeColor(TH_HILITE);
- glRecti(x-1, curarea->winy-st->lheight*(h)-2, x+1, curarea->winy-st->lheight*(h+1)-2);
- }
+ if (st->overwrite) {
+ w= BMF_GetCharacterWidth(spacetext_get_font(st), text->sell->line[text->selc]);
+ BIF_ThemeColor(TH_HILITE);
+ glRecti(x, y-st->lheight-1, x+w, y-st->lheight+1);
+ } else {
+ BIF_ThemeColor(TH_HILITE);
+ glRecti(x-1, y, x+1, y-st->lheight);
}
do_brackets();
More information about the Bf-blender-cvs
mailing list