diff options
Diffstat (limited to 'source/blender/editors/space_text/text_draw.c')
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 270 |
1 files changed, 199 insertions, 71 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 46ab2d9e688..1818c4a5b31 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -51,7 +51,11 @@ #include "BKE_suggestions.h" #include "BKE_text.h" -#include "BIF_gl.h" +#include "GPU_colors.h" +#include "GPU_primitives.h" +#include "GPU_utility.h" + +#include "BIF_glutil.h" #include "ED_datafiles.h" #include "UI_interface.h" @@ -92,18 +96,6 @@ static int text_font_draw_character(SpaceText *st, int x, int y, char c) return st->cwidth; } -static int text_font_draw_character_utf8(SpaceText *st, int x, int y, const char *c) -{ - char str[BLI_UTF8_MAX + 1]; - size_t len = BLI_str_utf8_size_safe(c); - memcpy(str, c, len); - str[len] = '\0'; - - BLF_position(mono, x, y, 0); - BLF_draw(mono, str, len); - - return st->cwidth; -} /****************** flatten string **********************/ @@ -147,14 +139,15 @@ int flatten_string(SpaceText *st, FlattenString *fs, const char *in) fs->accum = fs->fixedaccum; fs->len = sizeof(fs->fixedbuf); - for (r = 0, i = 0; *in; r++) { + i = 0; + for (r = 0; *in; r++) { if (*in == '\t') { i = st->tabnumber - (total % st->tabnumber); total += i; - + while (i--) flatten_string_append(fs, " ", r, 1); - + in++; } else { @@ -164,7 +157,7 @@ int flatten_string(SpaceText *st, FlattenString *fs, const char *in) total++; } } - + flatten_string_append(fs, "\0", r, 1); return total; @@ -721,6 +714,11 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w for (i = 0, mi = 0; str[mi]; i++, mi += BLI_str_utf8_size_safe(str + mi)) { if (i - start >= max) { + int ox; + char last_format; + char buffer[BLF_DRAW_STR_DUMMY_MAX]; + size_t len = 0; + /* skip hidden part of line */ if (skip) { skip--; @@ -729,11 +727,43 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w continue; } + if (st->showsyntax && format) { + last_format = format[start]; + format_draw_color(format[start]); + } + + ox = x; + + ma = mstart; + /* Draw the visible portion of text on the overshot line */ - for (a = start, ma = mstart; a < end; a++, ma += BLI_str_utf8_size_safe(str + ma)) { - if (st->showsyntax && format) format_draw_color(format[a]); - x += text_font_draw_character_utf8(st, x, y, str + ma); + for (a = start; a < end; a++) { + size_t char_len; + + if (st->showsyntax && format && last_format != format[a]) { + memcpy(buffer, str + ma - len, len); + buffer[len] = '\0'; + text_font_draw(st, ox, y, buffer); + + ox = x; + len = 0; + + format_draw_color(format[a]); + last_format = format[a]; + } + + char_len = BLI_str_utf8_size(str + ma); + len += char_len; + ma += char_len; + + x += st->cwidth; } + + /* draw last chunk */ + memcpy(buffer, str + ma - len, len); + buffer[len] = '\0'; + text_font_draw(st, ox, y, buffer); + y -= st->lheight + TXT_LINE_SPACING; x = basex; lines++; @@ -748,11 +778,48 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w } /* Draw the remaining text */ - for (a = start, ma = mstart; str[ma] && y > 0; a++, ma += BLI_str_utf8_size_safe(str + ma)) { - if (st->showsyntax && format) - format_draw_color(format[a]); + if (y > 0) { + int ox; + char last_format; + char buffer[BLF_DRAW_STR_DUMMY_MAX]; + size_t len = 0; + const int showsyntax = st->showsyntax && format; + + if (showsyntax) { + last_format = format[start]; + format_draw_color(format[start]); + } + + ox = x; + + ma = mstart; + + for (a = start; str[ma]; a++) { + size_t char_len; + + if (showsyntax && last_format != format[a]) { + memcpy(buffer, str + ma - len, len); + buffer[len] = '\0'; + text_font_draw(st, ox, y, buffer); + + ox = x; + len = 0; + + format_draw_color(format[a]); + last_format = format[a]; + } + + char_len = BLI_str_utf8_size(str + ma); + len += char_len; + ma += char_len; + + x += st->cwidth; + } - x += text_font_draw_character_utf8(st, x, y, str + ma); + /* draw last chunk */ + memcpy(buffer, str + ma - len, len); + buffer[len] = '\0'; + text_font_draw(st, ox, y, buffer); } flatten_string_free(&fs); @@ -777,17 +844,52 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra w = w - cshift; if (draw) { - int amount = maxwidth ? MIN2(w, maxwidth) : w; - + int amount = + maxwidth ? + MIN3(w, maxwidth, BLF_DRAW_STR_DUMMY_MAX) : + MIN2(w, BLF_DRAW_STR_DUMMY_MAX); + if (st->showsyntax && format) { - int a, str_shift = 0; + int a; + int str_shift = 0; + int ox; + char last_format; + char buffer[BLF_DRAW_STR_DUMMY_MAX]; + size_t len = 0; + format = format + cshift; + last_format = format[0]; + format_draw_color(format[0]); + + ox = x; + for (a = 0; a < amount; a++) { - format_draw_color(format[a]); - x += text_font_draw_character_utf8(st, x, y, in + str_shift); - str_shift += BLI_str_utf8_size_safe(in + str_shift); + size_t char_len; + + if (last_format != format[a]) { + memcpy(buffer, in + str_shift - len, len); + buffer[len] = '\0'; + text_font_draw(st, ox, y, buffer); + + ox = x; + len = 0; + + format_draw_color(format[a]); + last_format = format[a]; + } + + char_len = BLI_str_utf8_size(in + str_shift); + str_shift += char_len; + len += char_len; + + x += st->cwidth; } + + /* draw last chunk */ + memcpy(buffer, in + str_shift - len, len); + buffer[len] = '\0'; + text_font_draw(st, ox, y, buffer); } else text_font_draw(st, x, y, in); } @@ -1193,7 +1295,7 @@ static void draw_textscroll(SpaceText *st, rcti *scroll, rcti *back) float rad; UI_ThemeColor(TH_BACK); - glRecti(back->xmin, back->ymin, back->xmax, back->ymax); + gpuSingleFilledRecti(back->xmin, back->ymin, back->xmax, back->ymax); uiWidgetScrollDraw(&wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT) ? UI_SCROLL_PRESSED : 0); @@ -1201,7 +1303,7 @@ static void draw_textscroll(SpaceText *st, rcti *scroll, rcti *back) rad = 0.4f * min_ii(BLI_rcti_size_x(&st->txtscroll), BLI_rcti_size_y(&st->txtscroll)); UI_GetThemeColor3ubv(TH_HILITE, col); col[3] = 48; - glColor4ubv(col); + gpuCurrentColor4ubv(col); glEnable(GL_BLEND); uiRoundBox(st->txtscroll.xmin + 1, st->txtscroll.ymin, st->txtscroll.xmax - 1, st->txtscroll.ymax, rad); glDisable(GL_BLEND); @@ -1243,26 +1345,30 @@ static void draw_documentation(SpaceText *st, ARegion *ar) /* Draw panel */ UI_ThemeColor(TH_BACK); - glRecti(x, y, x + boxw, y - boxh); + gpuSingleFilledRecti(x, y, x + boxw, y - boxh); UI_ThemeColor(TH_SHADE1); - glBegin(GL_LINE_LOOP); - glVertex2i(x, y); - glVertex2i(x + boxw, y); - glVertex2i(x + boxw, y - boxh); - glVertex2i(x, y - boxh); - glEnd(); - glBegin(GL_LINE_LOOP); - glVertex2i(x + boxw - 10, y - 7); - glVertex2i(x + boxw - 4, y - 7); - glVertex2i(x + boxw - 7, y - 2); - glEnd(); - glBegin(GL_LINE_LOOP); - glVertex2i(x + boxw - 10, y - boxh + 7); - glVertex2i(x + boxw - 4, y - boxh + 7); - glVertex2i(x + boxw - 7, y - boxh + 2); - glEnd(); + gpuImmediateFormat_V2(); + gpuBegin(GL_LINE_LOOP); + gpuVertex2i(x, y); + gpuVertex2i(x + boxw, y); + gpuVertex2i(x + boxw, y - boxh); + gpuVertex2i(x, y - boxh); + gpuEnd(); + gpuBegin(GL_LINE_LOOP); + gpuVertex2i(x + boxw - 10, y - 7); + gpuVertex2i(x + boxw - 4, y - 7); + gpuVertex2i(x + boxw - 7, y - 2); + gpuEnd(); + gpuBegin(GL_LINE_LOOP); + gpuVertex2i(x + boxw - 10, y - boxh + 7); + gpuVertex2i(x + boxw - 4, y - boxh + 7); + gpuVertex2i(x + boxw - 7, y - boxh + 2); + gpuEnd(); + gpuImmediateUnformat(); UI_ThemeColor(TH_TEXT); + BLF_draw_lock(mono); + i = 0; br = DOC_WIDTH; lines = 0; // XXX -doc_scroll; for (p = docs; *p; p++) { if (*p == '\r' && *(++p) != '\n') *(--p) = '\n'; /* Fix line endings */ @@ -1289,6 +1395,8 @@ static void draw_documentation(SpaceText *st, ARegion *ar) if (lines >= DOC_HEIGHT) break; } + BLF_draw_unlock(mono); + if (0 /* XXX doc_scroll*/ > 0 && lines < DOC_HEIGHT) { // XXX doc_scroll--; draw_documentation(st, ar); @@ -1332,9 +1440,11 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar) boxh = SUGG_LIST_SIZE * st->lheight + 8; UI_ThemeColor(TH_SHADE1); - glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1); + gpuSingleFilledRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1); UI_ThemeColor(TH_BACK); - glRecti(x, y, x + boxw, y - boxh); + gpuSingleFilledRecti(x, y, x + boxw, y - boxh); + + BLF_draw_lock(mono); /* Set the top 'item' of the visible list */ for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ; @@ -1349,7 +1459,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar) if (item == sel) { UI_ThemeColor(TH_SHADE2); - glRecti(x + 16, y - 3, x + 16 + w, y + st->lheight - 3); + gpuSingleFilledRecti(x + 16, y - 3, x + 16 + w, y + st->lheight - 3); } b = 1; /* b=1 color block, text is default. b=0 no block, color text */ switch (item->type) { @@ -1360,13 +1470,15 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar) case '?': UI_ThemeColor(TH_TEXT); b = 0; break; } if (b) { - glRecti(x + 8, y + 2, x + 11, y + 5); + gpuSingleFilledRecti(x + 8, y + 2, x + 11, y + 5); UI_ThemeColor(TH_TEXT); } text_draw(st, str, 0, 0, 1, x + 16, y - 1, NULL); if (item == last) break; } + + BLF_draw_unlock(mono); } /*********************** draw cursor ************************/ @@ -1399,9 +1511,9 @@ static void draw_cursor(SpaceText *st, ARegion *ar) if (vcurl == vsell) { y -= vcurl * lheight; if (vcurc < vselc) - glRecti(x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - lheight + TXT_LINE_SPACING); + gpuSingleFilledRecti(x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - st->lheight + TXT_LINE_SPACING); else - glRecti(x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - lheight + TXT_LINE_SPACING); + gpuSingleFilledRecti(x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - st->lheight + TXT_LINE_SPACING); } else { int froml, fromc, tol, toc; @@ -1416,11 +1528,16 @@ static void draw_cursor(SpaceText *st, ARegion *ar) } y -= froml * lheight; - glRecti(x + fromc * st->cwidth - 1, y, ar->winx, y - lheight); y -= lheight; + gpuSingleFilledRecti(x + fromc * st->cwidth - 1, y, ar->winx, y - st->lheight); + y -= st->lheight; for (i = froml + 1; i < tol; i++) - glRecti(x - 4, y, ar->winx, y - lheight), y -= lheight; - glRecti(x - 4, y, x + toc * st->cwidth, y - lheight + TXT_LINE_SPACING); y -= lheight; + for (i = froml + 1; i < tol; i++) { + gpuSingleFilledRecti(x - 4, y, ar->winx, y - st->lheight + TXT_LINE_SPACING); + y -= st->lheight; + } + + gpuSingleFilledRecti(x - 4, y, x + toc * st->cwidth, y - st->lheight); } } else { @@ -1456,15 +1573,14 @@ static void draw_cursor(SpaceText *st, ARegion *ar) x1 = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; x2 = x1 + ar->winx; - glColor4ub(255, 255, 255, 32); + gpuCurrentColor4x(CPACK_WHITE, 0.125f); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - glRecti(x1 - 4, y1, x2, y2 + TXT_LINE_SPACING); + gpuSingleFilledRecti(x1 - 4, y1, x2, y2 + TXT_LINE_SPACING); glDisable(GL_BLEND); } } - + if (!hidden) { /* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */ x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; @@ -1479,11 +1595,11 @@ static void draw_cursor(SpaceText *st, ARegion *ar) if (ch == '\t') w *= st->tabnumber - (vselc + st->left) % st->tabnumber; UI_ThemeColor(TH_HILITE); - glRecti(x, y - lheight - 1, x + w, y - lheight + 1); + gpuSingleFilledRecti(x, y - lheight - 1, x + w, y - lheight + 1); } else { UI_ThemeColor(TH_HILITE); - glRecti(x - 1, y, x + 1, y - lheight + TXT_LINE_SPACING); + gpuSingleFilledRecti(x - 1, y, x + 1, y - lheight + TXT_LINE_SPACING); } } } @@ -1680,7 +1796,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) x = TXT_OFFSET + TEXTXLOC; UI_ThemeColor(TH_GRID); - glRecti((TXT_OFFSET - 12), 0, (TXT_OFFSET - 5) + TEXTXLOC, ar->winy - 2); + gpuSingleFilledRecti((TXT_OFFSET - 12), 0, (TXT_OFFSET - 5) + TEXTXLOC, ar->winy - 2); } else { st->linenrs_tot = 0; /* not used */ @@ -1695,6 +1811,10 @@ void draw_text_main(SpaceText *st, ARegion *ar) /* draw the text */ UI_ThemeColor(TH_TEXT); + GPU_STRING_MARKER("draw_text_main:begin"); + + BLF_draw_lock(mono); + for (i = 0; y > 0 && i < st->viewlines && tmp; i++, tmp = tmp->next) { if (st->showsyntax && !tmp->format) txt_format_line(st, tmp, 0); @@ -1726,23 +1846,29 @@ void draw_text_main(SpaceText *st, ARegion *ar) wrap_skip = 0; } - + + BLF_draw_unlock(mono); + + GPU_STRING_MARKER("draw_text_main:end"); + if (st->flags & ST_SHOW_MARGIN) { UI_ThemeColor(TH_HILITE); margin_column_x = x + st->cwidth * (st->margin_column - st->left); if (margin_column_x >= x) { - glBegin(GL_LINES); - glVertex2i(margin_column_x, 0); - glVertex2i(margin_column_x, ar->winy - 2); - glEnd(); + gpuImmediateFormat_V2(); + gpuBegin(GL_LINES); + gpuVertex2i(x + st->cwidth * st->margin_column, 0); + gpuVertex2i(x + st->cwidth * st->margin_column, ar->winy - 2); + gpuEnd(); + gpuImmediateUnformat(); } } /* draw other stuff */ draw_brackets(st, ar); - glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0f); /* XXX scroll requires exact pixel space */ + gpuTranslate(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0f); /* XXX scroll requires exact pixel space */ draw_textscroll(st, &scroll, &back); draw_documentation(st, ar); draw_suggestion_list(st, ar); @@ -1796,7 +1922,9 @@ void text_scroll_to_cursor(SpaceText *st, ScrArea *sa) st->left = 0; } else { + BLF_draw_lock(mono); x = text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL); + BLF_draw_unlock(mono); if (x == 0 || x > winx) st->left = text->curc - 0.5 * winx / st->cwidth; |