Add Input class

This commit is contained in:
Rick van Vonderen
2019-12-19 00:25:39 +01:00
parent 2275a6be3e
commit e80b186c4d
2 changed files with 60 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
#include <GLFW/glfw3.h>
#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<float, float> 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;
}
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef INPUT_H
#define INPUT_H
#include <utility>
namespace Inferno {
class Input {
public:
static bool isKeyPressed(int key);
static bool isMouseButtonPressed(int button);
static std::pair<float, float> getMousePosition();
static float getMouseX();
static float getMouseY();
};
}
#endif // INPUT_H