input.add_callback

This commit is contained in:
MihailRis
2024-05-05 06:49:17 +03:00
parent 92f6fd2226
commit ba885e4e08
7 changed files with 66 additions and 6 deletions
+2 -1
View File
@@ -85,6 +85,7 @@ void Events::pollEvents() {
if (!binding.state) {
binding.state = true;
binding.justChange = true;
binding.onactived.notify();
}
}
else {
@@ -105,7 +106,7 @@ void Events::bind(std::string name, inputtype type, mousecode code) {
}
void Events::bind(std::string name, inputtype type, int code) {
bindings[name] = { type, code, false, false };
bindings[name] = Binding(type, code);
}
bool Events::active(std::string name) {
+8 -2
View File
@@ -1,6 +1,8 @@
#ifndef WINDOW_INPUT_H_
#define WINDOW_INPUT_H_
#include "../util/RunnablesList.hpp"
#include <string>
/// @brief Represents glfw3 keycode values.
@@ -86,8 +88,6 @@ enum class keycode : int {
UNKNOWN = -1
};
/// @brief Represents glfw3 mouse button IDs.
/// @details There is a subset of glfw3 mouse button IDs.
enum class mousecode : int {
@@ -104,6 +104,7 @@ inline mousecode MOUSECODES_ALL[] {
namespace input_util {
void initialize();
keycode keycode_from(const std::string& name);
/// @return Key label by keycode
std::string to_string(keycode code);
@@ -117,10 +118,15 @@ enum class inputtype {
};
struct Binding {
util::RunnablesList onactived;
inputtype type;
int code;
bool state = false;
bool justChange = false;
Binding(){}
Binding(inputtype type, int code) : type(type), code(code) {}
bool active() const {
return state;