Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KeyName.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_KEYNAME
19 #define INCLUDED_KEYNAME
20 
21 // Need SDLK_* enum values.
23 
24 class CStr8;
25 
26 extern void InitKeyNameMap();
27 extern CStr8 FindKeyName( int keycode );
28 extern int FindKeyCode( const CStr8& keyname );
29 
30 // Pick a code which is greater than any keycodes used by SDL itself
31 #if SDL_VERSION_ATLEAST(1, 3, 0)
32 # define CUSTOM_SDL_KEYCODE SDL_SCANCODE_TO_KEYCODE(SDL_NUM_SCANCODES)
33 #else
34 # define CUSTOM_SDL_KEYCODE SDLK_LAST
35 #endif
36 
37 enum {
38  // 'Keycodes' for the mouse buttons
42 
43 #if SDL_VERSION_ATLEAST(2, 0, 0)
44  // SDL2 doesn't count wheels as buttons, so just give them the next sequential IDs
49 #elif SDL_VERSION_ATLEAST(1, 2, 13)
50  // SDL 1.2 defines wheel buttons before X1/X2 buttons
51  MOUSE_WHEELUP = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELUP,
52  MOUSE_WHEELDOWN = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN,
53  MOUSE_X1 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_X1,
54  MOUSE_X2 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_X2,
55 #else
56  // SDL <1.2.13 doesn't support X1/X2 buttons, so define them manually
59  MOUSE_X1 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN + 1,
60  MOUSE_X2 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN + 2,
61 #endif
62 
63  // 'Keycodes' for the unified modifier keys
69 };
70 
71 #endif // #ifndef INCLUDED_KEYNAME
#define CUSTOM_SDL_KEYCODE
Definition: KeyName.h:34
int FindKeyCode(const CStr &keyname)
Definition: KeyName.cpp:345
CStr FindKeyName(int keycode)
Definition: KeyName.cpp:354
void InitKeyNameMap()
Definition: KeyName.cpp:333