"main().";
exit_err(init_win_meta(screen, &win_meta), &world, err_winmem);
world.wins.meta = &win_meta;
- struct Win win_keys = init_win(&win_meta,
- "Keys", 0, 29, &world, draw_keys_win);
- struct Win win_info = init_win(&win_meta,
- "Info", 3, 20, &world, draw_info_win);
- struct Win win_log = init_win(&win_meta,
- "Log", -4, 20, &world, draw_log_win);
- struct Win win_map = init_win(&win_meta,
- "Map", 0, -51, &world, draw_map_win);
+ struct Win win_keys = init_win_from_file(&world, "Keys", draw_keys_win);
+ struct Win win_info = init_win_from_file(&world, "Info", draw_info_win);
+ struct Win win_log = init_win_from_file(&world, "Log", draw_log_win);
+ struct Win win_map = init_win_from_file(&world, "Map", draw_map_win);
world.wins.keys = &win_keys;
- world.wins.log = &win_log;
+ world.wins.log = &win_log;
world.wins.info = &win_info;
- world.wins.map = &win_map;
+ world.wins.map = &win_map;
sorted_wintoggle(&world);
/* Replay mode. */
/* wincontrol.c */
#include "wincontrol.h"
+#include <stdlib.h> /* for malloc(), free() */
#include <string.h> /* for strlen() */
#include <stdint.h> /* for uint8_t, uint16_t */
#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(),
- * resize_active_win(), struct Win, struct WinMeta
+ * resize_active_win(), init_win(), structs Win, WinMeta
*/
#include "yx_uint16.h" /* for yx_uint16 struct */
#include "main.h" /* for Wins struct */
+extern struct Win init_win_from_file(struct World * world, char * w_name,
+ void (* f) (struct Win *))
+{
+ char * err = "Trouble in init_win_from_file() with malloc().";
+ char * prefix = "config/Win_";
+ uint8_t size = strlen(prefix) + strlen(w_name) + 1;
+ char * path = malloc(size);
+ exit_err(NULL == path, world, err);
+ sprintf(path, "%s%s", prefix, w_name);
+
+ err = "Trouble in init_win_from_file() with fopen().";
+ FILE * file = fopen(path, "r");
+ free(path);
+ exit_err(NULL == file, world, err);
+ uint16_t linemax;
+ textfile_sizes(file, &linemax, NULL);
+ char * line = malloc(linemax);
+ err = "Trouble in init_win_from_file() with fgets().";
+ exit_err(NULL == fgets(line, linemax, file), world, err);
+ int16_t height = atoi(line);
+ exit_err(NULL == fgets(line, linemax, file), world, err);
+ int16_t width = atoi(line);
+ free(line);
+ err = "Trouble in init_win_from_file() with fclose().";
+ exit_err(fclose(file), world, err);
+
+ struct WinMeta * wmeta = world->wins.meta;
+ return init_win(wmeta, w_name, height, width, world, f);
+}
+
+
extern void sorted_wintoggle(struct World * world)
{
+/* Wrapper around init_win() that reads the desired window size from a file
+ * at the path prefixing the provided win name "w_name" with "config/Win_".
+ * "f" is the window drawing function (Win._draw()).
+ */
+extern struct Win init_win_from_file(struct World * world, char * w_name,
+ void (* f) (struct Win *));
+
+
+
+
/* Toggle windows in world->wins in the order desribed by the first line of
* config/toggled_win_order, wherein each character may correspond to one
* hardcoded window.