X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FUtils%2FInput.cpp;h=06a7b74e649c9f68b513345e2df8f6f98817076b;hb=d3f16728298e0639a3b2e916386f4e8cea4018ff;hp=93765225ea2de526e35eb826eff922fa302f1a7c;hpb=b84825978803615f45a9f128232e62431042aec0;p=lugaru.git diff --git a/Source/Utils/Input.cpp b/Source/Utils/Input.cpp index 9376522..06a7b74 100644 --- a/Source/Utils/Input.cpp +++ b/Source/Utils/Input.cpp @@ -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]; @@ -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); }