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"
24 #include "config/keys.h"
27 /// ***** Private Variables *****
37 static const int keySize = 323;
38 static State keyState[keySize];
40 /// ***** Initializers/Cleaners *****
44 for(int i=0; i< keySize; i++)
52 /// ***** Public Methods *****
54 const Uint32 eventMask = -1; // ALL events
60 for(int i=0; i< keySize; i++)
62 if(keyState[i] == wasR)
64 else if(keyState[i] == wasP)
68 while(0 < SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventMask))
73 keyState[event.key.keysym.sym] = wasR;
76 keyState[event.key.keysym.sym] = wasP;
79 keyState[key::end] = wasR;
87 Vector2 input::mousePosition()
90 SDL_GetMouseState(&x, &y);
95 bool input::mouseLeft()
97 Uint8 state = SDL_GetMouseState(NULL, NULL);
99 return state & SDL_BUTTON(1);
101 bool input::mouseRight()
103 Uint8 state = SDL_GetMouseState(NULL, NULL);
105 return state & SDL_BUTTON(3);
108 bool input::isPressed(const SDLKey& key)
110 return keyState[key] == isP || keyState[key] == wasP;
112 bool input::isReleased(const SDLKey& key)
114 return keyState[key] == isR || keyState[key] == wasR;
117 bool input::wasPressed(const SDLKey& key)
119 return keyState[key] == wasP;
121 bool input::wasReleased(const SDLKey& key)
123 return keyState[key] == wasR;