void curses_destroy_win(WINDOW *win) { werase(win); wrefresh(win); delwin(win); curses_refresh_nethack_windows(); }
int curses_read_char() { int ch, tmpch; ch = getch(); tmpch = ch; ch = curses_convert_keys(ch); if (ch == 0) { ch = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ } #if defined(ALT_0) && defined(ALT_9) /* PDCurses, maybe others */ if ((ch >= ALT_0) && (ch <= ALT_9)) { tmpch = (ch - ALT_0) + '0'; ch = M(tmpch); } #endif #if defined(ALT_A) && defined(ALT_Z) /* PDCurses, maybe others */ if ((ch >= ALT_A) && (ch <= ALT_Z)) { tmpch = (ch - ALT_A) + 'a'; ch = M(tmpch); } #endif #ifdef KEY_RESIZE /* Handle resize events via get_nh_event, not this code */ if (ch == KEY_RESIZE) { ch = '\033'; /* NetHack doesn't know what to do with KEY_RESIZE */ } #endif if (counting && !isdigit(ch)) /* Dismiss count window if necissary */ { curses_count_window(NULL); curses_refresh_nethack_windows(); } return ch; }
void curses_create_main_windows() { int message_x = 0; int message_y = 0; int status_x = 0; int status_y = 0; int map_x = 0; int map_y = 0; int message_height = 0; int message_width = 0; int status_height = 0; int status_width = 0; int map_height = 0; int map_width = 0; int min_message_height = 1; int message_orientation = 0; int status_orientation = 0; int border_space = 0; int hspace = term_cols - 80; boolean borders = FALSE; switch (iflags.wc2_windowborders) { case 1: /* On */ { borders = TRUE; break; } case 2: /* Off */ { borders = FALSE; break; } case 3: /* Auto */ { if ((term_cols > 81) && (term_rows > 25)) { borders = TRUE; } break; } default: { borders = FALSE; } } if (borders) { border_space = 2; hspace -= border_space; } if ((term_cols - border_space) < COLNO) { min_message_height++; } /* Determine status window orientation */ if (!iflags.wc_align_status || (iflags.wc_align_status == ALIGN_TOP) || (iflags.wc_align_status == ALIGN_BOTTOM)) { if (!iflags.wc_align_status) { iflags.wc_align_status = ALIGN_BOTTOM; } status_orientation = iflags.wc_align_status; } else /* left or right alignment */ { /* Max space for player name and title horizontally */ if ((hspace >= 26) && (term_rows >= 24)) { status_orientation = iflags.wc_align_status; hspace -= (26 + border_space); } else { status_orientation = ALIGN_BOTTOM; } } /* Determine message window orientation */ if (!iflags.wc_align_message || (iflags.wc_align_message == ALIGN_TOP) || (iflags.wc_align_message == ALIGN_BOTTOM)) { if (!iflags.wc_align_message) { iflags.wc_align_message = ALIGN_TOP; } message_orientation = iflags.wc_align_message; } else /* left or right alignment */ { if ((hspace - border_space) >= 25) /* Arbitrary */ { message_orientation = iflags.wc_align_message; } else { message_orientation = ALIGN_TOP; } } /* Determine window placement and size - 16 possible combos If anyone wants to try to generalize this, be my guest! */ if ((status_orientation == ALIGN_TOP) && (message_orientation == ALIGN_TOP)) { status_x = 0; status_y = 0; status_width = (term_cols - border_space); status_height = 2; message_x = 0; message_y = status_y + (status_height + border_space); message_width = (term_cols - border_space); message_height = term_rows - (status_height + ROWNO + (border_space * 3)); if (message_height < min_message_height) { message_height = min_message_height; } map_x = 0; map_y = message_y + (message_height + border_space); map_width = (term_cols - border_space); map_height = term_rows - (status_height + message_height + (border_space * 3)); } else if ((status_orientation == ALIGN_TOP) && (message_orientation == ALIGN_RIGHT)) { status_x = 0; status_y = 0; status_height = 2; message_height = (term_rows - border_space); message_width = term_cols - (COLNO + (border_space * 2)); status_width = term_cols - (message_width + (border_space * 2)); message_x = status_x + (status_width + border_space); message_y = 0; map_x = 0; map_y = status_y + (status_height + border_space); map_width = status_width; map_height = term_rows - (status_height + (border_space * 2)); } else if ((status_orientation == ALIGN_TOP) && (message_orientation == ALIGN_BOTTOM)) { status_x = 0; status_y = 0; status_width = (term_cols - border_space); status_height = 2; map_x = 0; map_y = status_y + (status_height + border_space); map_width = (term_cols - border_space); message_height = term_rows - (status_height + ROWNO + (border_space * 3)); if (message_height < min_message_height) { message_height = min_message_height; } map_height = term_rows - (status_height + message_height + (border_space * 3)); message_x = 0; message_y = map_y + (map_height + border_space); message_width = (term_cols - border_space); } else if ((status_orientation == ALIGN_TOP) && (message_orientation == ALIGN_LEFT)) { message_x = 0; message_y = 0; message_height = (term_rows - border_space); message_width = term_cols - (COLNO + (border_space * 2)); status_x = message_x + (message_width + border_space); status_y = 0; status_height = 2; status_width = term_cols - (message_width + (border_space * 2)); map_x = status_x; map_y = status_y + (status_height + border_space); map_height = term_rows - (status_height + (border_space * 2)); map_width = status_width; } if ((status_orientation == ALIGN_RIGHT) && (message_orientation == ALIGN_TOP)) { status_width = 26; status_height = (term_rows - border_space); status_x = term_cols - (status_width + border_space); status_y = 0; message_x = 0; message_y = 0; message_width = term_cols - (status_width + (border_space * 2)); message_height = term_rows - (ROWNO + (border_space * 2)); if (message_height < min_message_height) { message_height = min_message_height; } map_x = 0; map_y = message_y + (message_height + border_space); map_width = term_cols - (status_width + (border_space * 2)); map_height = term_rows - (message_height + (border_space * 2)); } else if ((status_orientation == ALIGN_RIGHT) && (message_orientation == ALIGN_RIGHT)) { map_x = 0; map_y = 0; map_height = (term_rows - border_space); status_width = 26; message_width = term_cols - (COLNO + status_width + (border_space * 3)); map_width = term_cols - (status_width + message_width + (border_space * 3)); message_x = map_x + (map_width + border_space); message_y = 0; message_height = (term_rows - border_space); status_x = message_x + (message_width + border_space); status_y = 0; status_height = (term_rows - border_space); } else if ((status_orientation == ALIGN_RIGHT) && (message_orientation == ALIGN_BOTTOM)) { map_x = 0; map_y = 0; status_width = 26; map_width = term_cols - (status_width + (border_space * 2)); message_height = term_rows - (ROWNO + (border_space * 2)); if (message_height < min_message_height) { message_height = min_message_height; } map_height = term_rows - (message_height + (border_space * 2)); message_x = 0; message_y = map_y + (map_height + border_space); message_width = map_width; status_x = map_x + (map_width + border_space); status_y = 0; status_height = (term_rows - border_space); } else if ((status_orientation == ALIGN_RIGHT) && (message_orientation == ALIGN_LEFT)) { status_x = 0; status_y = 0; status_height = (term_rows - border_space); status_width = 26; message_width = term_cols - (status_width + COLNO + (border_space * 3)); map_x = status_x + (status_width + border_space); map_y = 0; map_height = (term_rows - border_space); map_width = term_cols - (status_width + message_width + (border_space * 3)); message_x = map_x + (map_width + border_space); message_y = 0; message_height = (term_rows - border_space); } if ((status_orientation == ALIGN_BOTTOM) && (message_orientation == ALIGN_TOP)) { message_x = 0; message_y = 0; message_width = (term_cols - border_space); status_height = 2; message_height = term_rows - (status_height + ROWNO + (border_space * 3)); if (message_height < min_message_height) { message_height = min_message_height; } map_x = 0; map_y = message_y + (message_height + border_space); map_width = (term_cols - border_space); map_height = term_rows - (status_height + message_height + (border_space * 3)); status_x = 0; status_y = map_y + (map_height + border_space); status_width = (term_cols - border_space); } else if ((status_orientation == ALIGN_BOTTOM) && (message_orientation == ALIGN_RIGHT)) { map_x = 0; map_y = 0; status_height = 2; map_height = term_rows - (status_height + (border_space * 2)); message_width = term_cols - (COLNO + (border_space * 2)); map_width = term_cols - (message_width + (border_space * 2)); status_x = 0; status_y = map_y + (map_height + border_space); status_width = map_width + message_width + border_space; message_x = map_x + (map_width + border_space); message_y = 0; message_height = map_height; } else if ((status_orientation == ALIGN_BOTTOM) && (message_orientation == ALIGN_BOTTOM)) { map_x = 0; map_y = 0; message_x = 0; status_x = 0; message_width = (term_cols - border_space); status_height = 2; message_height = term_rows - (status_height + ROWNO + (border_space * 3)); if (message_height < min_message_height) { message_height = min_message_height; } map_width = (term_cols - border_space); map_height = term_rows - (status_height + message_height + (border_space * 3)); message_y = map_y + (map_height + border_space); status_y = message_y + (message_height + border_space); status_width = (term_cols - border_space); } else if ((status_orientation == ALIGN_BOTTOM) && (message_orientation == ALIGN_LEFT)) { message_x = 0; message_y = 0; message_height = (term_rows - border_space); message_width = term_cols - (COLNO + (border_space * 2)); status_height = 2; map_x = message_x + (message_width + border_space); map_y = 0; map_height = term_rows - (status_height + (border_space * 2)); map_width = term_cols - (message_width + (border_space * 2)); status_x = map_x; status_y = map_y + (map_height + border_space); status_width = term_cols - (message_width + (border_space * 2)); } if ((status_orientation == ALIGN_LEFT) && (message_orientation == ALIGN_TOP)) { status_x = 0; status_y = 0; status_height = (term_rows - border_space); status_width = 26; message_x = status_x + (status_width + border_space); message_y = 0; message_height = term_rows - (ROWNO + (border_space * 2)); if (message_height < min_message_height) { message_height = min_message_height; } message_width = term_cols - (status_width + (border_space * 2)); map_x = message_x; map_y = message_y + (message_height + border_space); map_height = term_rows - (message_height + (border_space * 2)); map_width = term_cols - (status_width + (border_space * 2)); } else if ((status_orientation == ALIGN_LEFT) && (message_orientation == ALIGN_RIGHT)) { message_x = 0; message_y = 0; message_height = (term_rows - border_space); status_width = 26; message_width = term_cols - (status_width + COLNO + (border_space * 3)); map_x = message_x + (message_width + border_space); map_y = 0; map_height = (term_rows - border_space); map_width = term_cols - (status_width + message_width + (border_space * 3)); status_x = map_x + (map_width + border_space); status_y = 0; status_height = (term_rows - border_space); } else if ((status_orientation == ALIGN_LEFT) && (message_orientation == ALIGN_BOTTOM)) { status_x = 0; status_y = 0; status_height = (term_rows - border_space); status_width = 26; map_x = status_x + (status_width + border_space); map_y = 0; message_height = term_rows - (ROWNO + (border_space * 2)); if (message_height < min_message_height) { message_height = min_message_height; } map_height = term_rows - (message_height + (border_space * 2)); map_width = term_cols - (status_width + (border_space * 2)); message_x = status_x + (status_width + border_space); message_y = map_y + (map_height + border_space); message_width = map_width; } else if ((status_orientation == ALIGN_LEFT) && (message_orientation == ALIGN_LEFT)) { status_x = 0; status_y = 0; status_height = (term_rows - border_space); status_width = 26; message_x = status_x + (status_width + border_space); message_y = 0; message_height = status_height; message_width = term_cols - (COLNO + status_width + (border_space * 3)); map_x = message_x + (message_width + border_space); map_y = 0; map_height = message_height; map_width = term_cols - (status_width + message_width + (border_space * 3)); } if (map_width > COLNO) { map_width = COLNO; } if (map_height > ROWNO) { map_height = ROWNO; } if (curses_window_exists(STATUS_WIN)) { curses_del_nhwin(STATUS_WIN); curses_del_nhwin(MESSAGE_WIN); curses_del_nhwin(MAP_WIN); clear(); } curses_add_nhwin(STATUS_WIN, status_height, status_width, status_y, status_x, status_orientation, borders); curses_add_nhwin(MESSAGE_WIN, message_height, message_width, message_y, message_x, message_orientation, borders); curses_add_nhwin(MAP_WIN, map_height, map_width, map_y, map_x, 0, borders); refresh(); curses_refresh_nethack_windows(); if (iflags.window_inited) { curses_update_stats(TRUE); } else { iflags.window_inited = TRUE; } }
/* Restore the windows after being suspended. */ void curses_resume_nhwindows() { curses_refresh_nethack_windows(); }