]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/CKeyboard.cpp
Initial conversion to SDL2.
[quix0rs-blobwars.git] / src / CKeyboard.cpp
1 /*
2 Copyright (C) 2004-2011 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] = SDL_SCANCODE_LEFT;
31         control[CONTROL::RIGHT] = SDL_SCANCODE_RIGHT;
32         control[CONTROL::DOWN] = SDL_SCANCODE_DOWN;
33         control[CONTROL::JUMP] = SDL_SCANCODE_UP;
34         control[CONTROL::UP] = 0;
35         control[CONTROL::FIRE] = SDL_SCANCODE_LCTRL;
36         control[CONTROL::JETPACK] = SDL_SCANCODE_SPACE;
37         control[CONTROL::PAUSE] = SDL_SCANCODE_P;
38         control[CONTROL::MAP] = SDL_SCANCODE_TAB;
39 }
40
41 const char *Keyboard::translateKey(int key)
42 {
43         static char keyName[50];
44         keyName[0] = 0;
45         keyName[0] = '\0';
46         
47         if (key <= 0)
48         {
49                 return "...";
50         }
51         
52         strlcpy(keyName, _(SDL_GetKeyName(key)), sizeof keyName);
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 >= SDL_SCANCODE_A) && (*c <= SDL_SCANCODE_Z))
67                 {
68                         if (uppercase)
69                         {
70                                 *c -= 32;
71                                 uppercase = false;
72                         }
73                 }
74                 else if (*c == SDL_SCANCODE_SPACE)
75                 {
76                         uppercase = true;
77                 }
78                 
79                 c++;
80         }
81         
82         return keyName;
83 }
84