macros and ui element
This commit is contained in:
@@ -2,12 +2,19 @@
|
||||
|
||||
namespace Game {
|
||||
const bool* Input::mCurrentKeyStates = nullptr;
|
||||
bool* Input::mPreviousKeyStates = nullptr;
|
||||
const bool* Input::mPreviousKeyStates = nullptr;
|
||||
int Input::mNumKeys = 0;
|
||||
SDL_MouseButtonFlags Input::mCurrentMouseButtonStates = 0;
|
||||
SDL_MouseButtonFlags Input::mPreviousMouseButtonStates = 0;
|
||||
float Input::mMouseX = 0.0f;
|
||||
float Input::mMouseY = 0.0f;
|
||||
|
||||
void Input::update() {
|
||||
mPreviousKeyStates = const_cast<bool*>(mCurrentKeyStates);
|
||||
mPreviousKeyStates = mCurrentKeyStates;
|
||||
mCurrentKeyStates = SDL_GetKeyboardState(&mNumKeys);
|
||||
|
||||
mPreviousMouseButtonStates = mCurrentMouseButtonStates;
|
||||
mCurrentMouseButtonStates = SDL_GetMouseState(&mMouseX, &mMouseY);
|
||||
}
|
||||
|
||||
bool Input::isKeyPressed(SDL_Scancode key) {
|
||||
@@ -24,4 +31,24 @@ namespace Game {
|
||||
if (key < 0 || key >= mNumKeys) return false;
|
||||
return (!mCurrentKeyStates[key]) && mPreviousKeyStates && mPreviousKeyStates[key];
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonPressed(Uint8 button) {
|
||||
return (mCurrentMouseButtonStates & SDL_BUTTON_MASK(button)) != 0;
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonJustPressed(Uint8 button) {
|
||||
return (mCurrentMouseButtonStates & SDL_BUTTON_MASK(button)) != 0 && (mPreviousMouseButtonStates & SDL_BUTTON_MASK(button)) == 0;
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonJustReleased(Uint8 button) {
|
||||
return (mCurrentMouseButtonStates & SDL_BUTTON_MASK(button)) == 0 && (mPreviousMouseButtonStates & SDL_BUTTON_MASK(button)) != 0;
|
||||
}
|
||||
|
||||
float Input::getMouseX() {
|
||||
return mMouseX;
|
||||
}
|
||||
|
||||
float Input::getMouseY() {
|
||||
return mMouseY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user