ref: ffc9934ccdba5b995ea087ad6f08c4e864b0bd4b
parent: 5d24d81bb734f235a1abb57aa0322e980383c966
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 14 18:19:36 EST 2020
plan9: simplify redraw a bit
--- a/plan9.c
+++ b/plan9.c
@@ -303,10 +303,9 @@
static void
redraw(void)
{
- Rectangle r;
Point p, top, bot;
int x, y, len, rx, ry;
- int bg, fg, attr;
+ int bg, fg, attr, selected;
Rune c;
draw(screen, screen->r, color[Dback], nil, ZP);
@@ -317,17 +316,6 @@
bot.x = top.x;
bot.y = screen->r.max.y - Txtoff - charh*2;
- /* cursor bg */
- p.x += curx * charw;
- p.y += cury * charh;
- r.min = p;
- r.max = p;
- r.max.x += selw * charw;
- r.max.y += selh * charh;
- draw(screen, r, color[Dbinv], nil, ZP);
-
- p = top;
-
for (y = 0; y < field.height && p.y < bot.y-charh; y++) {
for (x = 0; x < field.width; x++) {
c = field.buffer[field.width*y + x];
@@ -336,6 +324,10 @@
if (c == '.')
c = dot[dotstyle];
+ selected = x >= curx && y >= cury && x < curx+selw && y < cury+selh;
+ bg = selected ? Dbinv : Dback;
+ fg = selected ? Dfinv : Dfhigh;
+
if (c == dot[dotstyle] && attr == 0) {
if ((x % gridw) == 0 && (y % gridh) == 0) {
rx = !!x + (x + 1) / field.width;
@@ -342,13 +334,8 @@
ry = !!y + (y + 1) / field.height;
c = ruler[rulerstyle][ry*3+rx];
}
- runestringn(screen, p, color[Dflow], ZP, font, &c, 1);
- } else if (x >= curx && y >= cury && x < curx+selw && y < cury+selh) {
- runestringn(screen, p, color[Dfinv], ZP, font, &c, 1);
- } else {
- bg = Dback;
- fg = Dfhigh;
-
+ fg = Dflow;
+ } else if (!selected) {
if (c == '#') {
fg = Dfmed;
} else {
@@ -372,8 +359,8 @@
bg = Dback;
fg = Dbmed;
}
- runestringnbg(screen, p, color[fg], ZP, font, &c, 1, color[bg], ZP);
}
+ runestringnbg(screen, p, color[fg], ZP, font, &c, 1, color[bg], ZP);
p.x += charw;
}
p.y += font->height;