ref: 7efd7e49120af31c6600effbe2f94b6618a020b5
parent: 1353aa191fcf796a947f79cd5e7885b991e3e805
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 17 07:57:39 EST 2020
plan9: use Point instead of separate int vars
--- a/plan9.c
+++ b/plan9.c
@@ -67,12 +67,12 @@
static Rune *linebuf;
static vlong tick;
-static int gridw = 8, gridh = 8;
static int rulerstyle = Sfancy, dotstyle = Sfancy;
static int bpm = 120, apm = 120;
+static Point grid = {8, 8};
+static Point glyphsz;
static Point cur;
static Rectangle sel;
-static int charw, charh;
static Field field;
static Mbuf_reusable mbuf, mscr;
static char filename[256];
@@ -180,6 +180,7 @@
case ';':
case '=':
case '?':
+ case '$':
return true;
}
return false;
@@ -365,7 +366,7 @@
p = addpt(screen->r.min, Pt(Txtoff, Txtoff));
top = p;
bot.x = top.x;
- bot.y = screen->r.max.y - Txtoff - charh*2;
+ bot.y = screen->r.max.y - Txtoff - glyphsz.y*2;
if (complete) {
r = screen->r;
@@ -375,7 +376,7 @@
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;
+ r.min.x += MIN(field.width*glyphsz.x, Dx(r)-Txtoff) + Txtoff;
draw(screen, r, color[Dback], nil, ZP);
}
@@ -384,7 +385,7 @@
bg = -1;
fg = -1;
- for (y = 0; y < field.height && p.y < bot.y-charh; y++) {
+ for (y = 0; y < field.height && p.y < bot.y-glyphsz.y; y++) {
p.x = top.x;
for (x = i = 0; x < field.width && x < screen->r.max.x-Txtoff; x++) {
oldbg = bg;
@@ -414,7 +415,7 @@
p = runestringnbg(screen, p, color[oldfg], ZP, font, linebuf, i, color[oldbg], ZP);
i = 0;
}
- p.x += charw;
+ p.x += glyphsz.x;
continue;
}
@@ -428,7 +429,7 @@
c = dot[dotstyle];
if (c == dot[dotstyle] && attr == 0) {
- if ((x % gridw) == 0 && (y % gridh) == 0) {
+ if ((x % grid.x) == 0 && (y % grid.y) == 0) {
rx = !!x + (x + 1) / field.width;
ry = !!y + (y + 1) / field.height;
c = rulerstyle == Snone ? dot[dotstyle] : ruler[rulerstyle][ry*3+rx];
@@ -468,17 +469,17 @@
linebuf[i++] = c;
}
runestringnbg(screen, p, color[fg], ZP, font, linebuf, i, color[bg], ZP);
- p.y += charh;
+ p.y += glyphsz.y;
}
r = screen->r;
- r.min.y = MIN(top.y + field.height*charh, bot.y-charh);
+ r.min.y = MIN(top.y + field.height*glyphsz.y, bot.y-glyphsz.y);
draw(screen, r, color[Dback], nil, ZP);
i = 0;
sprint(s, "%udx%ud", field.width, field.height);
i += runesprint(linebuf, "%-10s", s);
- sprint(s, "%d/%d", gridw, gridh);
+ sprint(s, "%d/%d", grid.x, grid.y);
i += runesprint(linebuf+i, "%-9s", s);
sprint(s, "%lldf%c", MAX(0, tick), pause ? '~' : 0);
i += runesprint(linebuf+i, "%-9s", s);
@@ -490,7 +491,7 @@
sprint(s, "%ldms", labs(framedev));
i += runesprint(linebuf+i, "%-8s", s);
runestringn(screen, bot, color[Dfhigh], ZP, font, linebuf, i);
- bot.y += charh;
+ bot.y += glyphsz.y;
i = 0;
sprint(s, "%ud,%ud", cur.x, cur.y);
@@ -712,8 +713,8 @@
static void
screensize(int *w, int *h)
{
- *w = snaplow((Dx(screen->r) - 2*Txtoff) / charw, gridw);
- *h = snaplow(((Dy(screen->r) - 2*Txtoff) - 3*charh) / charh, gridh);
+ *w = snaplow((Dx(screen->r) - 2*Txtoff) / glyphsz.x, grid.x);
+ *h = snaplow(((Dy(screen->r) - 2*Txtoff) - 3*glyphsz.y) / glyphsz.y, grid.y);
}
static void
@@ -843,8 +844,8 @@
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;
+ glyphsz.x = stringwidth(font, "X");
+ glyphsz.y = font->height;
screensize(&w, &h);
field_init_fill(&field, h, w, '.');
@@ -924,8 +925,8 @@
break;
case Kctl:
ctldown = key.down;
- movex = ctldown ? gridw : 1;
- movey = ctldown ? gridh : 1;
+ movex = ctldown ? grid.x : 1;
+ movey = ctldown ? grid.y : 1;
break;
case Kup:
case Kdown:
@@ -1037,32 +1038,32 @@
selpaste();
break;
case '[':
- gridw = MAX(4, gridw-1);
+ grid.x = MAX(4, grid.x-1);
complete = true;
break;
case ']':
- gridw = MIN(16, gridw+1);
+ grid.x = MIN(16, grid.x+1);
complete = true;
break;
case '{':
- gridh = MAX(4, gridh-1);
+ grid.y = MAX(4, grid.y-1);
complete = true;
break;
case '}':
- gridh = MIN(16, gridh+1);
+ grid.y = MIN(16, grid.y+1);
complete = true;
break;
case '(':
- w = snaplow(w, gridw);
+ w = snaplow(w, grid.x);
break;
case ')':
- w = snaphigh(w, gridw);
+ w = snaphigh(w, grid.x);
break;
case '_':
- h = snaplow(h, gridh);
+ h = snaplow(h, grid.y);
break;
case '+':
- h = snaphigh(h, gridh);
+ h = snaphigh(h, grid.y);
break;
case '>':
apm = ++bpm;
@@ -1110,7 +1111,7 @@
default:
if (key.rune == Kdel || key.rune == ' ')
key.rune = '.';
- if (orca_is_valid_glyph(key.rune) || key.rune == '$') {
+ if (orca_is_valid_glyph(key.rune)) {
fieldmodeset(key.rune);
} else {
// fprint(2, "unhandled key %04x\n", key.rune);