From: Christian Heller Date: Thu, 29 Aug 2013 20:05:05 +0000 (+0200) Subject: Moved several windows control functions from misc library into new wincontrol library. X-Git-Tag: tce~1007 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/day_todos?a=commitdiff_plain;h=e6dcab0e1261bc96d7754b24b798cc3a5f262335;p=plomrogue Moved several windows control functions from misc library into new wincontrol library. --- diff --git a/src/control.c b/src/control.c index a2a44b2..0c782ab 100644 --- a/src/control.c +++ b/src/control.c @@ -11,9 +11,9 @@ #include "map.h" /* for map_scroll(), map_center_player(), dir enum */ #include "main.h" /* for World struct */ #include "rexit.h" /* for exit_err() */ -#include "misc.h" /* for scroll_pad(), toggle_window(), - * growshrink_active_window() - */ +#include "wincontrol.h" /* for scroll_pad(), toggle_window(), + * growshrink_active_window() + */ #include "map_object_actions.h" /* for player_wait(), move_player() */ #include "command_db.h" /* for is_command_id_shortdsc() */ diff --git a/src/main.c b/src/main.c index f240975..6c60afa 100644 --- a/src/main.c +++ b/src/main.c @@ -21,9 +21,8 @@ * build_map_objects() */ #include "map.h" /* for struct Map, init_map() */ -#include "misc.h" /* for update_log(), toggle_window(), find_passable_pos(), - * save_game() - */ +#include "misc.h" /* for update_log(), find_passable_pos(), save_game() */ +#include "wincontrol.h" /* for toggle_window() */ #include "rrand.h" /* for rrand(), rrand_seed() */ #include "rexit.h" /* for exit_game() */ #include "control.h" /* for meta_control() */ diff --git a/src/misc.c b/src/misc.c index b826436..b007dcd 100644 --- a/src/misc.c +++ b/src/misc.c @@ -5,20 +5,18 @@ #include /* for unlink(), acess() */ #include /* for calloc(), free() */ #include /* for strlen(), strcmp(), memcpy() */ -#include /* for uint8_t */ -#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), - * resize_active_win(), struct Win, struct WinMeta - */ +#include /* for uint16_t */ #include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian]() */ #include "map_objects.h" /* for struct Monster, write_map_objects(), */ #include "map_object_actions.h" /* for is_passable(), move_monster() */ #include "map.h" /* for Map struct */ #include "main.h" /* for World struct */ -#include "yx_uint16.h" /* for yx_uint16 */ +#include "yx_uint16.h" /* for yx_uint16 struct */ #include "rrand.h" /* for rrand(), rrand_seed() */ #include "rexit.h" /* for exit_err() */ + extern void textfile_sizes(FILE * file, uint16_t * linemax_p, uint16_t * n_lines_p) { @@ -191,62 +189,6 @@ extern void save_game(struct World * world) -extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) -{ - if (0 != win->frame.curses_win) - { - return suspend_win(win_meta, win); - } - else - { - return append_win(win_meta, win); - } -} - - - -extern void scroll_pad(struct WinMeta * win_meta, char dir) -{ - if ('+' == dir) - { - reset_pad_offset(win_meta, win_meta->pad_offset + 1); - } - else if ('-' == dir) - { - reset_pad_offset(win_meta, win_meta->pad_offset - 1); - } -} - - - -extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change) -{ - if (0 != win_meta->active) - { - struct yx_uint16 size = win_meta->active->frame.size; - if (change == '-') - { - size.y--; - } - else if (change == '+') - { - size.y++; - } - else if (change == '_') - { - size.x--; - } - else if (change == '*') - { - size.x++; - } - return resize_active_win (win_meta, size); - } - return 0; -} - - - extern struct yx_uint16 find_passable_pos(struct Map * map) { struct yx_uint16 pos; diff --git a/src/misc.h b/src/misc.h index eb2d0cd..be43197 100644 --- a/src/misc.h +++ b/src/misc.h @@ -9,12 +9,10 @@ -#include /* for uint8_t, uint16_t, uint32_t */ +#include /* for uint16_t */ #include /* for FILE typedef */ #include "yx_uint16.h" /* for yx_uint16 coordinates */ struct World; -struct WinMeta; -struct Win; struct Map; @@ -54,32 +52,6 @@ extern void save_game(struct World * world); -/* Toggle display of a window "win". - * - * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. - */ -extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win); - - - -/* Try to scroll virtual screen left ("dir" = "-") or right ("dir" = "+"), - * subject to the limitations provided by the window manager via - * reset_pad_offset(). - */ -extern void scroll_pad(struct WinMeta * win_meta, char dir); - - - -/* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or - * vertically ("change = "+"/"-") by one cell size, subject to the limitations - * provided by the window manager via resize_active_win(). - * - * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. - */ -extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change); - - - /* Return a random position on the map "map" that is passable (as determined by * is_passable(). */ diff --git a/src/wincontrol.c b/src/wincontrol.c new file mode 100644 index 0000000..4d166e8 --- /dev/null +++ b/src/wincontrol.c @@ -0,0 +1,64 @@ +/* wincontrol.c */ + +#include "wincontrol.h" +#include /* for uint8_t */ +#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), + * resize_active_win(), struct Win, struct WinMeta + */ +#include "yx_uint16.h" /* for yx_uint16 struct */ + + +extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) +{ + if (0 != win->frame.curses_win) + { + return suspend_win(win_meta, win); + } + else + { + return append_win(win_meta, win); + } +} + + + +extern void scroll_pad(struct WinMeta * win_meta, char dir) +{ + if ('+' == dir) + { + reset_pad_offset(win_meta, win_meta->pad_offset + 1); + } + else if ('-' == dir) + { + reset_pad_offset(win_meta, win_meta->pad_offset - 1); + } +} + + + +extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change) +{ + if (0 != win_meta->active) + { + struct yx_uint16 size = win_meta->active->frame.size; + if (change == '-') + { + size.y--; + } + else if (change == '+') + { + size.y++; + } + else if (change == '_') + { + size.x--; + } + else if (change == '*') + { + size.x++; + } + return resize_active_win (win_meta, size); + } + return 0; +} + diff --git a/src/wincontrol.h b/src/wincontrol.h new file mode 100644 index 0000000..18ac01c --- /dev/null +++ b/src/wincontrol.h @@ -0,0 +1,44 @@ +/* wincontrol.h + * + * Routines that build on top of the windows library to provide a simple window + * management API to the game. + */ + +#ifndef WINCONTROL_H +#define WINCONTROL_H + + + +#include /* for uint8_t */ +struct Win; +struct WinMeta; + + + +/* Toggle display of a window "win". + * + * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. + */ +extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win); + + + +/* Try to scroll virtual screen left ("dir" = "-") or right ("dir" = "+"), + * subject to the limitations provided by the window manager via + * reset_pad_offset(). + */ +extern void scroll_pad(struct WinMeta * win_meta, char dir); + + + +/* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or + * vertically ("change = "+"/"-") by one cell size, subject to the limitations + * provided by the window manager via resize_active_win(). + * + * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. + */ +extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change); + + + +#endif