diff options
author | tylermurphy534 <tylermurphy534@gmail.com> | 2022-09-25 12:13:07 -0400 |
---|---|---|
committer | tylermurphy534 <tylermurphy534@gmail.com> | 2022-09-25 12:13:07 -0400 |
commit | ffd2d8220d57587da9a73183f9aa1bdaff303f3f (patch) | |
tree | 32202311cfb74c2a2d522b7192480bed87b1cab8 /engine/xe_input.cpp | |
parent | vertex data no longer hard coded (diff) | |
parent | delete unused folder (diff) | |
download | minecraftvulkan-ffd2d8220d57587da9a73183f9aa1bdaff303f3f.tar.gz minecraftvulkan-ffd2d8220d57587da9a73183f9aa1bdaff303f3f.tar.bz2 minecraftvulkan-ffd2d8220d57587da9a73183f9aa1bdaff303f3f.zip |
merge in input
Diffstat (limited to 'engine/xe_input.cpp')
-rw-r--r-- | engine/xe_input.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/engine/xe_input.cpp b/engine/xe_input.cpp new file mode 100644 index 0000000..a764e0c --- /dev/null +++ b/engine/xe_input.cpp @@ -0,0 +1,46 @@ +#include "xe_input.hpp" + +#include <GLFW/glfw3.h> + +namespace xe { + +static Input* _instance; + +Input::Input(Window& window) : window{window} { + glfwSetKeyCallback(window.getGLFWwindow(), Input::key_callback); + glfwSetMouseButtonCallback(window.getGLFWwindow(), Input::mouse_callback); + _instance = this; +} + +bool Input::isKeyPressed(int key) { + return glfwGetKey(window.getGLFWwindow(), key) == GLFW_PRESS; +} + +bool Input::wasKeyPressed(int key) { + if(_pressed[key] == true) { + _pressed[key] = false; + return true; + } + return false; +} + +bool Input::wasKeyReleased(int key) { + if(_released[key] == true) { + _released[key] = false; + return true; + } + return false; +} + +void Input::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { + if(action == GLFW_PRESS) _instance->_pressed[key] = true; + if(action == GLFW_RELEASE) _instance->_released[key] = true; +} + +void Input::mouse_callback(GLFWwindow* window, int key, int action, int mods) { + if(action == GLFW_PRESS) _instance->_pressed[key] = true; + if(action == GLFW_RELEASE) _instance->_released[key] = true; +} + + +}
\ No newline at end of file |