X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FUtils%2FInput.cpp;h=70d47a55b44ac03245cc0dcb21a176477bc67a1b;hb=0aab437dc560d2afa982e61cc2547756ad7b0761;hp=93765225ea2de526e35eb826eff922fa302f1a7c;hpb=b84825978803615f45a9f128232e62431042aec0;p=lugaru.git diff --git a/Source/Utils/Input.cpp b/Source/Utils/Input.cpp index 9376522..70d47a5 100644 --- a/Source/Utils/Input.cpp +++ b/Source/Utils/Input.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) +Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. @@ -18,8 +18,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Utils/Input.h" +#include "Utils/Input.hpp" bool keyDown[SDL_NUM_SCANCODES + 6]; bool keyPressed[SDL_NUM_SCANCODES + 6]; @@ -28,7 +27,7 @@ void Input::Tick() { SDL_PumpEvents(); int numkeys; - const Uint8 *keyState = SDL_GetKeyboardState(&numkeys); + const Uint8* keyState = SDL_GetKeyboardState(&numkeys); for (int i = 0; i < numkeys; i++) { keyPressed[i] = !keyDown[i] && keyState[i]; keyDown[i] = keyState[i]; @@ -42,51 +41,40 @@ void Input::Tick() bool Input::isKeyDown(int k) { - if (k >= SDL_NUM_SCANCODES + 6) // really useful? check that. + if (k >= SDL_NUM_SCANCODES + 6) { return false; + } return keyDown[k]; } bool Input::isKeyPressed(int k) { - if (k >= SDL_NUM_SCANCODES + 6) + if (k >= SDL_NUM_SCANCODES + 6) { return false; + } return keyPressed[k]; } const char* Input::keyToChar(unsigned short i) { - if (i < SDL_NUM_SCANCODES) - return SDL_GetScancodeName(SDL_Scancode(i)); - else if (i == MOUSEBUTTON1) - return "mouse1"; - else if (i == MOUSEBUTTON2) - return "mouse2"; - else if (i == MOUSEBUTTON3) - return "mouse3"; - else + if (i < SDL_NUM_SCANCODES) { + return SDL_GetKeyName(SDL_GetKeyFromScancode(SDL_Scancode(i))); + } else if (i == MOUSEBUTTON_LEFT) { + return "mouse left button"; + } else if (i == MOUSEBUTTON_RIGHT) { + return "mouse right button"; + } else if (i == MOUSEBUTTON_MIDDLE) { + return "mouse middle button"; + } else if (i == MOUSEBUTTON_X1) { + return "mouse button 4"; + } else if (i == MOUSEBUTTON_X2) { + return "mouse button 5"; + } else { return "unknown"; -} - -unsigned short Input::CharToKey(const char* which) -{ - for (unsigned short i = 0; i < SDL_NUM_SCANCODES; i++) { - if (!strcasecmp(which, SDL_GetScancodeName(SDL_Scancode(i)))) - return i; - } - if (!strcasecmp(which, "mouse1")) { - return MOUSEBUTTON1; - } - if (!strcasecmp(which, "mouse2")) { - return MOUSEBUTTON2; - } - if (!strcasecmp(which, "mouse3")) { - return MOUSEBUTTON3; } - return SDL_NUM_SCANCODES; } bool Input::MouseClicked() { - return isKeyPressed(SDL_NUM_SCANCODES + SDL_BUTTON_LEFT); + return isKeyPressed(MOUSEBUTTON_LEFT); }