1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* An arbitrary cellular automata model using ncurses
* Copyright (C) 2018 Aiden Woodruff
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "menus.h"
int print_copying_warranty (WINDOW * win) {
const char * WARRANTY = " THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.\n EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.\n THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.\n SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.";
return waddstr(win, WARRANTY);
}
int print_help (WINDOW * win) {
if (waddstr(win, "Arrow keys - Motion\n") == OK &&
waddstr(win, "Space - Flip cell (if it's alive, to dead, and vice versa)\n") == OK &&
waddstr(win, "Enter - Pause/Play\n") == OK &&
waddstr(win, "\tN.B. - Many keys can only be used while paused.\n") == OK &&
waddstr(win, ", - Lower delay time\n") == OK &&
waddstr(win, ". - Increase delay time\n") == OK &&
waddstr(win, "R - Input a rule-int\n") == OK &&
waddstr(win, "Ctrl+R - Open the fancy rule menu\n") == OK &&
waddstr(win, "Ctrl+L - Redraw screen\n") == OK &&
waddstr(win, "W - Show warranty\n") == OK &&
waddstr(win, "V - Print version\n") == OK) {
return OK;
} else {
return ERR;
}
}
int read_num (WINDOW * win, int min, int max) {
int ret = 0;
werase(win);
int width = getmaxx(win);
char * text = (char*) malloc((size_t)(width + 1));
memset(text, 0, (size_t)(width + 1));
curs_set(1);
echo();
wgetnstr(win, text, (size_t)(width + 1));
ret = (int) strtol((const char *) text, NULL, 10);
if (!(ret >= min && ret <= max)) {
ret = 0;
}
noecho();
curs_set(0);
free(text);
return ret;
}
// Fancy rule menu, returns new rules or -1 on fail
int fancy_rules (WINDOW * win, int ruleint, int speed) {
int done = FALSE;
int cursor = 0;
int ch = 0;
wtimeout(win, speed);
while (done == FALSE && ch != 'q') {
werase(win);
waddstr(win, "Press space to toggle buttons\n");
wprintw(win, "Rule int: %d\n", ruleint);
waddstr(win, "B012345678/S012345678\n");
waddch(win, 'B');
for (int i = 0; i < 9; i++) {
if (cursor == i) {
wstandout(win);
}
waddch(win, has(ruleint, 1 << i) ? '1' : '0');
if (cursor == i) {
wstandend(win);
}
}
waddstr(win, "/S");
for (int i = 9; i < 18; i++) {
if (cursor == i) {
wstandout(win);
}
waddch(win, has(ruleint, 1 << i) ? '1' : '0');
if (cursor == i) {
wstandend(win);
}
}
waddstr(win, "\n");
if (cursor == 18) {
wstandout(win);
waddstr(win, "Cancel");
wstandend(win);
} else {
waddstr(win, "Cancel");
}
waddstr(win, " ");
if (cursor == 19) {
wstandout(win);
waddstr(win, "Default");
wstandend(win);
} else {
waddstr(win, "Default");
}
waddstr(win, " ");
if (cursor == 20) {
wstandout(win);
waddstr(win, "Done");
wstandend(win);
} else {
waddstr(win, "Done");
}
wrefresh(win);
if (ch == KEY_LEFT) {
if (cursor > 0 && cursor < 18) {
cursor--;
} else if (cursor > 18) {
cursor--;
}
} else if (ch == KEY_RIGHT) {
if (cursor < 17) {
cursor++;
} else if (cursor > 17 && cursor < 20) {
cursor++;
}
} else if (ch == KEY_UP || ch == KEY_DOWN) {
if (cursor > 17) {
switch (cursor) {
case 18:
cursor = 0;
break;
case 19:
cursor = 6;
break;
case 20:
cursor = 13;
break;
}
} else {
if (cursor > -1 && cursor < 6) {
cursor = 18;
} else if (cursor > 5 && cursor < 13) {
cursor = 19;
} else if (cursor > 12) {
cursor = 20;
}
}
} else if (ch == ' ' || ch == '\n') {
switch (cursor) {
case 18:
ruleint = -1;
done = TRUE;
break;
case 19:
ruleint = 6152;
break;
case 20:
done = TRUE;
break;
default:
ruleint ^= 1 << cursor;
break;
}
}
if (done == FALSE) {
ch = wgetch(win);
}
}
werase(win);
wrefresh(win);
return ruleint;
}
|