From: Timo Korvola Date: Thu, 25 Jan 2018 22:08:29 +0000 (+0200) Subject: New function unix_get_terminal_size. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=d05fb0d8298f2757b77f5567ada437d304ebd1b8;p=liskon_frotz.git New function unix_get_terminal_size. Now startup and resize use the same code for getting the terminal size (including override support). --- diff --git a/src/curses/ux_audio.c b/src/curses/ux_audio.c index 6765ae9..d814332 100644 --- a/src/curses/ux_audio.c +++ b/src/curses/ux_audio.c @@ -49,9 +49,6 @@ #include #include -#define MAX(x,y) ((x)>(y)) ? (x) : (y) -#define MIN(x,y) ((x)<(y)) ? (x) : (y) - enum sound_type { FORM, OGGV, diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index 67240c3..a4a90e3 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -65,6 +65,8 @@ #define PATH1 "ZCODE_PATH" #define PATH2 "INFOCOM_PATH" +#define MAX(x,y) ((x)>(y)) ? (x) : (y) +#define MIN(x,y) ((x)<(y)) ? (x) : (y) /* Some regular curses (not ncurses) libraries don't do this correctly. */ #ifndef getmaxyx @@ -86,11 +88,11 @@ extern volatile sig_atomic_t terminal_resized; /*** Functions specific to the Unix port of Frotz ***/ bool unix_init_pictures(void); /* ux_pic.c */ -bool unix_init_pictures(void); /* ux_pic.c */ -void unix_init_scrollback(void); /* ux_screen.c */ -void unix_save_screen(int); /* ux_screen.c */ -void unix_do_scrollback(void); /* ux_screen.c */ +/* void unix_init_scrollback(void); /* ux_screen.c */ +/* void unix_save_screen(int); /* ux_screen.c */ +/* void unix_do_scrollback(void); /* ux_screen.c */ void unix_resize_display(void); /* ux_screen.c */ +void unix_get_terminal_size(void); /* ux_init.c */ #ifdef NO_STRRCHR diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 2313575..f930769 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -376,6 +376,33 @@ void os_process_arguments (int argc, char *argv[]) }/* os_process_arguments */ +void unix_get_terminal_size() +{ + int y, x; + getmaxyx(stdscr, y, x); + + if (u_setup.screen_height != -1) + h_screen_rows = u_setup.screen_height; + else + /* 255 disables paging entirely. */ + h_screen_rows = MIN(254, y); + + if (u_setup.screen_width != -1) + h_screen_cols = u_setup.screen_width; + else + h_screen_cols = MIN(255, x); + + if (h_screen_cols < 1) + os_fatal("Invalid screen width. Must be between 1 and 255."); + + h_font_width = 1; + h_font_height = 1; + + h_screen_width = h_screen_cols; + h_screen_height = h_screen_rows; +} + + /* * os_init_screen * @@ -453,21 +480,7 @@ void os_init_screen (void) if (f_setup.undo_slots == 0) h_flags &= ~UNDO_FLAG; - getmaxyx(stdscr, h_screen_rows, h_screen_cols); - - if (u_setup.screen_height != -1) - h_screen_rows = u_setup.screen_height; - if (u_setup.screen_width != -1) - h_screen_cols = u_setup.screen_width; - - h_screen_width = h_screen_cols; - h_screen_height = h_screen_rows; - - if (h_screen_width > 255 || h_screen_width < 1) - os_fatal("Invalid screen width. Must be between 1 and 255."); - - h_font_width = 1; - h_font_height = 1; + unix_get_terminal_size(); /* Must be after screen dimensions are computed. */ if (h_version == V6) { diff --git a/src/curses/ux_screen.c b/src/curses/ux_screen.c index 7a8be2f..2a18eff 100644 --- a/src/curses/ux_screen.c +++ b/src/curses/ux_screen.c @@ -144,32 +144,16 @@ void os_scroll_area (int top, int left, int bottom, int right, int units) */ void unix_resize_display(void) { -// int x, y; - endwin(); refresh(); + unix_get_terminal_size(); /* Notify the game that the display needs refreshing */ if (h_version == V6) h_flags |= REFRESH_FLAG; - /* Get new terminal dimensions */ -// getmaxyx(stdscr, y, x); - - /* Update the game's header */ - h_screen_width = (zword) COLS; - h_screen_height = (zword) LINES; - h_screen_cols = (zbyte) (h_screen_width / h_font_width); - h_screen_rows = (zbyte)(h_screen_height / h_font_height); - if (zmp != NULL) { resize_screen(); restart_header(); } - -// clearok(stdscr, 1); -// redrawwin(stdscr); -// refresh(); -// clearok(stdscr, 0); - }/* unix_redraw_display */