]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/CKeyboard.cpp
Import of version 1.14 minus music and sounds.
[quix0rs-blobwars.git] / src / CKeyboard.cpp
1 /*
2 Copyright (C) 2004 Parallel Realities
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.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "headers.h"
22
23 Keyboard::Keyboard()
24 {
25         setDefaultKeys();
26 }
27
28 void Keyboard::setDefaultKeys()
29 {
30         control[CONTROL::LEFT] = SDLK_LEFT;
31         control[CONTROL::RIGHT] = SDLK_RIGHT;
32         control[CONTROL::DOWN] = SDLK_DOWN;
33         control[CONTROL::JUMP] = SDLK_UP;
34         control[CONTROL::UP] = 0;
35         control[CONTROL::FIRE] = SDLK_LCTRL;
36         control[CONTROL::JETPACK] = SDLK_SPACE;
37         control[CONTROL::PAUSE] = SDLK_p;
38         control[CONTROL::MAP] = SDLK_TAB;
39 }
40
41 const char *Keyboard::translateKey(int key)
42 {
43         static char keyName[50];
44         strcpy(keyName, "");
45         keyName[0] = '\0';
46         
47         if (key <= 0)
48         {
49                 return "...";
50         }
51         
52         strcpy(keyName, _(SDL_GetKeyName((SDLKey)key)));
53         
54         /*
55         This is not really neccessary, but it just makes
56         everything look neater. It runs through the string
57         and uppercase the first letter and any letter after
58         a space.
59         */
60         
61         bool uppercase = true;
62         char *c = keyName;
63         
64         while (*c != '\0')
65         {
66                 if ((*c >= SDLK_a) && (*c <= SDLK_z))
67                 {
68                         if (uppercase)
69                         {
70                                 *c -= 32;
71                                 uppercase = false;
72                         }
73                 }
74                 else if (*c == SDLK_SPACE)
75                 {
76                         uppercase = true;
77                 }
78                 
79                 c++;
80         }
81         
82         return keyName;
83 }
84