aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--life.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/life.c b/life.c
index b76954f..058fffc 100644
--- a/life.c
+++ b/life.c
@@ -1,31 +1,29 @@
1/* 1/*
2 2
3 * An arbitrary cellular automata model using ncurses 3 * An arbitrary cellular automata model using ncurses
4 * Copyright (C) 2018 Aiden Woodruff 4 * Copyright (C) 2018 Aiden Woodruff
5 5
6 * This program is free software: you can redistribute it and/or modify 6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or 8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 10
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 15
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 */ 19 */
20#include "life.h" 20#include "life.h"
21 21
22#ifndef stat_bar_print 22#ifndef stat_bar_print
23// Print text to status bar in the nice way, without erasing or refreshing 23// Print text to status bar in the nice way, without erasing or refreshing
24#define stat_bar_print(win,fmt,...) \ 24#define stat_bar_print(win,fmt,...) \
25 wstandout(win); \
26 wprintw(win, fmt, ##__VA_ARGS__); \ 25 wprintw(win, fmt, ##__VA_ARGS__); \
27 for (int _i = getcurx(win); _i < COLS; _i++) waddch(win, ' '); \ 26 for (int _i = getcurx(win); _i < COLS; _i++) waddch(win, ' ');
28 wstandend(stat_bar);
29#endif 27#endif
30 28
31#ifndef foreach 29#ifndef foreach
@@ -125,6 +123,7 @@ int main (int argc, char * argv[]) {
125 WINDOW * board = newwin(height, width + 1, 0, 0); 123 WINDOW * board = newwin(height, width + 1, 0, 0);
126 WINDOW * stat_bar = newwin(1, 0, LINES - 2, 0); 124 WINDOW * stat_bar = newwin(1, 0, LINES - 2, 0);
127 WINDOW * entry = newwin(1, 0, LINES - 1, 0); 125 WINDOW * entry = newwin(1, 0, LINES - 1, 0);
126 wstandout(stat_bar);
128 char * map = NULL; 127 char * map = NULL;
129 map = malloc((height * width)+1); 128 map = malloc((height * width)+1);
130 memset(map, 0, height * width + 1); 129 memset(map, 0, height * width + 1);
@@ -198,6 +197,7 @@ int main (int argc, char * argv[]) {
198 printw(". - Increase delay time\n"); 197 printw(". - Increase delay time\n");
199 printw("R - Input a rule-int\n"); 198 printw("R - Input a rule-int\n");
200 // TODO printw("Ctrl+R - Open the fancy rule menu\n"); 199 // TODO printw("Ctrl+R - Open the fancy rule menu\n");
200 printw("Ctrl+L - Redraw screen\n");
201 printw("W - Show warranty\n"); 201 printw("W - Show warranty\n");
202 printw("V - Print version\n"); 202 printw("V - Print version\n");
203 foreach(wnoutrefresh, 3, stdscr, entry, stat_bar); 203 foreach(wnoutrefresh, 3, stdscr, entry, stat_bar);
@@ -226,6 +226,8 @@ int main (int argc, char * argv[]) {
226 delaymax -= (delaymax > 1 ? 1 : 0); 226 delaymax -= (delaymax > 1 ? 1 : 0);
227 } else if (ch == '.') { 227 } else if (ch == '.') {
228 delaymax += (delaymax < 20 ? 1 : 0); 228 delaymax += (delaymax < 20 ? 1 : 0);
229 } else if (strcmp(keyname(ch), "^L") == 0) {
230 foreach(wclear, 4, stdscr, entry, stat_bar, board);
229 } 231 }
230 for (int i = 0; i < height; ++i) { 232 for (int i = 0; i < height; ++i) {
231 if (i == y) { 233 if (i == y) {
@@ -238,7 +240,7 @@ int main (int argc, char * argv[]) {
238 wprintw(board, "%.*s\n", width, (map + (i * width))); 240 wprintw(board, "%.*s\n", width, (map + (i * width)));
239 } 241 }
240 } 242 }
241 stat_bar_print(stat_bar, "(%d, %d)\t\tGeneration: %d\t\tDelay Time: %d\n", x, y, generation, delaymax); 243 stat_bar_print(stat_bar, "(%d, %d)\t\tGeneration: %d\t\tDelay Time: %d", x, y, generation, delaymax);
242 foreach(wnoutrefresh, 4, stdscr, board, entry, stat_bar); 244 foreach(wnoutrefresh, 4, stdscr, board, entry, stat_bar);
243 doupdate(); 245 doupdate();
244 if (playing == TRUE) { 246 if (playing == TRUE) {