ref: 1faf0b55cd978d5b16d655429ca6819c5bbf5b15
parent: f57b5cb6017c682427ccfa96a96e4f478a5c86b0
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 14 05:35:42 EST 2020
plan9: getting to style it properly
--- a/plan9.c
+++ b/plan9.c
@@ -22,10 +22,27 @@
Credraw,
Numchan,
+ Sfancy = 0,
+ Splain,
+ Snone,
+ Numstyles,
+
Minsert = 0,
Mappend,
Mslide,
Mselect,
+ Nummodes,
+
+ Dback = 0,
+ Dfhigh,
+ Dfmed,
+ Dflow,
+ Dfinv,
+ Dbhigh,
+ Dbmed,
+ Dblow,
+ Dbinv,
+ Numcolors,
};
typedef struct Key Key;
@@ -40,13 +57,37 @@
Rune rune;
};
+static Rune dot[Numstyles] = {
+ [Sfancy] = L'·',
+ [Splain] = '.',
+ [Snone] = ' ',
+};
+
+static Rune ruler[Numstyles][9] = {
+ [Sfancy] = {
+ L'┌', L'┬', L'┐',
+ L'├', L'┼', L'┤',
+ L'└', L'┴', L'┘',
+ },
+ [Splain] = {
+ '+', '+', '+',
+ '+', '+', '+',
+ '+', '+', '+',
+ },
+ [Snone] = {
+ ' ', ' ', ' ',
+ ' ', ' ', ' ',
+ ' ', ' ', ' ',
+ },
+};
+
static Rune *linebuf;
static Usz tick;
static int gridw = 8, gridh = 8;
+static int rulerstyle = Sfancy, dotstyle = Sfancy;
static int bpm = 120, pause;
static int curx, cury;
static int selw = 1, selh = 1;
-static Image *curbg;
static int charw, charh;
static Field field;
static Mbuf_reusable mbuf;
@@ -58,7 +99,21 @@
static int mode = Minsert;
static long framedev; /* frame deviation >= 1µs */
-static char *modes[] = {
+static u32int theme[Numcolors] = {
+ [Dback] = 0x000000ff,
+ [Dfhigh] = 0xffffffff,
+ [Dfmed] = 0x777777ff,
+ [Dflow] = 0x444444ff,
+ [Dfinv] = 0x000000ff,
+ [Dbhigh] = 0xddddddff,
+ [Dbmed] = 0x72dec2ff,
+ [Dblow] = 0x222222ff,
+ [Dbinv] = 0xffb545ff,
+};
+
+static Image *color[Numcolors];
+
+static char *modes[Nummodes] = {
[Minsert] = "insert",
[Mappend] = "append",
[Mslide] = "slide",
@@ -238,9 +293,9 @@
{
Rectangle r;
Point p, top, bot;
- int x, y, len;
+ int x, y, len, rx, ry;
- draw(screen, screen->r, display->black, nil, ZP);
+ draw(screen, screen->r, color[Dback], nil, ZP);
p = screen->r.min;
p.x += Txtoff;
p.y += Txtoff;
@@ -251,12 +306,18 @@
for (y = 0; y < field.height && p.y < bot.y-charh; y++) {
for (x = 0; x < field.width; x++) {
Rune c = field.buffer[field.width*y + x];
- if (c == L'.')
- c = L'·';
+ if (c == '.') {
+ c = dot[dotstyle];
+ if ((x % gridw) == 0 && (y % gridh) == 0) {
+ rx = x == 0 ? 0 : (x == field.width-1 ? 2 : 1);
+ ry = y == 0 ? 0 : (y == field.height-1 ? 2 : 1);
+ c = ruler[dotstyle][ry*3+rx];
+ }
+ }
linebuf[x] = c;
}
linebuf[x] = 0;
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dflow], ZP, font, linebuf);
p.y += font->height;
}
@@ -265,48 +326,48 @@
/* 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, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* cursor position */
p.y += font->height;
runesprint(linebuf, "%ud,%ud", curx, cury);
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* selection size */
p.x += charw * (len + Coloff);
len = MAX(2+1+2, runesprint(linebuf, "%d:%d", selw, selh));
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* grid size */
p.y -= font->height;
runesprint(linebuf, "%d/%d", gridw, gridh);
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* ticks */
p.x += charw * (len + Coloff);
runesprint(linebuf, "%ludf", tick);
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* insert/append mode */
p.y += font->height;
len = MAX(6, runesprint(linebuf, "%s", modes[altdown ? Mslide : mode]));
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* bpm */
p.y -= font->height;
p.x += charw * (len + Coloff);
len = MAX(6, runesprint(linebuf, "%d", bpm));
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
/* filename */
p.y += font->height;
- string(screen, p, display->white, ZP, font, filename[0] ? filename : "unnamed");
+ string(screen, p, color[Dfhigh], ZP, font, filename[0] ? filename : "unnamed");
/* frame deviation */
p.y -= font->height;
p.x += charw * (len + Coloff);
len = MAX(6, runesprint(linebuf, "%ldµs", labs(framedev)));
- runestring(screen, p, display->white, ZP, font, linebuf);
+ runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
USED(len);
@@ -318,7 +379,7 @@
r.max = p;
r.max.x += selw * charw;
r.max.y += selh * charh;
- draw(screen, r, curbg, nil, ZP);
+ draw(screen, r, color[Dbinv], nil, ZP);
flushimage(display, 1);
}
@@ -586,7 +647,8 @@
a[Cresize].c = mctl->resizec;
a[Credraw].c = chancreate(sizeof(ulong), 1);
- curbg = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, setalpha(DYellow, 128));
+ for (n = 0; n < Numcolors; n++)
+ color[n] = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, setalpha(theme[n] & ~0xff, theme[n] & 0xff));
charw = stringwidth(font, "X");
charh = font->height;