History

plan9: configure dots/rulers style from the menu

Sigrid Haflínudóttir committed 6 years ago

Commit 98ffa7f1 parent 1faf0b51 file · +52 −34Browse files

Unified · Split

plan9.c+52−34
@@ -8,6 +8,8 @@ · 7 unmodified lines
88 #include <keyboard.h>
99 #include <thread.h>
1010
11+typedef struct Key Key;
12+
1113 #define MIN(x,y) ((x)<(y)?(x):(y))
1214 #define MAX(x,y) ((x)>(y)?(x):(y))
1315
@@ -33,6 +35,12 @@ enum { · 19 unmodified lines
3335 Mselect,
3436 Nummodes,
3537
38+ Menu3load = 0,
39+ Menu3save,
40+ Menu3dotstyle,
41+ Menu3rulerstyle,
42+ Nummenu3,
43+
3644 Dback = 0,
3745 Dfhigh,
3846 Dfmed,
@@ -45,18 +53,35 @@ enum { · 6 unmodified lines
4553 Numcolors,
4654 };
4755
48−typedef struct Key Key;
49−
50−static struct {
51− u8int u[4];
52− Usz at;
53−}noteoff[16*128]; /* 16 channels, 128 notes each */
54−
5556 struct Key {
5657 int down;
5758 Rune rune;
5859 };
5960
61+static Rune *linebuf;
62+static Usz tick;
63+static int gridw = 8, gridh = 8;
64+static int rulerstyle = Sfancy, dotstyle = Sfancy;
65+static int bpm = 120, pause;
66+static int curx, cury;
67+static int selw = 1, selh = 1;
68+static int charw, charh;
69+static Field field;
70+static Mbuf_reusable mbuf;
71+static Oevent_list events;
72+static char filename[256];
73+static Channel *cchan;
74+static Field copyfield;
75+static int altdown;
76+static int mode = Minsert;
77+static long framedev; /* frame deviation >= 1µs */
78+
79+static char *style[Numstyles] = {
80+ [Sfancy] = "fancy",
81+ [Splain] = "plain",
82+ [Snone] = "none",
83+};
84+
6085 static Rune dot[Numstyles] = {
6186 [Sfancy] = L'·',
6287 [Splain] = '.',
@@ -81,23 +106,10 @@ static Rune ruler[Numstyles][9] = { · 18 unmodified lines
81106 },
82107 };
83108
84−static Rune *linebuf;
85−static Usz tick;
86−static int gridw = 8, gridh = 8;
87−static int rulerstyle = Sfancy, dotstyle = Sfancy;
88−static int bpm = 120, pause;
89−static int curx, cury;
90−static int selw = 1, selh = 1;
91−static int charw, charh;
92−static Field field;
93−static Mbuf_reusable mbuf;
94−static Oevent_list events;
95−static char filename[256];
96−static Channel *cchan;
97−static Field copyfield;
98−static int altdown;
99−static int mode = Minsert;
100−static long framedev; /* frame deviation >= 1µs */
109+static struct {
110+ u8int u[4];
111+ Usz at;
112+}noteoff[16*128]; /* 16 channels, 128 notes each */
101113
102114 static u32int theme[Numcolors] = {
103115 [Dback] = 0x000000ff,
@@ -120,10 +132,9 @@ static char *modes[Nummodes] = { · 16 unmodified lines
120132 [Mselect] = "select",
121133 };
122134
123−static char *menu3i[] = {
124− "load",
125− "save",
126− nil,
135+static char *menu3i[Nummenu3+1] = {
136+ [Menu3load] = "load",
137+ [Menu3save] = "save",
127138 };
128139
129140 static Menu menu3 = {
@@ -309,9 +320,9 @@ redraw(void) · 179 unmodified lines
309320 if (c == '.') {
310321 c = dot[dotstyle];
311322 if ((x % gridw) == 0 && (y % gridh) == 0) {
312− rx = x == 0 ? 0 : (x == field.width-1 ? 2 : 1);
313− ry = y == 0 ? 0 : (y == field.height-1 ? 2 : 1);
314− c = ruler[dotstyle][ry*3+rx];
323+ rx = !!x + (x + 1) / field.width;
324+ ry = !!y + (y + 1) / field.height;
325+ c = ruler[rulerstyle][ry*3+rx];
315326 }
316327 }
317328 linebuf[x] = c;
@@ -680,18 +691,25 @@ threadmain(int argc, char **argv) · 362 unmodified lines
680691 case 2:
681692 break;
682693 case 4:
694+ menu3i[Menu3dotstyle] = tmp;
695+ menu3i[Menu3rulerstyle] = 1 + menu3i[Menu3dotstyle] + sprintf(tmp, "%s dots", style[(dotstyle+1) % Numstyles]);
696+ sprintf(menu3i[Menu3rulerstyle], "%s rulers", style[(rulerstyle+1) % Numstyles]);
683697 n = menuhit(3, mctl, &menu3, nil);
684− if (n == 0 || n == 1) {
698+ if (n == Menu3load || n == Menu3save) {
685699 strncpy(tmp, filename, sizeof(tmp));
686700 if (enter("file path:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0) {
687− if (n == 0 && fieldload(tmp) == 0) {
701+ if (n == Menu3load && fieldload(tmp) == 0) {
688702 w = field.width;
689703 h = field.height;
690704 strncpy(filename, tmp, sizeof(filename));
691− } else if (n == 1 && fieldsave(tmp) == 0) {
705+ } else if (n == Menu3save && fieldsave(tmp) == 0) {
692706 strncpy(filename, tmp, sizeof(filename));
693707 }
694708 }
709+ } else if (n == Menu3dotstyle) {
710+ dotstyle = ++dotstyle % Numstyles;
711+ } else if (n == Menu3rulerstyle) {
712+ rulerstyle = ++rulerstyle % Numstyles;
695713 }
696714 break;
697715 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t