From: Christian Heller Date: Tue, 6 Aug 2013 02:45:23 +0000 (+0200) Subject: init_win() now takes arguments for the designated window height and width. X-Git-Tag: tce~1103 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/static/foo.html?a=commitdiff_plain;h=7815e738f77aad4e918c84a89aa21f7ae683ebab;p=plomrogue init_win() now takes arguments for the designated window height and width. --- diff --git a/src/main.c b/src/main.c index 9c2b87e..80e7b01 100644 --- a/src/main.c +++ b/src/main.c @@ -134,16 +134,15 @@ int main(int argc, char *argv[]) raw(); init_keybindings(&world); struct WinMeta win_meta = init_win_meta(screen); - struct Win win_keys = init_win(&win_meta, "Keys", &world, draw_keys_win); - struct Win win_map = init_win(&win_meta, "Map", &world, draw_map_win); - struct Win win_info = init_win(&win_meta, "Info", &world, draw_info_win); - struct Win win_log = init_win(&win_meta, "Log", &world, draw_log_win); - win_keys.frame.size.x = 29; - win_map.frame.size.x = win_meta.padframe.size.x - win_keys.frame.size.x - - win_log.frame.size.x - 2; - win_info.frame.size.y = 2; - win_log.frame.size.y = win_meta.padframe.size.y - - (2 + win_info.frame.size.y); + struct Win win_keys = init_win(&win_meta, "Keys", 0, 29, &world, draw_keys_win); + struct Win win_info = init_win(&win_meta, "Info", 2, 20, &world, draw_info_win); + uint16_t height_logwin = win_meta.padframe.size.y - (2 + win_info.frame.size.y); + struct Win win_log = init_win(&win_meta, "Log", + height_logwin, 20, &world, draw_log_win); + uint16_t width_mapwin = win_meta.padframe.size.x - win_keys.frame.size.x + - win_log.frame.size.x - 2; + struct Win win_map = init_win(&win_meta, "Map", + 0, width_mapwin, &world, draw_map_win); toggle_window(&win_meta, &win_keys); toggle_window(&win_meta, &win_map); toggle_window(&win_meta, &win_info); diff --git a/src/windows.c b/src/windows.c index 86cf1fe..ef7a30d 100644 --- a/src/windows.c +++ b/src/windows.c @@ -270,6 +270,7 @@ extern struct WinMeta init_win_meta(WINDOW * screen) extern struct Win init_win(struct WinMeta * wmeta, char * title, + uint16_t height, uint16_t width, void * data, void * func) { struct Win w; @@ -277,10 +278,24 @@ extern struct Win init_win(struct WinMeta * wmeta, char * title, w.next = 0; w.frame.curses_win = 0; w.title = title; - w.frame.size.x = 20; - w.frame.size.y = wmeta->padframe.size.y - 1; w.data = data; w.draw = func; + if (width > 0) + { + w.frame.size.x = width; + } + else + { + w.frame.size.x = 1; + } + if (height > 0 && height <= wmeta->padframe.size.y - 1) + { + w.frame.size.y = height; + } + else + { + w.frame.size.y = wmeta->padframe.size.y - 1; + } return w; } diff --git a/src/windows.h b/src/windows.h index 2c8c19e..2823996 100644 --- a/src/windows.h +++ b/src/windows.h @@ -88,17 +88,20 @@ extern struct WinMeta init_win_meta(WINDOW * screen); -/* Create a window below inside "wmeta" titled "title" and appointing "func"() - * to interpret and draw the content stored at "data" if the window is visible. +/* Create a window below inside "wmeta" titled "title" of "height" and "width" + * and appointing "func"() to interpret and draw the content stored at "data" + * if the window is visible. * - * The start size for the Frame will be a width of 20 cells and a height one - * less than the height of the virtual screen (so as to fit the title bar on top - * of the window). Other values will be initialized to 0. The window will stay - * invisible until appended to the chain of visible windows via append_win(). + * A value for "width" <1 will trigger a fallback to width=1. A "height" <1 or + * larger than the maximum window height possible within the virtual screen will + * trigger a fallback to the maximum height possible (i.e. pass a "height" of 0 + * to initialize the window to its largest possible height). * - * TODO: Why default start widths/heights instead of passing start values? + * Other values of the Win struct will be initialized to 0. The window will stay + * invisible until appended to the chain of visible windows via append_win(). */ extern struct Win init_win(struct WinMeta * wmeta, char * title, + uint16_t height, uint16_t widtht, void * data, void * func);