1 /* src/client/misc.c */
4 #include <ncurses.h> /* delwin(), endwin(), refresh() */
5 #include <stdint.h> /* uint8_t, uint16_t */
6 #include <string.h> /* memset(), strlen() */
7 #include "cleanup.h" /* for set_cleanup_flag() */
8 #include "keybindings.h" /* init_keybindings(), free_keybindings(),
11 #include "map_window.h" /* for map_center() */
12 #include "wincontrol.h" /* struct WinConf, init_winconfs(), init_wins(),
13 * sorted_wintoggle_and_activate(), get_win_by_id(),
14 * get_winconf_by_win(), toggle_window(),
15 * get_next_winconf_id()
17 #include "windows.h" /* struct Win, make_pad(), suspend_win(), free_win() */
18 #include "world.h" /* global world */
22 extern void save_interface_conf()
24 save_keybindings("confclient/keybindings_global", &world.kb_global);
25 save_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
26 save_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
32 extern void load_interface_conf()
34 init_keybindings("confclient/keybindings_global", &world.kb_global);
35 init_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
36 init_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
40 sorted_wintoggle_and_activate();
41 set_cleanup_flag(CLEANUP_INTERFACE);
46 extern void unload_interface_conf()
48 free_keybindings(world.kb_global.kbs);
49 free_keybindings(world.kb_wingeom.kbs);
50 free_keybindings(world.kb_winkeys.kbs);
51 while (0 != world.wmeta.active)
53 suspend_win(world.wmeta.active);
56 delwin(world.wmeta.pad);
61 extern void winch_called(int signal)
68 extern void reset_windows()
70 endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */
71 refresh(); /* <http://invisible-island.net/ncurses/ncurses-intro.html>. */
72 struct Win * w_p = world.wmeta.chain_start;
73 char win_ids[strlen(world.winconf_db.winconf_ids) + 1];
74 memset(win_ids, '\0', strlen(world.winconf_db.winconf_ids) + 1);
77 for (; NULL != w_p; w_p = w_p->next, i++)
79 struct WinConf * wc_p = get_winconf_by_win(w_p);
80 win_ids[i] = wc_p->id;
81 if (w_p == world.wmeta.active)
86 while (0 != world.wmeta.active)
88 w_p = world.wmeta.active;
92 while (0 != (id = get_next_winconf_id()))
94 free_win(get_win_by_id(id));
96 delwin(world.wmeta.pad);
99 if (strlen(win_ids) < 1)
103 for (i = 0; i < strlen(win_ids); i++)
105 toggle_window(win_ids[i]);
106 if (active == win_ids[i])
108 world.wmeta.active = get_win_by_id(win_ids[i]);
115 extern void reload_interface_conf()
117 unload_interface_conf();
118 load_interface_conf();
124 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
128 if (mapsize > framesize)
130 if (position > framesize / 2)
132 if (position < mapsize - (framesize / 2))
134 offset = position - (framesize / 2);
138 offset = mapsize - framesize;
147 extern void nav_inventory(char dir)
151 world.player_inventory_select = world.player_inventory_select
152 - (world.player_inventory_select > 0);
157 for (i = 0; '\0' != world.player_inventory[i]; i++)
159 n_elems = n_elems + ('\n' == world.player_inventory[i]);
161 world.player_inventory_select = world.player_inventory_select
162 + (world.player_inventory_select < n_elems);