Added simple glfw input callbacks
This commit is contained in:
parent
7b9685c381
commit
4df6cfba90
@ -12,6 +12,13 @@ namespace BarinkEngine {
|
|||||||
void PollEvents();
|
void PollEvents();
|
||||||
void attach(BarinkWindow* window);
|
void attach(BarinkWindow* window);
|
||||||
|
|
||||||
|
|
||||||
|
// GLFW Handlers
|
||||||
|
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
|
static void CursorPositionCallback(GLFWwindow* window, double x, double y);
|
||||||
|
static void CursorEnterCallback(GLFWwindow* window, int entered);
|
||||||
|
static void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||||
|
static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
private:
|
private:
|
||||||
std::vector<BarinkWindow*> windows;
|
std::vector<BarinkWindow*> windows;
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "Input/InputManager.h"
|
#include "Input/InputManager.h"
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include <iostream>
|
||||||
void BarinkEngine::InputManager::PollEvents()
|
void BarinkEngine::InputManager::PollEvents()
|
||||||
{
|
{
|
||||||
for (std::vector<BarinkWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
|
for (std::vector<BarinkWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
|
||||||
@ -7,9 +9,61 @@ void BarinkEngine::InputManager::PollEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::cout << "'a' key was pressed" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
|
||||||
|
{
|
||||||
|
std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
||||||
|
{
|
||||||
|
if (entered) {
|
||||||
|
// Cursor entered the window's screen space
|
||||||
|
std::cout << "Cursor entered!" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "Cursor left!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||||
|
{
|
||||||
|
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
||||||
|
std::cout << "Right mouse button was pressed!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
|
{
|
||||||
|
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
||||||
{
|
{
|
||||||
|
|
||||||
windows.push_back(window);
|
windows.push_back(window);
|
||||||
|
|
||||||
|
// Attach callbacks
|
||||||
|
glfwSetKeyCallback(window->windowptr(), KeyCallback);
|
||||||
|
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
|
||||||
|
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
|
||||||
|
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
|
||||||
|
glfwSetScrollCallback(window->windowptr(), ScrollCallback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BarinkEngine::InputManager::InputManager()
|
BarinkEngine::InputManager::InputManager()
|
||||||
|
Loading…
Reference in New Issue
Block a user