X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2Finput%2FinputManager.cpp;h=5a42b2cebc1d87cf0b99d91fdbf73322f8ae3669;hb=3d1f081343dc603a3292538eeb9bd794b255deb6;hp=0df4baad73e9e249e46c156c23627a59d8bddffa;hpb=a823a80039c6069bb7676433832d9f9413494860;p=physics.git diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index 0df4baa..5a42b2c 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -16,7 +16,11 @@ */ #include "inputManager.h" -#include "../debug.h" +#include "debug.h" + +#include + +#include "config/keys.h" /// ***** Private Variables ***** @@ -46,6 +50,8 @@ void input::clean() /// ***** Public Methods ***** +const Uint32 eventMask = -1; // ALL events + void input::update() { SDL_Event event; @@ -58,7 +64,7 @@ void input::update() keyState[i] = isP; } - while(SDL_PollEvent(&event)) + while(0 < SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventMask)) { switch(event.type) { @@ -68,34 +74,50 @@ void input::update() case SDL_KEYDOWN: keyState[event.key.keysym.sym] = wasP; break; + case SDL_QUIT: + keyState[key::end] = wasR; + break; + default: + break; } } } Vector2 input::mousePosition() { - int x; - int y; - + int x,y; SDL_GetMouseState(&x, &y); return Vector2(x,y); } -bool input::isPressed(Uint8 key) +bool input::mouseLeft() +{ + Uint8 state = SDL_GetMouseState(NULL, NULL); + + return state & SDL_BUTTON(1); +} +bool input::mouseRight() +{ + Uint8 state = SDL_GetMouseState(NULL, NULL); + + return state & SDL_BUTTON(3); +} + +bool input::isPressed(const SDLKey& key) { return keyState[key] == isP || keyState[key] == wasP; } -bool input::isReleased(Uint8 key) +bool input::isReleased(const SDLKey& key) { return keyState[key] == isR || keyState[key] == wasR; } -bool input::wasPressed(Uint8 key) +bool input::wasPressed(const SDLKey& key) { return keyState[key] == wasP; } -bool input::wasReleased(Uint8 key) +bool input::wasReleased(const SDLKey& key) { return keyState[key] == wasR; }