]> git.jsancho.org Git - lugaru.git/blob - Source/Input.cpp
3cf1b1ce99657b9d466589834047025056e680e0
[lugaru.git] / Source / Input.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010 - MCMic
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22
23 /**> HEADER FILES <**/
24 #include "Input.h"
25
26 extern bool keyboardfrozen;
27
28 bool Input::isKeyDown(int k) {
29         if(keyboardfrozen)return 0; // vraiment utile? à vérifier
30         Uint8 *keystate = SDL_GetKeyState(NULL);
31         if(k<SDLK_LAST)
32                 return keystate[k];
33         else
34                 return SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(k-SDLK_LAST);
35 }
36
37 const char* Input::keyToChar(unsigned short i) {
38         if(i<SDLK_LAST)
39                 return SDL_GetKeyName(SDLKey(i));
40         else if(i==SDLK_LAST+SDL_BUTTON_LEFT)
41                 return "mouse1";
42         else if(i==SDLK_LAST+SDL_BUTTON_RIGHT)
43                 return "mouse2";
44         else if(i==SDLK_LAST+SDL_BUTTON_MIDDLE)
45                 return "mouse3";
46         else
47                 return "unknown";
48 }
49
50 unsigned short  Input::CharToKey(const char* which)
51 {
52         for(unsigned short i=0;i<SDLK_LAST;i++) {
53                 if(!strcasecmp(which,SDL_GetKeyName(SDLKey(i))))
54                         return i;
55         }
56         if(!strcasecmp(which,"mouse1")){
57                 return MOUSEBUTTON1;
58         }
59         if(!strcasecmp(which,"mouse2")){
60                 return MOUSEBUTTON2;
61         }
62         return SDLK_LAST;
63 }
64
65 Boolean Input::Button()
66 {
67     return SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(SDL_BUTTON_LEFT);
68 }