diff options
author | Kent Overstreet <koverstreet@google.com> | 2013-03-18 06:53:09 -0700 |
---|---|---|
committer | Kent Overstreet <koverstreet@google.com> | 2013-04-23 16:37:36 -0700 |
commit | 7acf588020999e1c5369dff96c9f31566291ae46 (patch) | |
tree | 0f6f84ef2bbf97b59a27e9241dbeba7a06862f75 | |
parent | 77c8d0b761b09239d20b171b633f18476f4ed955 (diff) |
revamp drawregion()
-rw-r--r-- | st.c | 63 |
1 files changed, 30 insertions, 33 deletions
@@ -575,52 +575,49 @@ static void xdrawcursor(struct st_window *xw) } } -static void drawregion(struct st_window *xw, - int x1, int y1, int x2, int y2) +static struct st_glyph sel_glyph(struct st_window *xw, unsigned x, unsigned y) { - int ic, ib, x, y, ox; - struct st_glyph base, new; - bool ena_sel = xw->term.sel.bx != -1; + struct st_glyph ret = xw->term.line[y][x]; - if (xw->term.sel.alt != xw->term.altscreen) - ena_sel = 0; + if (xw->term.sel.bx != -1 && + xw->term.sel.alt == xw->term.altscreen && + term_selected(&xw->term.sel, x, y)) + ret.reverse ^= 1; + + return ret; +} + +static void draw(struct st_window *xw) +{ + struct coord pos; if (!xw->visible) return; - for (y = y1; y < y2; y++) { - if (!xw->term.dirty[y]) + for (pos.y = 0; pos.y < xw->term.size.y; pos.y++) { + if (!xw->term.dirty[pos.y]) continue; - xw->term.dirty[y] = 0; - base = xw->term.line[y][0]; - ic = ib = ox = 0; - for (x = x1; x < x2; x++) { - new = xw->term.line[y][x]; - if (ena_sel && new.c && term_selected(&xw->term.sel, x, y)) - new.reverse ^= 1; - if (ic > 0 && new.cmp != base.cmp) { - xdraw_glyphs(xw, (struct coord) {ox, y}, - base, &xw->term.line[y][ox], ic); - ic = 0; - } - if (ic == 0) { - ox = x; - base = new; - } + xw->term.dirty[pos.y] = 0; - ++ic; + pos.x = 0; + + while (pos.x < xw->term.size.x) { + unsigned x2 = pos.x + 1; + struct st_glyph base = sel_glyph(xw, pos.x, pos.y); + + while (x2 < xw->term.size.x && + base.cmp == sel_glyph(xw, x2, pos.y).cmp) + x2++; + + xdraw_glyphs(xw, pos, base, + term_pos(&xw->term, pos), x2 - pos.x); + pos.x = x2; } - if (ic > 0) - xdraw_glyphs(xw, (struct coord) {ox, y}, - base, &xw->term.line[y][ox], ic); } + xdrawcursor(xw); -} -static void draw(struct st_window *xw) -{ - drawregion(xw, 0, 0, xw->term.size.x, xw->term.size.y); XCopyArea(xw->dpy, xw->buf, xw->win, xw->gc, 0, 0, xw->winsize.x, xw->winsize.y, 0, 0); XSetForeground(xw->dpy, xw->gc, |