summaryrefslogtreecommitdiff
path: root/engine/xe_input.cpp
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-09-23 13:20:30 -0400
committerTyler Murphy <tylermurphy534@gmail.com>2022-09-23 13:20:30 -0400
commit9b7d14361904a9c2bceb8de335fd5da169fabd59 (patch)
tree231348855310530145f8ce4bb35931d36bd74438 /engine/xe_input.cpp
parentdelete old files (diff)
downloadminecraftvulkan-9b7d14361904a9c2bceb8de335fd5da169fabd59.tar.gz
minecraftvulkan-9b7d14361904a9c2bceb8de335fd5da169fabd59.tar.bz2
minecraftvulkan-9b7d14361904a9c2bceb8de335fd5da169fabd59.zip
abstract user input, refactor #include's
Diffstat (limited to 'engine/xe_input.cpp')
-rw-r--r--engine/xe_input.cpp46
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..91b9cab
--- /dev/null
+++ b/engine/xe_input.cpp
@@ -0,0 +1,46 @@
+#include "xe_input.hpp"
+
+#include <GLFW/glfw3.h>
+
+namespace xe {
+
+static XeInput* _instance;
+
+XeInput::XeInput(XeWindow& window) : window{window} {
+ glfwSetKeyCallback(window.getGLFWwindow(), XeInput::key_callback);
+ glfwSetMouseButtonCallback(window.getGLFWwindow(), XeInput::mouse_callback);
+ _instance = this;
+}
+
+bool XeInput::isKeyPressed(int key) {
+ return glfwGetKey(window.getGLFWwindow(), key) == GLFW_PRESS;
+}
+
+bool XeInput::wasKeyPressed(int key) {
+ if(_pressed[key] == true) {
+ _pressed[key] = false;
+ return true;
+ }
+ return false;
+}
+
+bool XeInput::wasKeyReleased(int key) {
+ if(_released[key] == true) {
+ _released[key] = false;
+ return true;
+ }
+ return false;
+}
+
+void XeInput::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 XeInput::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