home · contact · privacy
Moved meta_keys() into new library "control" to soon include all key-press processing.
[plomrogue] / src / control.c
1 /* control.c */
2
3 #include "control.h"
4 #include <stdint.h> /* for uint8_t */
5 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
6                       *  struct WinMeta
7                       */
8 #include "keybindings.h" /* for get_action_key(), save_keybindings(),
9                           * keyswin_move_selection(), keyswin_mod_key()
10                           */
11 #include "map.h" /* for map_scroll(), map_center_player(), dir enum */
12 #include "main.h" /* for World struct */
13 #include "rexit.h" /* for exit_err() */
14 #include "misc.h" /* for scroll_pad(), toggle_window(),
15                    * growshrink_active_window()
16                    */
17
18
19
20 extern uint8_t meta_keys(int key, struct World * world)
21 {
22     struct WinMeta * win_meta = world->wins.meta;
23     struct Win * win_keys     = world->wins.keys;
24     struct Win * win_map      = world->wins.map;
25     struct Win * win_info     = world->wins.info;
26     struct Win * win_log      = world->wins.log;
27     char * err_toggle = "Trouble with toggle_window() in meta_keys().";
28     char * err_shift  = "Trouble with shift_active_win() in meta_keys().";
29     char * err_resize = "Trouble with growshrink_active_window() in "
30                         "meta_keys().";
31     if (key == get_action_key(world->keybindings, "quit"))
32     {
33         return 1;
34     }
35     else if (key == get_action_key(world->keybindings, "scroll pad right"))
36     {
37         scroll_pad(win_meta, '+');
38     }
39     else if (key == get_action_key(world->keybindings, "scroll pad left"))
40     {
41         scroll_pad(win_meta, '-');
42     }
43     else if (key == get_action_key(world->keybindings, "toggle keys window"))
44     {
45         exit_err(toggle_window(win_meta, win_keys), world, err_toggle);
46     }
47     else if (key == get_action_key(world->keybindings, "toggle map window"))
48     {
49         exit_err(toggle_window(win_meta, win_map), world, err_toggle);
50     }
51     else if (key == get_action_key(world->keybindings, "toggle info window"))
52     {
53         exit_err(toggle_window(win_meta, win_info), world, err_toggle);
54     }
55     else if (key == get_action_key(world->keybindings, "toggle log window"))
56     {
57         exit_err(toggle_window(win_meta, win_log), world, err_toggle);
58     }
59     else if (key == get_action_key(world->keybindings, "cycle forwards"))
60     {
61         cycle_active_win(win_meta, 'f');
62     }
63     else if (key == get_action_key(world->keybindings, "cycle backwards"))
64     {
65         cycle_active_win(win_meta, 'b');
66     }
67     else if (key == get_action_key(world->keybindings, "shift forwards"))
68     {
69         exit_err(shift_active_win(win_meta, 'f'), world, err_shift);
70     }
71     else if (key == get_action_key(world->keybindings, "shift backwards"))
72     {
73         exit_err(shift_active_win(win_meta, 'b'), world, err_shift);
74     }
75     else if (key == get_action_key(world->keybindings, "grow horizontally"))
76     {
77         exit_err(growshrink_active_window(win_meta, '*'), world, err_resize);
78     }
79     else if (key == get_action_key(world->keybindings, "shrink horizontally"))
80     {
81         exit_err(growshrink_active_window(win_meta, '_'), world, err_resize);
82     }
83     else if (key == get_action_key(world->keybindings, "grow vertically"))
84     {
85         exit_err(growshrink_active_window(win_meta, '+'), world, err_resize);
86     }
87     else if (key == get_action_key(world->keybindings, "shrink vertically"))
88     {
89         exit_err(growshrink_active_window(win_meta, '-'), world, err_resize);
90     }
91     else if (key == get_action_key(world->keybindings, "save keys"))
92     {
93         save_keybindings(world);
94     }
95     else if (key == get_action_key(world->keybindings, "keys nav up"))
96     {
97         keyswin_move_selection (world, 'u');
98     }
99     else if (key == get_action_key(world->keybindings, "keys nav down"))
100     {
101         keyswin_move_selection (world, 'd');
102     }
103     else if (key == get_action_key(world->keybindings, "keys mod"))
104     {
105         keyswin_mod_key (world, win_meta);
106     }
107     else if (key == get_action_key(world->keybindings, "map up"))
108     {
109         map_scroll(world->map, NORTH, win_map->frame.size);
110      }
111     else if (key == get_action_key(world->keybindings, "map down"))
112     {
113         map_scroll(world->map, SOUTH, win_map->frame.size);
114     }
115     else if (key == get_action_key(world->keybindings, "map right"))
116     {
117         map_scroll(world->map, EAST, win_map->frame.size);
118     }
119     else if (key == get_action_key(world->keybindings, "map left"))
120     {
121         map_scroll(world->map, WEST, win_map->frame.size);
122     }
123     else if (key == get_action_key(world->keybindings, "map center player"))
124     {
125         map_center_player (world->map, world->player, win_map->frame.size);
126     }
127     return 0;
128 }