diff --git a/inferno/src/inferno/input.cpp b/inferno/src/inferno/input.cpp new file mode 100644 index 0000000..e07ee8f --- /dev/null +++ b/inferno/src/inferno/input.cpp @@ -0,0 +1,40 @@ +#include + +#include "inferno/application.h" +#include "inferno/input.h" +#include "inferno/window.h" + +namespace Inferno { + + bool Input::isKeyPressed(int key) + { + GLFWwindow* w = Application::get().getWindow().getWindow(); + return glfwGetKey(w, key) == GLFW_PRESS; + } + + bool Input::isMouseButtonPressed(int button) + { + GLFWwindow* w = Application::get().getWindow().getWindow(); + return glfwGetMouseButton(w, button) == GLFW_PRESS; + } + + std::pair Input::getMousePosition() + { + GLFWwindow* w = Application::get().getWindow().getWindow(); + double xPos; + double yPos; + glfwGetCursorPos(w, &xPos, &yPos); + return { (float)xPos, (float)yPos }; + } + + float Input::getMouseX() + { + return getMousePosition().first; + } + + float Input::getMouseY() + { + return getMousePosition().second; + } + +} diff --git a/inferno/src/inferno/input.h b/inferno/src/inferno/input.h new file mode 100644 index 0000000..2a132b1 --- /dev/null +++ b/inferno/src/inferno/input.h @@ -0,0 +1,20 @@ +#ifndef INPUT_H +#define INPUT_H + +#include + +namespace Inferno { + + class Input { + public: + static bool isKeyPressed(int key); + static bool isMouseButtonPressed(int button); + static std::pair getMousePosition(); + static float getMouseX(); + static float getMouseY(); + }; + +} + + +#endif // INPUT_H