52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "InputMap.hpp"
|
|
|
|
InputMap::InputMap(GLFWwindow* window): window(window) { }
|
|
InputMap::~InputMap() { }
|
|
|
|
void InputMap::saveKeys() {
|
|
for (auto input : Toggles) {
|
|
Previous.insert_or_assign(input, isDown(input));
|
|
}
|
|
PreviousLeft = isDown(Mouse::Left);
|
|
PreviousRight = isDown(Mouse::Right);
|
|
}
|
|
|
|
bool InputMap::isDown(Input input) const {
|
|
return glfwGetKey(window, Map.at(input)) == GLFW_PRESS;
|
|
}
|
|
bool InputMap::wasDown(Input input) const {
|
|
return Previous.at(input);
|
|
}
|
|
bool InputMap::isPressing(Input input) const {
|
|
return isDown(input) && !wasDown(input);
|
|
}
|
|
bool InputMap::isReleasing(Input input) const {
|
|
return !isDown(input) && wasDown(input);
|
|
}
|
|
|
|
void InputMap::toggle(bool &val, Input input) const {
|
|
if(isPressing(input))
|
|
val = !val;
|
|
}
|
|
|
|
bool InputMap::isDown(Mouse input) const {
|
|
return glfwGetMouseButton(window, static_cast<int>(input)) == GLFW_PRESS;
|
|
}
|
|
bool InputMap::wasDown(Mouse input) const {
|
|
switch (input) {
|
|
case Mouse::Left:
|
|
return PreviousLeft;
|
|
|
|
case Mouse::Right:
|
|
return PreviousRight;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
bool InputMap::isPressing(Mouse input) const {
|
|
return isDown(input) && !wasDown(input);
|
|
}
|
|
bool InputMap::isReleasing(Mouse input) const {
|
|
return !isDown(input) && wasDown(input);
|
|
} |