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
8#include <keyboard.h>8#include <keyboard.h>
9#include <thread.h>9#include <thread.h>
10 10
11typedef struct Key Key;
12
11#define MIN(x,y) ((x)<(y)?(x):(y))13#define MIN(x,y) ((x)<(y)?(x):(y))
12#define MAX(x,y) ((x)>(y)?(x):(y))14#define MAX(x,y) ((x)>(y)?(x):(y))
13 15
@@ -33,6 +35,12 @@ enum { · 19 unmodified lines
33 Mselect,35 Mselect,
34 Nummodes,36 Nummodes,
35 37
38 Menu3load = 0,
39 Menu3save,
40 Menu3dotstyle,
41 Menu3rulerstyle,
42 Nummenu3,
43
36 Dback = 0,44 Dback = 0,
37 Dfhigh,45 Dfhigh,
38 Dfmed,46 Dfmed,
@@ -45,18 +53,35 @@ enum { · 6 unmodified lines
45 Numcolors,53 Numcolors,
46};54};
47 55
48typedef struct Key Key;
49
50static struct {
51 u8int u[4];
52 Usz at;
53}noteoff[16*128]; /* 16 channels, 128 notes each */
54
55struct Key {56struct Key {
56 int down;57 int down;
57 Rune rune;58 Rune rune;
58};59};
59 60
61static Rune *linebuf;
62static Usz tick;
63static int gridw = 8, gridh = 8;
64static int rulerstyle = Sfancy, dotstyle = Sfancy;
65static int bpm = 120, pause;
66static int curx, cury;
67static int selw = 1, selh = 1;
68static int charw, charh;
69static Field field;
70static Mbuf_reusable mbuf;
71static Oevent_list events;
72static char filename[256];
73static Channel *cchan;
74static Field copyfield;
75static int altdown;
76static int mode = Minsert;
77static long framedev; /* frame deviation >= 1µs */
78
79static char *style[Numstyles] = {
80 [Sfancy] = "fancy",
81 [Splain] = "plain",
82 [Snone] = "none",
83};
84
60static Rune dot[Numstyles] = {85static Rune dot[Numstyles] = {
61 [Sfancy] = L'·',86 [Sfancy] = L'·',
62 [Splain] = '.',87 [Splain] = '.',
@@ -81,23 +106,10 @@ static Rune ruler[Numstyles][9] = { · 18 unmodified lines
81 },106 },
82};107};
83 108
84static Rune *linebuf;109static struct {
85static Usz tick;110 u8int u[4];
86static int gridw = 8, gridh = 8;111 Usz at;
87static int rulerstyle = Sfancy, dotstyle = Sfancy;112}noteoff[16*128]; /* 16 channels, 128 notes each */
88static int bpm = 120, pause;
89static int curx, cury;
90static int selw = 1, selh = 1;
91static int charw, charh;
92static Field field;
93static Mbuf_reusable mbuf;
94static Oevent_list events;
95static char filename[256];
96static Channel *cchan;
97static Field copyfield;
98static int altdown;
99static int mode = Minsert;
100static long framedev; /* frame deviation >= 1µs */
101 113
102static u32int theme[Numcolors] = {114static u32int theme[Numcolors] = {
103 [Dback] = 0x000000ff,115 [Dback] = 0x000000ff,
@@ -120,10 +132,9 @@ static char *modes[Nummodes] = { · 16 unmodified lines
120 [Mselect] = "select",132 [Mselect] = "select",
121};133};
122 134
123static char *menu3i[] = {135static char *menu3i[Nummenu3+1] = {
124 "load",136 [Menu3load] = "load",
125 "save",137 [Menu3save] = "save",
126 nil,
127};138};
128 139
129static Menu menu3 = {140static Menu menu3 = {
@@ -309,9 +320,9 @@ redraw(void) · 179 unmodified lines
309 if (c == '.') {320 if (c == '.') {
310 c = dot[dotstyle];321 c = dot[dotstyle];
311 if ((x % gridw) == 0 && (y % gridh) == 0) {322 if ((x % gridw) == 0 && (y % gridh) == 0) {
312 rx = x == 0 ? 0 : (x == field.width-1 ? 2 : 1);323 rx = !!x + (x + 1) / field.width;
313 ry = y == 0 ? 0 : (y == field.height-1 ? 2 : 1);324 ry = !!y + (y + 1) / field.height;
314 c = ruler[dotstyle][ry*3+rx];325 c = ruler[rulerstyle][ry*3+rx];
315 }326 }
316 }327 }
317 linebuf[x] = c;328 linebuf[x] = c;
@@ -680,18 +691,25 @@ threadmain(int argc, char **argv) · 362 unmodified lines
680 case 2:691 case 2:
681 break;692 break;
682 case 4:693 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]);
683 n = menuhit(3, mctl, &menu3, nil);697 n = menuhit(3, mctl, &menu3, nil);
684 if (n == 0 || n == 1) {698 if (n == Menu3load || n == Menu3save) {
685 strncpy(tmp, filename, sizeof(tmp));699 strncpy(tmp, filename, sizeof(tmp));
686 if (enter("file path:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0) {700 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) {
688 w = field.width;702 w = field.width;
689 h = field.height;703 h = field.height;
690 strncpy(filename, tmp, sizeof(filename));704 strncpy(filename, tmp, sizeof(filename));
691 } else if (n == 1 && fieldsave(tmp) == 0) {705 } else if (n == Menu3save && fieldsave(tmp) == 0) {
692 strncpy(filename, tmp, sizeof(filename));706 strncpy(filename, tmp, sizeof(filename));
693 }707 }
694 }708 }
709 } else if (n == Menu3dotstyle) {
710 dotstyle = ++dotstyle % Numstyles;
711 } else if (n == Menu3rulerstyle) {
712 rulerstyle = ++rulerstyle % Numstyles;
695 }713 }
696 break;714 break;
697 }715 }

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