6#include <brenta/window.hpp>
7#include <brenta/input.hpp>
8#include <brenta/logger.hpp>
10using namespace brenta;
16std::unordered_map<int, std::function<void()>> input::keyboard_callbacks;
17std::unordered_map<std::string, std::function<void(
double,
double)>>
18 input::mouse_callbacks;
19const std::string input::subsystem_name =
"input";
20bool input::initialized =
false;
33 input::initialized =
true;
34 INFO(
"{} initialized", input::subsystem_name);
42 input::initialized =
false;
43 INFO(
"{}: terminated", input::subsystem_name);
49 return input::subsystem_name;
54 return input::initialized;
61input &input::instance()
69 input::keyboard_callbacks[key] = callback;
70 DEBUG(
"{}: aded callback for key: {}",
71 input::subsystem_name, std::to_string(key));
76 if (input::keyboard_callbacks.find(key) == input::keyboard_callbacks.end())
78 ERROR(
"{}: no callback found for key: {}", input::subsystem_name, key);
82 input::keyboard_callbacks.erase(key);
83 DEBUG(
"{}: removed callback for key: {}", input::subsystem_name, key);
87 [[maybe_unused]]
int key,
88 [[maybe_unused]]
int scancode,
int action,
89 [[maybe_unused]]
int mods)
91 if (action == GLFW_PRESS)
93 if (input::keyboard_callbacks.find(key) != input::keyboard_callbacks.end())
95 input::keyboard_callbacks.at(key)();
101 std::function<
void(
double,
double)> callback)
103 input::mouse_callbacks[callback_name] = callback;
104 DEBUG(
"{}: added callback for mouse: {}",
105 input::subsystem_name, callback_name);
110 if (input::mouse_callbacks.find(callback_name)
111 == input::mouse_callbacks.end())
113 ERROR(
"{}: no callback found for mouse: {}",
114 input::subsystem_name, callback_name);
118 input::mouse_callbacks.erase(callback_name);
119 DEBUG(
"{}: removed callback for mouse: {}",
120 input::subsystem_name, callback_name);
127 for (
auto &callback : input::mouse_callbacks)
129 callback.second(xpos, ypos);
139 return input::instance();