53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
|
|
//
|
||
|
|
// Created by slinky on 5/3/26.
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifndef B_ENGINE_INPUTMANAGER_H
|
||
|
|
#define B_ENGINE_INPUTMANAGER_H
|
||
|
|
|
||
|
|
#include <functional>
|
||
|
|
#include <string>
|
||
|
|
#include <initializer_list>
|
||
|
|
#include <memory>
|
||
|
|
|
||
|
|
#include "GLFW/glfw3.h"
|
||
|
|
|
||
|
|
using MouseDeltaCallback = std::function<void(float, float)>;
|
||
|
|
|
||
|
|
enum KeyState {
|
||
|
|
KEY_PRESSED,
|
||
|
|
KEY_HELD,
|
||
|
|
KEY_DOWN,
|
||
|
|
KEY_RELEASED,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct InputRequirement {
|
||
|
|
int key;
|
||
|
|
KeyState state;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct InputAction {
|
||
|
|
std::vector<InputRequirement> requirements{};
|
||
|
|
};
|
||
|
|
|
||
|
|
class InputManager {
|
||
|
|
public:
|
||
|
|
static bool mouseInit;
|
||
|
|
static float lastMousePositionX;
|
||
|
|
static float lastMousePositionY;
|
||
|
|
|
||
|
|
static void mouse_pos_callback(GLFWwindow* window, double x, double y);
|
||
|
|
static void add_mouse_listener(MouseDeltaCallback callback);
|
||
|
|
|
||
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||
|
|
static void generate_input_action(std::string_view actionName, std::initializer_list<InputRequirement> requirements);
|
||
|
|
static bool check_action_performed(std::string_view actionName);
|
||
|
|
|
||
|
|
static bool key_pressed(int key);
|
||
|
|
static bool key_held(int key);
|
||
|
|
static bool key_released(int key);
|
||
|
|
static bool key_down(int key);
|
||
|
|
static bool key_up(int key);
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif //B_ENGINE_INPUTMANAGER_H
|