From: Christian Heller Date: Thu, 29 Aug 2013 22:06:40 +0000 (+0200) Subject: Negative values may now be passed to init_win() for sizes in negative relation to... X-Git-Tag: tce~1003 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/new_day?a=commitdiff_plain;h=3b2c82991c9ab169b33248c7be840a9bcd351e6d;p=plomrogue Negative values may now be passed to init_win() for sizes in negative relation to the terminal screen size. --- diff --git a/src/main.c b/src/main.c index 50a14a9..f637aea 100644 --- a/src/main.c +++ b/src/main.c @@ -204,18 +204,14 @@ int main(int argc, char *argv[]) "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); - 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); + 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); world.wins.keys = &win_keys; world.wins.log = &win_log; world.wins.info = &win_info; diff --git a/src/windows.c b/src/windows.c index 48d17f0..efba919 100644 --- a/src/windows.c +++ b/src/windows.c @@ -389,7 +389,7 @@ extern uint8_t init_win_meta(WINDOW * screen, struct WinMeta * wmeta) extern struct Win init_win(struct WinMeta * wmeta, char * title, - uint16_t height, uint16_t width, + int16_t height, int16_t width, void * data, void * func) { struct Win w; @@ -399,18 +399,26 @@ extern struct Win init_win(struct WinMeta * wmeta, char * title, w._title = title; w.data = data; w._draw = func; - if (width > 0) + if (0 < width) { w.frame.size.x = width; } + else if (0 > width) + { + w.frame.size.x = wmeta->padframe.size.x + width; + } else { w.frame.size.x = wmeta->padframe.size.x; } - if (height > 0 && height <= wmeta->padframe.size.y - 1) + if (0 < height && height <= wmeta->padframe.size.y - 1) { w.frame.size.y = height; } + else if (0 > height && wmeta->padframe.size.y + (height - 1) > 0) + { + w.frame.size.y = wmeta->padframe.size.y + (height - 1); + } else { w.frame.size.y = wmeta->padframe.size.y - 1; diff --git a/src/windows.h b/src/windows.h index 8cb5ec1..a98bbdb 100644 --- a/src/windows.h +++ b/src/windows.h @@ -104,14 +104,18 @@ extern uint8_t init_win_meta(WINDOW * screen, struct WinMeta * wmeta); * if the window is visible. * * Pass 0 for "width" to make the window as wide as the terminal screen. Pass - * for "height" 0 or a value larger than the maximum window height possible - * within the virtual screen to attain that maximum window height. + * negative values for "width" to make the size so many cells smaller than the + * terminal screen. Pass 0 for "height" to give the window the maximum allowed + * height: one cell smaller than the terminal screen. Pass negative values to + * make the window so many smalls smaller than the terminal screen. The maximum + * allowed height is also applied for positive values that exceed it or negative + * values that would reduce the window height < 1 cell. * * Other members of the Win struct are 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 width, + int16_t height, int16_t width, void * data, void * func);