1 /* Tower Toppler - Nebulus
2  * Copyright (C) 2000-2012  Andreas R�ver
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18 
19 #ifndef KEYB_H
20 #define KEYB_H
21 
22 #include "decl.h"
23 
24 #include <SDL_types.h>
25 #include <SDL_keyboard.h>
26 
27 typedef enum {
28   no_key       =  0x0000,
29   up_key       =  0x0001,
30   down_key     =  0x0002,
31   left_key     =  0x0004,
32   right_key    =  0x0008,
33   fire_key     =  0x0010,
34   break_key    =  0x0020,
35   pause_key    =  0x0040,
36   any_key      =  0xFFFF
37 } ttkey;
38 
39 typedef void FDECL((*keyb_wait_proc), (void));
40 
41 void key_init(void);
42 void key_done(void);
43 
44 /* waits until the game window gets focus */
45 void wait_for_focus(void);
46 
47 /* returns bitmask with currently pressed keys */
48 Uint16 key_keystat(void);
49 
50 /* true, if key is pressed */
51 bool key_keypressed(ttkey key);
52 
53 /* returns if a key has been pushed and released (typed) but only for the keys in
54  the list */
55 ttkey key_readkey(void);
56 
57 /* Returns the last pressed key, in SDLKey format */
58 SDLKey key_sdlkey(void);
59 
60 /* Converts sdlkey to internal key representation, or returns no_key
61    if SDLKey cannot be converted. */
62 ttkey key_sdlkey2conv(SDLKey k, bool game);
63 
64 /* Converts internal key to sdlkey, or returns SDLK_UNKNOWN. */
65 SDLKey key_conv2sdlkey(ttkey k, bool game);
66 
67 /* returns a typed character */
68 char key_chartyped(void);
69 
70 /* combines key_sdlkey(), key_readkey() and key_chartyped() */
71 void key_keydatas(SDLKey &sdlkey, ttkey &tkey, char &ch);
72 
73 /* waits until no key is pressed, calling bg while waiting */
74 void key_wait_for_none(keyb_wait_proc bg);
75 
76 /* returns the current mouse coordinate and button pressed. */
77 bool key_mouse(Uint16 *x, Uint16 *y, ttkey *bttn);
78 
79 /* redefine a key, so that it returns code  */
80 void key_redefine(ttkey code, SDLKey key);
81 
82 #endif
83 
84