ref: 98ffa7f810093bbffc0ccb24bb38a6992bacfdb0
parent: 1faf0b55cd978d5b16d655429ca6819c5bbf5b15
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 14 07:48:47 EST 2020
plan9: configure dots/rulers style from the menu
--- a/plan9.c
+++ b/plan9.c
@@ -8,6 +8,8 @@
#include <keyboard.h>
#include <thread.h>
+typedef struct Key Key;
+
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
@@ -33,6 +35,12 @@
Mselect,
Nummodes,
+ Menu3load = 0,
+ Menu3save,
+ Menu3dotstyle,
+ Menu3rulerstyle,
+ Nummenu3,
+
Dback = 0,
Dfhigh,
Dfmed,
@@ -45,18 +53,35 @@
Numcolors,
};
-typedef struct Key Key;
-
-static struct {
- u8int u[4];
- Usz at;
-}noteoff[16*128]; /* 16 channels, 128 notes each */
-
struct Key {
int down;
Rune rune;
};
+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 int charw, charh;
+static Field field;
+static Mbuf_reusable mbuf;
+static Oevent_list events;
+static char filename[256];
+static Channel *cchan;
+static Field copyfield;
+static int altdown;
+static int mode = Minsert;
+static long framedev; /* frame deviation >= 1µs */
+
+static char *style[Numstyles] = {
+ [Sfancy] = "fancy",
+ [Splain] = "plain",
+ [Snone] = "none",
+};
+
static Rune dot[Numstyles] = {
[Sfancy] = L'·',
[Splain] = '.',
@@ -81,23 +106,10 @@
},
};
-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 int charw, charh;
-static Field field;
-static Mbuf_reusable mbuf;
-static Oevent_list events;
-static char filename[256];
-static Channel *cchan;
-static Field copyfield;
-static int altdown;
-static int mode = Minsert;
-static long framedev; /* frame deviation >= 1µs */
+static struct {
+ u8int u[4];
+ Usz at;
+}noteoff[16*128]; /* 16 channels, 128 notes each */
static u32int theme[Numcolors] = {
[Dback] = 0x000000ff,
@@ -120,10 +132,9 @@
[Mselect] = "select",
};
-static char *menu3i[] = {
- "load",
- "save",
- nil,
+static char *menu3i[Nummenu3+1] = {
+ [Menu3load] = "load",
+ [Menu3save] = "save",
};
static Menu menu3 = {
@@ -309,9 +320,9 @@
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];
+ rx = !!x + (x + 1) / field.width;
+ ry = !!y + (y + 1) / field.height;
+ c = ruler[rulerstyle][ry*3+rx];
}
}
linebuf[x] = c;
@@ -680,18 +691,25 @@
case 2:
break;
case 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]);
n = menuhit(3, mctl, &menu3, nil);
- if (n == 0 || n == 1) {
+ if (n == Menu3load || n == Menu3save) {
strncpy(tmp, filename, sizeof(tmp));
if (enter("file path:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0) {
- if (n == 0 && fieldload(tmp) == 0) {
+ if (n == Menu3load && fieldload(tmp) == 0) {
w = field.width;
h = field.height;
strncpy(filename, tmp, sizeof(filename));
- } else if (n == 1 && fieldsave(tmp) == 0) {
+ } else if (n == Menu3save && fieldsave(tmp) == 0) {
strncpy(filename, tmp, sizeof(filename));
}
}
+ } else if (n == Menu3dotstyle) {
+ dotstyle = ++dotstyle % Numstyles;
+ } else if (n == Menu3rulerstyle) {
+ rulerstyle = ++rulerstyle % Numstyles;
}
break;
}