From be6ea8ff2c51a421536cde6f550f6f1edd71e617 Mon Sep 17 00:00:00 2001 From: Justin Dailey Date: Fri, 16 Nov 2012 01:12:01 +0000 Subject: fix [#33180] text editor line height issue Added small space between lines in the text editor. --- source/blender/editors/space_text/text_draw.c | 44 ++++++++++++++----------- source/blender/editors/space_text/text_intern.h | 1 + source/blender/editors/space_text/text_ops.c | 6 ++-- 3 files changed, 28 insertions(+), 23 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index f463b015bf5..76908e5b369 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1494,6 +1494,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar) Text *text = st->text; int vcurl, vcurc, vsell, vselc, hidden = 0; int x, y, w, i; + int lheight = st->lheight + TXT_LINE_SPACING; /* Draw the selection */ if (text->curl != text->sell || text->curc != text->selc) { @@ -1514,11 +1515,11 @@ static void draw_cursor(SpaceText *st, ARegion *ar) y = ar->winy - 2; if (vcurl == vsell) { - y -= vcurl * st->lheight; + y -= vcurl * lheight; if (vcurc < vselc) - glRecti(x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - st->lheight); + glRecti(x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - lheight + TXT_LINE_SPACING); else - glRecti(x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - st->lheight); + glRecti(x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - lheight + TXT_LINE_SPACING); } else { int froml, fromc, tol, toc; @@ -1532,12 +1533,12 @@ static void draw_cursor(SpaceText *st, ARegion *ar) fromc = vselc; toc = vcurc; } - y -= froml * st->lheight; - glRecti(x + fromc * st->cwidth - 1, y, ar->winx, y - st->lheight); y -= st->lheight; + y -= froml * lheight; + glRecti(x + fromc * st->cwidth - 1, y, ar->winx, y - lheight); y -= lheight; for (i = froml + 1; i < tol; i++) - glRecti(x - 4, y, ar->winx, y - st->lheight), y -= st->lheight; + glRecti(x - 4, y, ar->winx, y - lheight), y -= lheight; - glRecti(x - 4, y, x + toc * st->cwidth, y - st->lheight); y -= st->lheight; + glRecti(x - 4, y, x + toc * st->cwidth, y - lheight + TXT_LINE_SPACING); y -= lheight; } } else { @@ -1561,12 +1562,12 @@ static void draw_cursor(SpaceText *st, ARegion *ar) wrap_offset_in_line(st, ar, text->sell, text->selc, &offl, &offc); - y1 = ar->winy - 2 - (vsell - offl) * st->lheight; - y2 = y1 - st->lheight * visible_lines + 1; + y1 = ar->winy - 2 - (vsell - offl) * lheight; + y2 = y1 - lheight * visible_lines + 1; } else { - y1 = ar->winy - 2 - vsell * st->lheight; - y2 = y1 - st->lheight + 1; + y1 = ar->winy - 2 - vsell * lheight; + y2 = y1 - lheight + 1; } if (!(y1 < 0 || y2 > ar->winy)) { /* check we need to draw */ @@ -1577,7 +1578,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - glRecti(x1 - 4, y1, x2, y2); + glRecti(x1 - 4, y1, x2, y2 + TXT_LINE_SPACING); glDisable(GL_BLEND); } } @@ -1586,20 +1587,21 @@ static void draw_cursor(SpaceText *st, ARegion *ar) /* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */ x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; x += vselc * st->cwidth; - y = ar->winy - 2 - vsell * st->lheight; + y = ar->winy - 2 - vsell * lheight; if (st->overwrite) { char ch = text->sell->line[text->selc]; + y += TXT_LINE_SPACING; w = st->cwidth; if (ch == '\t') w *= st->tabnumber - (vselc + st->left) % st->tabnumber; UI_ThemeColor(TH_HILITE); - glRecti(x, y - st->lheight - 1, x + w, y - st->lheight + 1); + glRecti(x, y - lheight - 1, x + w, y - lheight + 1); } else { UI_ThemeColor(TH_HILITE); - glRecti(x - 1, y, x + 1, y - st->lheight); + glRecti(x - 1, y, x + 1, y - lheight + TXT_LINE_SPACING); } } } @@ -1714,8 +1716,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar) if (viewc >= 0) { viewl = txt_get_span(text->lines.first, startl) - st->top + offl; - text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * st->lheight, ch); - text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * st->lheight, ch); + text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * (st->lheight + TXT_LINE_SPACING), ch); + text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * (st->lheight + TXT_LINE_SPACING), ch); } /* draw closing bracket */ @@ -1726,8 +1728,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar) if (viewc >= 0) { viewl = txt_get_span(text->lines.first, endl) - st->top + offl; - text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * st->lheight, ch); - text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * st->lheight, ch); + text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * (st->lheight + TXT_LINE_SPACING), ch); + text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * (st->lheight + TXT_LINE_SPACING), ch); } } @@ -1743,7 +1745,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) int wraplinecount = 0, wrap_skip = 0; int margin_column_x; - if (st->lheight) st->viewlines = (int)ar->winy / st->lheight; + if (st->lheight) st->viewlines = (int)ar->winy / (st->lheight + TXT_LINE_SPACING); else st->viewlines = 0; /* if no text, nothing to do */ @@ -1839,6 +1841,8 @@ void draw_text_main(SpaceText *st, ARegion *ar) text_draw(st, tmp->line, st->left, ar->winx / st->cwidth, 1, x, y, tmp->format); y -= st->lheight; } + + y-= TXT_LINE_SPACING; wrap_skip = 0; } diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 4f973e7076b..d687f4cdd8a 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -57,6 +57,7 @@ void text_update_cursor_moved(struct bContext *C); #define TXT_OFFSET 15 #define TXT_SCROLL_WIDTH 20 #define TXT_SCROLL_SPACE 2 +#define TXT_LINE_SPACING 4 /* space between lines */ #define TEXTXLOC (st->cwidth * st->linenrs_tot) diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 105e20ffadb..ae5de4c6a25 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2202,10 +2202,10 @@ static void text_scroll_apply(bContext *C, wmOperator *op, wmEvent *event) if (!tsc->scrollbar) { txtdelta[0] = -tsc->delta[0] / st->cwidth; - txtdelta[1] = tsc->delta[1] / st->lheight; + txtdelta[1] = tsc->delta[1] / (st->lheight + TXT_LINE_SPACING); tsc->delta[0] %= st->cwidth; - tsc->delta[1] %= st->lheight; + tsc->delta[1] %= (st->lheight + TXT_LINE_SPACING); } else { txtdelta[1] = -tsc->delta[1] * st->pix_per_line; @@ -2599,7 +2599,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int { Text *text = st->text; text_update_character_width(st); - y = (ar->winy - 2 - y) / st->lheight; + y = (ar->winy - 2 - y) / (st->lheight + TXT_LINE_SPACING); if (st->showlinenrs) x -= TXT_OFFSET + TEXTXLOC; else x -= TXT_OFFSET; -- cgit v1.2.3