Fix arrow direction for vertical arrows
[clav.git] / clav.c
blob9c01bfaec754627496f7530a12c84496f4048078
1 #include <locale.h>
2 #include <stdint.h>
3 #include <stdio.h>
5 #include "macros.h"
6 #include "quiver.h"
7 #include "ui.h"
9 /* The general state of the application */
10 static enum {
11 ST_DEFAULT = 0,
12 ST_ASKING_QUIT,
13 ST_SHOULD_QUIT
14 } state;
16 /* Having received some kind of input, change state accordingly */
17 static int state_transition(struct ui_event *e)
19 int ret = 0;
21 switch (state) {
22 case ST_SHOULD_QUIT:
23 break;
24 case ST_DEFAULT:
26 switch (e->type) {
27 case ET_INITIAL_QUIT:
28 ret = ui_confirm_deny("Quit?");
29 state = ST_ASKING_QUIT;
30 break;
31 case ET_FORCE_QUIT:
32 state = ST_SHOULD_QUIT;
33 break;
34 case ET_NONE:
35 case ET_CONFIRM:
36 case ET_DENY:
37 break;
40 break;
41 case ST_ASKING_QUIT:
43 switch (e->type) {
44 case ET_CONFIRM:
45 case ET_FORCE_QUIT:
46 state = ST_SHOULD_QUIT;
47 break;
48 case ET_DENY:
49 state = ST_DEFAULT;
50 break;
51 case ET_NONE:
52 case ET_INITIAL_QUIT:
53 break;
56 break;
59 if (ret) {
60 state = ST_SHOULD_QUIT;
63 return ret;
66 /* Main loop */
67 int main(int argc, char **argv)
69 int ret;
70 uint_fast8_t more_evs = 0;
71 struct ui_event e = { 0 };
72 struct quiver q = { 0 };
73 size_t v0, vinf, v1, v2, v1b, v2b, v12, v21, v23, v32, v30, v03, v10,
74 v01;
76 UNUSED(argc);
77 UNUSED(argv);
78 setlocale(LC_ALL, "");
80 if ((ret = ui_init(&q))) {
81 goto done;
85 /* XXX: rem (this is C2 U_{02} C2) */
86 quiver_add_vertex(&q, &v0, "0", 1, 0, -170, 0);
87 quiver_add_vertex(&q, &vinf, "\u221e", 2, 0, 170, 0);
88 quiver_add_vertex(&q, &v1, "1", 2, 100, 100, 0);
89 quiver_add_vertex(&q, &v2, "2", 1, 170, -70, 0);
90 quiver_add_vertex(&q, &v1b, "1'", 2, -140, 100, 0);
91 quiver_add_vertex(&q, &v2b, "2'", 1, -110, -70, 0);
92 quiver_add_vertex(&q, &v12, "12", 2, -350, -150, 0);
93 quiver_add_vertex(&q, &v21, "21", 1, -150, -350, 0);
94 quiver_add_vertex(&q, &v32, "32", 1, 350, -150, 0);
95 quiver_add_vertex(&q, &v23, "23", 2, 150, -350, 0);
96 quiver_add_vertex(&q, &v30, "30", 2, 350, 150, 0);
97 quiver_add_vertex(&q, &v03, "03", 1, 150, 350, 0);
98 quiver_add_vertex(&q, &v10, "10", 1, -350, 150, 0);
99 quiver_add_vertex(&q, &v01, "01", 2, -150, 350, 0);
100 /* edges */
101 quiver_add_to_edge(&q, v12, v21, 1, 2, 0);
102 quiver_add_to_edge(&q, v23, v32, 1, 2, 0);
103 quiver_add_to_edge(&q, v10, v01, 1, 2, 0);
104 quiver_add_to_edge(&q, v30, v03, 1, 2, 0);
105 quiver_add_to_edge(&q, v21, v2b, 1, 1, 0);
106 quiver_add_to_edge(&q, v23, v1, 1, 1, 0);
107 quiver_add_to_edge(&q, v12, v1b, 1, 1, 0);
108 quiver_add_to_edge(&q, v2b, v12, 1, 1, 0);
109 quiver_add_to_edge(&q, v2b, v0, 1, 1, 0);
110 quiver_add_to_edge(&q, v2b, v10, 1, 1, 0);
111 quiver_add_to_edge(&q, v0, v32, 1, 1, 0);
112 quiver_add_to_edge(&q, v0, v1b, 1, 1, 0);
113 quiver_add_to_edge(&q, v32, v2, 1, 1, 0);
114 quiver_add_to_edge(&q, v1b, vinf, 1, 1, 0);
115 quiver_add_to_edge(&q, v1, v30, 1, 1, 0);
116 quiver_add_to_edge(&q, v1, v2, 1, 1, 0);
117 quiver_add_to_edge(&q, v2, v0, 1, 1, 0);
118 quiver_add_to_edge(&q, v2, v23, 1, 1, 0);
119 quiver_add_to_edge(&q, v2, v03, 1, 1, 0);
120 quiver_add_to_edge(&q, v10, v21, 1, 1, 0);
121 quiver_add_to_edge(&q, vinf, v1, 1, 1, 0);
122 quiver_add_to_edge(&q, vinf, v01, 1, 1, 0);
123 quiver_add_to_edge(&q, v30, vinf, 1, 1, 0);
124 quiver_add_to_edge(&q, v01, v1b, 1, 1, 0);
125 quiver_add_to_edge(&q, v03, v1, 1, 1, 0);
128 if ((ret = ui_respond_quiver_change())) {
129 goto done;
133 if ((ret = ui_start_frame())) {
134 goto done;
137 while (state != ST_SHOULD_QUIT) {
138 /* includes framelimiting delay */
139 if ((ret = ui_finish_frame())) {
140 goto done;
143 more_evs = 1;
145 while (more_evs) {
146 if ((ret = ui_get_event(&e, &more_evs))) {
147 goto done;
150 if (e.type) {
151 state_transition(&e);
155 if ((ret = ui_start_frame())) {
156 goto done;
160 done:
161 ui_teardown();
163 return ret;