shithub: orca

Download patch

ref: 3cb575b88691ffaeff4e33b78b25e61b12e84d31
parent: e3b96ea3476cdc2f544847537a9052a31d961ede
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 14 21:19:00 EST 2020

plan9: faster redraw

--- a/plan9.c
+++ b/plan9.c
@@ -129,7 +129,7 @@
 static char *modes[Nummodes] = {
 	[Minsert] = "insert",
 	[Mappend] = "append",
-	[Mslide] = "slide",
+	[Mslide] = "slide ",
 	[Mselect] = "select",
 };
 
@@ -302,7 +302,7 @@
 }
 
 static void
-redraw(void)
+redraw(int complete)
 {
 	Rectangle r;
 	Point p, top, bot;
@@ -315,18 +315,20 @@
 	bot.x = top.x;
 	bot.y = screen->r.max.y - Txtoff - charh*2;
 
-	r = screen->r;
-	r.max.y = r.min.y + Txtoff;
-	draw(screen, r, color[Dback], nil, ZP);
-	r = screen->r;
-	r.max.x = r.min.x + Txtoff;
-	draw(screen, r, color[Dback], nil, ZP);
-	r = screen->r;
-	r.min.x += MIN(field.width*charw, Dx(r)-Txtoff) + Txtoff;
-	draw(screen, r, color[Dback], nil, ZP);
-	r = screen->r;
-	r.min.y = MIN(top.y + field.height*charh, bot.y-charh);
-	draw(screen, r, color[Dback], nil, ZP);
+	if (complete) {
+		r = screen->r;
+		r.max.y = r.min.y + Txtoff;
+		draw(screen, r, color[Dback], nil, ZP);
+		r = screen->r;
+		r.max.x = r.min.x + Txtoff;
+		draw(screen, r, color[Dback], nil, ZP);
+		r = screen->r;
+		r.min.x += MIN(field.width*charw, Dx(r)-Txtoff) + Txtoff;
+		draw(screen, r, color[Dback], nil, ZP);
+		r = screen->r;
+		r.min.y = MIN(top.y + field.height*charh, bot.y-charh);
+		draw(screen, r, color[Dback], nil, ZP);
+	}
 
 	bg = -1;
 	fg = -1;
@@ -393,49 +395,53 @@
 
 	/* field size */
 	p.x = screen->r.min.x + Txtoff;
-	len = MAX(3+1+3, runesprint(linebuf, "%udx%ud", field.width, field.height));
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	runesprint(linebuf, "%udx%ud        ", field.width, field.height);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
+	len = 5+1+5;
 
 	/* cursor position */
-	p.y += font->height;
-	runesprint(linebuf, "%ud,%ud", curx, cury);
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	p.y += charh;
+	runesprint(linebuf, "%ud,%ud        ", curx, cury);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
 
 	/* selection size */
 	p.x += charw * (len + Coloff);
-	len = MAX(2+1+2, runesprint(linebuf, "%d:%d", selw, selh));
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	runesprint(linebuf, "%d:%d    ", selw, selh);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
+	len = 3+1+3;
 
 	/* grid size */
-	p.y -= font->height;
+	p.y -= charh;
 	runesprint(linebuf, "%d/%d", gridw, gridh);
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
 
 	/* ticks */
 	p.x += charw * (len + Coloff);
 	runesprint(linebuf, "%lldf", MAX(0, tick));
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
 
 	/* insert/append mode */
-	p.y += font->height;
-	len = MAX(6, runesprint(linebuf, "%s", modes[altdown ? Mslide : mode]));
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	p.y += charh;
+	runesprint(linebuf, "%s", modes[altdown ? Mslide : mode]);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
+	len = 6;
 
 	/* bpm */
-	p.y -= font->height;
+	p.y -= charh;
 	p.x += charw * (len + Coloff);
-	len = MAX(6, runesprint(linebuf, "%d", bpm));
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	runesprint(linebuf, "%d     ", bpm);
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
+	len = 6;
 
 	/* filename */
-	p.y += font->height;
-	string(screen, p, color[Dfhigh], ZP, font, filename[0] ? filename : "unnamed");
+	p.y += charh;
+	stringbg(screen, p, color[Dfhigh], ZP, font, filename[0] ? filename : "unnamed", color[Dback], ZP);
 
 	/* frame deviation */
-	p.y -= font->height;
+	p.y -= charh;
 	p.x += charw * (len + Coloff);
-	len = MAX(6, runesprint(linebuf, "%ldms", labs(framedev)));
-	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
+	runesprint(linebuf, "%ldms       ", labs(framedev));
+	runestringbg(screen, p, color[Dfhigh], ZP, font, linebuf, color[Dback], ZP);
 
 	USED(len);
 
@@ -593,11 +599,6 @@
 }
 
 static void
-select(void)
-{
-}
-
-static void
 kbdproc(void *k)
 {
 	char buf[128], buf2[128], *s;
@@ -672,7 +673,7 @@
 	Mouse m;
 	char tmp[256];
 	Channel *kchan;
-	int oldw, oldh, w, h, n, shiftdown;
+	int oldw, oldh, w, h, n, shiftdown, complete;
 	Alt a[Numchan+1] = {
 		[Cchar] = { nil, &key.rune, CHANRCV },
 		[Ckey] = { nil, &key, CHANRCV },
@@ -723,21 +724,17 @@
 	proccreate(orcathread, a[Credraw].c, mainstacksize);
 	shiftdown = 0;
 	altdown = 0;
+	complete = 1;
 
 	for (;;) {
-		redraw();
+		redraw(complete);
+		complete = 0;
 		oldw = w = field.width;
 		oldh = h = field.height;
 
 		switch (alt(a)) {
 		case Cmouse:
-			switch (m.buttons & 7) {
-			case 1:
-				select();
-				break;
-			case 2:
-				break;
-			case 4:
+			if (m.buttons == 4) {
 				menu3i[Menu3dotstyle] = tmp;
 				menu3i[Menu3rulerstyle] = 1 + menu3i[Menu3dotstyle] + sprintf(tmp, "%s dots", style[(dotstyle+1) % Numstyles]);
 				sprintf(menu3i[Menu3rulerstyle], "%s rulers", style[(rulerstyle+1) % Numstyles]);
@@ -749,8 +746,10 @@
 							w = field.width;
 							h = field.height;
 							strncpy(filename, tmp, sizeof(filename));
+							complete = 1;
 						} else if (n == Menu3save && fieldsave(tmp) == 0) {
 							strncpy(filename, tmp, sizeof(filename));
+							complete = 1;
 						}
 					}
 				} else if (n == Menu3dotstyle) {
@@ -758,12 +757,12 @@
 				} else if (n == Menu3rulerstyle) {
 					rulerstyle = ++rulerstyle % Numstyles;
 				}
-				break;
 			}
 			break;
 
 		case Cresize:
 			getwindow(display, Refnone);
+			complete = 1;
 			break;
 
 		case Ckey:
@@ -949,6 +948,7 @@
 		if (w != oldw || h != oldh) {
 			mbuf_reusable_ensure_size(&mbuf, h, w);
 			linebuf = realloc(linebuf, sizeof(Rune)*MAX(w+1, 64));
+			complete = 1;
 		}
 	}