2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
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. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "inputManager.h"
23 #include "../config/keys.h"
26 /// ***** Private Variables *****
36 static const int keySize = 323;
37 static State keyState[keySize];
39 /// ***** Initializers/Cleaners *****
43 for(int i=0; i< keySize; i++)
51 /// ***** Public Methods *****
53 const Uint32 eventMask = -1; // ALL events
59 for(int i=0; i< keySize; i++)
61 if(keyState[i] == wasR)
63 else if(keyState[i] == wasP)
67 while(0 < SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventMask))
72 keyState[event.key.keysym.sym] = wasR;
75 keyState[event.key.keysym.sym] = wasP;
78 keyState[key::end] = wasR;
86 Vector2 input::mousePosition()
89 SDL_GetMouseState(&x, &y);
94 bool input::mouseLeft()
96 Uint8 state = SDL_GetMouseState(NULL, NULL);
98 return state & SDL_BUTTON(1);
100 bool input::mouseRight()
102 Uint8 state = SDL_GetMouseState(NULL, NULL);
104 return state & SDL_BUTTON(3);
107 bool input::isPressed(const SDLKey& key)
109 return keyState[key] == isP || keyState[key] == wasP;
111 bool input::isReleased(const SDLKey& key)
113 return keyState[key] == isR || keyState[key] == wasR;
116 bool input::wasPressed(const SDLKey& key)
118 return keyState[key] == wasP;
120 bool input::wasReleased(const SDLKey& key)
122 return keyState[key] == wasR;