New function unix_get_terminal_size.
authorTimo Korvola <tkorvola@iki.fi>
Thu, 25 Jan 2018 22:08:29 +0000 (00:08 +0200)
committerTimo Korvola <tkorvola@iki.fi>
Thu, 25 Jan 2018 22:08:29 +0000 (00:08 +0200)
Now startup and resize use the same code for getting the terminal
size (including override support).

src/curses/ux_audio.c
src/curses/ux_frotz.h
src/curses/ux_init.c
src/curses/ux_screen.c

index 6765ae92ed3a0eb37e301f3d0c1c45016de7a64a..d8143323d8ddf7836edb7e5e6fd3b2ac4a4eea24 100644 (file)
@@ -49,9 +49,6 @@
 #include <vorbis/vorbisfile.h>
 #include <libmodplug/modplug.h>
 
-#define MAX(x,y) ((x)>(y)) ? (x) : (y)
-#define MIN(x,y) ((x)<(y)) ? (x) : (y)
-
 enum sound_type {
     FORM,
     OGGV,
index 67240c339d3594825fd2ac1528bdf33b85c08a9f..a4a90e3dce7b645f1d80f4fabce55c3745c17c03 100644 (file)
@@ -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
index 23135758799463b158335988fa2806cd565ad8de..f930769367ba32fe474df9ca0bf0347029c289c2 100644 (file)
@@ -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) {
index 7a8be2fc346e6b1ae0dfc2191925a5137cb23fa3..2a18eff3f908ecf2af777af047ca113c47de5d3a 100644 (file)
@@ -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 */