void draw_text_from_bottom (struct Win * win) {
// Draw text in win->data from end/bottom to the top.
void draw_text_from_bottom (struct Win * win) {
// Draw text in win->data from end/bottom to the top.
- for (y = 0; y < start_y; y++)
- for (x = 0; x < win->width; x++)
- mvwaddch(win->curses_win, y, x, ' '); }
else if (y > win->height) {
offset = y - win->height;
for (y = 0; y < offset; y++)
else if (y > win->height) {
offset = y - win->height;
for (y = 0; y < offset; y++)
mvwaddch(win->curses_win, y, x, '@');
else
mvwaddch(win->curses_win, y, x, cells[z]);
mvwaddch(win->curses_win, y, x, '@');
else
mvwaddch(win->curses_win, y, x, cells[z]);
void draw_info (struct Win * win) {
// Draw info window by appending win->data integer value to "Turn: " display.
void draw_info (struct Win * win) {
// Draw info window by appending win->data integer value to "Turn: " display.
char text[100];
snprintf(text, 100, "Turn: %d", count);
draw_with_linebreaks(win, text, 0); }
char text[100];
snprintf(text, 100, "Turn: %d", count);
draw_with_linebreaks(win, text, 0); }
void update_log (struct Win * win, char * text) {
// Update log with new text to be appended.
void update_log (struct Win * win, char * text) {
// Update log with new text to be appended.
if (keyswindata->select < (keyswindata->max - (win->height / 2)))
offset = keyswindata->select - (win->height / 2);
else
if (keyswindata->select < (keyswindata->max - (win->height / 2)))
offset = keyswindata->select - (win->height / 2);
else
- offset = keyswindata->max - win->height + 1; }
- int keydescwidth = 9; // max length assured by get_keyname()
- char * keydesc = malloc(keydescwidth + 1);
+ offset = keyswindata->max - win->height + 1; } }
+ int keydescwidth = 9 + 1; // max length assured by get_keyname() + \0
+ char * keydesc = malloc(keydescwidth);
attri = 0;
if (y == keyswindata->select - offset) {
attri = A_REVERSE;
if (1 == keyswindata->edit)
attri = attri | A_BLINK; }
keyname = get_keyname(keybindings[y + offset].key);
attri = 0;
if (y == keyswindata->select - offset) {
attri = A_REVERSE;
if (1 == keyswindata->edit)
attri = attri | A_BLINK; }
keyname = get_keyname(keybindings[y + offset].key);
- snprintf(keydesc, keydescwidth + 1, "%-9s", keyname);
+ snprintf(keydesc, keydescwidth, "%-9s", keyname);
mvwaddch(win->curses_win, y, x, keydesc[x] | attri);
else if (strlen(keydesc) < x && x < strlen(keybindings[y + offset].name) + strlen(keydesc) + 1)
mvwaddch(win->curses_win, y, x, keybindings[y + offset].name[x - strlen(keydesc) - 1] | attri);
else
mvwaddch(win->curses_win, y, x, ' ' | attri); }
mvwaddch(win->curses_win, y, x, keydesc[x] | attri);
else if (strlen(keydesc) < x && x < strlen(keybindings[y + offset].name) + strlen(keydesc) + 1)
mvwaddch(win->curses_win, y, x, keybindings[y + offset].name[x - strlen(keydesc) - 1] | attri);
else
mvwaddch(win->curses_win, y, x, ' ' | attri); }
- free(keydesc);
- if (y < win->height)
- for (; y < win->height; y++)
- for (x = 0; x < win->width; x++)
- mvwaddch(win->curses_win, y, x, ' '); }
struct KeyBinding * keybindings = malloc(lines * sizeof(struct KeyBinding));
fseek(file, 0, SEEK_SET);
char * command = malloc(linemax);
struct KeyBinding * keybindings = malloc(lines * sizeof(struct KeyBinding));
fseek(file, 0, SEEK_SET);
char * command = malloc(linemax);
memcpy(keybindings[keycount].name, command, commcount);
keybindings[keycount].key = key;
keycount++;
memcpy(keybindings[keycount].name, command, commcount);
keybindings[keycount].key = key;
keycount++;
struct Win win_info = init_window(&win_meta, "Info");
win_info.draw = draw_info;
struct Win win_info = init_window(&win_meta, "Info");
win_info.draw = draw_info;
struct Win win_log = init_window(&win_meta, "Log");
win_log.draw = draw_text_from_bottom;
struct Win win_log = init_window(&win_meta, "Log");
win_log.draw = draw_text_from_bottom;
else if (key == get_action_key(world.keybindings, "map left") && map.offset_x > 0)
map.offset_x--;
else if (key == get_action_key(world.keybindings, "player down") && map.player_y < map.height - 1) {
else if (key == get_action_key(world.keybindings, "map left") && map.offset_x > 0)
map.offset_x--;
else if (key == get_action_key(world.keybindings, "player down") && map.player_y < map.height - 1) {
update_log (&win_log, "\nYou move south.");
map.player_y++; }
else if (key == get_action_key(world.keybindings, "player up") && map.player_y > 0) {
update_log (&win_log, "\nYou move south.");
map.player_y++; }
else if (key == get_action_key(world.keybindings, "player up") && map.player_y > 0) {
update_log (&win_log, "\nYou move north.");
map.player_y--; }
else if (key == get_action_key(world.keybindings, "player right") && map.player_x < map.width - 1) {
update_log (&win_log, "\nYou move north.");
map.player_y--; }
else if (key == get_action_key(world.keybindings, "player right") && map.player_x < map.width - 1) {
update_log (&win_log, "\nYou move east.");
map.player_x++; }
else if (key == get_action_key(world.keybindings, "player left") && map.player_x > 0) {
update_log (&win_log, "\nYou move east.");
map.player_x++; }
else if (key == get_action_key(world.keybindings, "player left") && map.player_x > 0) {
update_log (&win_log, "\nYou move west.");
map.player_x--; }
else if (key == get_action_key(world.keybindings, "wait") ) {
update_log (&win_log, "\nYou move west.");
map.player_x--; }
else if (key == get_action_key(world.keybindings, "wait") ) {