Browse Source

Add Input class

master
Rick van Vonderen 5 years ago
parent
commit
e80b186c4d
  1. 40
      inferno/src/inferno/input.cpp
  2. 20
      inferno/src/inferno/input.h

40
inferno/src/inferno/input.cpp

@ -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
inferno/src/inferno/input.h

@ -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
Loading…
Cancel
Save