home · contact · privacy
Optimized WinConf / WinConfDB structure, removed redundant .draw.
[plomrogue] / src / client / windows.c
index dcf450b3fecff04703bb513d256cb021f5f594d4..1459ec2303c6c3b83946dbc4f94a8bd5252c16a5 100644 (file)
@@ -1,14 +1,15 @@
 /* src/client/windows.c */
 
 #include "windows.h"
+#include <stddef.h> /* NULL */
 #include <stdint.h> /* uint8_t, uint16_t, uint32_t, UINT16_MAX */
 #include <stdio.h> /* sprintf() */
 #include <stdlib.h> /* free() */
 #include <string.h> /* strlen(), memcpy(), strnlen() */
-#include <ncurses.h> /* pnoutrefresh(), doupdate(), werase(), wnoutrefresh(),
-                      * erase(), getmaxx(), getmaxy(), delwin(), endwin(),
-                      * initscr(), noecho(), curs_set(), newpad(), mvwaddch(),
-                      * mvwaddstr(), wresize(), chtype
+#include <ncurses.h> /* chtype, pnoutrefresh(), doupdate(), werase(), erase(),
+                      * wnoutrefresh(), getmaxx(), getmaxy(), initscr(),
+                      * noecho(), curs_set(), newpad(), mvwaddch(), mvwaddstr(),
+                      * wresize()
                       */
 #include "../common/rexit.h" /* for exit_err() */
 #include "../common/try_malloc.h" /* for try_malloc() */
@@ -422,29 +423,38 @@ static void shift_win_backward()
 
 
 
-extern void init_win_meta()
+extern void init_wmeta_and_ncurses()
 {
-    char * err_s = "init_win_meta() creates virtual screen beyond legal size.";
-    char * err_m = "init_win_meta() triggers memory alloc error via newpad().";
     world.wmeta.screen = initscr();
     set_cleanup_flag(CLEANUP_NCURSES);
     noecho();
     curs_set(0);
-    uint32_t maxy_test  = getmaxy(world.wmeta.screen);
-    uint32_t maxx_test  = getmaxx(world.wmeta.screen);
-    exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s);
-    world.wmeta.padsize.y   = maxy_test;
-    world.wmeta.padsize.x   = maxx_test;
+    world.wmeta.padsize.y   = 0;
+    world.wmeta.padsize.x   = 0;
     world.wmeta.chain_start = 0;
     world.wmeta.chain_end   = 0;
     world.wmeta.pad_offset  = 0;
-    world.wmeta.pad         = newpad(world.wmeta.padsize.y, 1);
-    exit_err(NULL == world.wmeta.pad, err_m);
+    world.wmeta.pad         = NULL;
     world.wmeta.active      = 0;
 }
 
 
 
+extern void make_pad()
+{
+    char * err_s = "make_pad() creates an illegaly large virtual screen.";
+    char * err_m = "make_pad() triggers memory allocation error via newpad().";
+    uint32_t maxy_test = getmaxy(world.wmeta.screen);
+    uint32_t maxx_test = getmaxx(world.wmeta.screen);
+    exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s);
+    world.wmeta.padsize.y = maxy_test;
+    world.wmeta.padsize.x = maxx_test;
+    world.wmeta.pad = newpad(world.wmeta.padsize.y, 1);
+    exit_err(NULL == world.wmeta.pad, err_m);
+}
+
+
+
 extern void init_win(struct Win ** wp, char * title, int16_t height,
                      int16_t width, void * func)
 {
@@ -460,35 +470,29 @@ extern void init_win(struct Win ** wp, char * title, int16_t height,
     w->draw         = func;
     w->center.y     = 0;
     w->center.x     = 0;
-    if      (0 < width)
+    w->framesize.y  = world.wmeta.padsize.y - 1;
+    if      (0 < height && height <= world.wmeta.padsize.y - 1)
     {
-        w->framesize.x = width;
+        w->framesize.y = height;
     }
-    else if (0 >= width)
+    else if (0 > height && world.wmeta.padsize.y + (height - 1) > 0)
     {
-        w->framesize.x = world.wmeta.padsize.x + width;
+        w->framesize.y = world.wmeta.padsize.y + (height - 1);
     }
-    if      (0 < height && height <= world.wmeta.padsize.y - 1)
+    w->framesize.x  = world.wmeta.padsize.x;
+    if      (0 < width)
     {
-        w->framesize.y = height;
+        w->framesize.x = width;
     }
-    else if (0 >= height && world.wmeta.padsize.y + (height - 1) > 0)
+    else if (0 > width && world.wmeta.padsize.x + width > 0)
     {
-        w->framesize.y = world.wmeta.padsize.y + (height - 1);
+        w->framesize.x = world.wmeta.padsize.x + width;
     }
     *wp = w;
 }
 
 
 
-extern void free_winmeta_and_endwin()
-{
-    delwin(world.wmeta.pad);
-    endwin();
-}
-
-
-
 extern void free_win(struct Win * win)
 {
     free(win->title);