mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
feat: key pressed event interception & 'owner' input.add_callback third argument
This commit is contained in:
parent
7fce735ca1
commit
b9ff1db086
17 changed files with 192 additions and 63 deletions
|
|
@ -23,7 +23,7 @@ bool Events::_cursor_locked = false;
|
|||
std::vector<uint> Events::codepoints;
|
||||
std::vector<keycode> Events::pressedKeys;
|
||||
std::unordered_map<std::string, Binding> Events::bindings;
|
||||
std::unordered_map<keycode, util::RunnablesList> Events::keyCallbacks;
|
||||
std::unordered_map<keycode, util::HandlersList<>> Events::keyCallbacks;
|
||||
|
||||
bool Events::pressed(keycode keycode) {
|
||||
return pressed(static_cast<int>(keycode));
|
||||
|
|
@ -180,7 +180,7 @@ void Events::setPosition(float xpos, float ypos) {
|
|||
Events::cursor.y = ypos;
|
||||
}
|
||||
|
||||
observer_handler Events::addKeyCallback(keycode key, runnable callback) {
|
||||
observer_handler Events::addKeyCallback(keycode key, KeyCallback callback) {
|
||||
return keyCallbacks[key].add(std::move(callback));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ class Events {
|
|||
static uint currentFrame;
|
||||
static bool cursor_drag;
|
||||
public:
|
||||
using KeyCallback = std::function<bool()>;
|
||||
|
||||
static int scroll;
|
||||
static glm::vec2 delta;
|
||||
static glm::vec2 cursor;
|
||||
|
|
@ -27,7 +29,7 @@ public:
|
|||
static std::vector<uint> codepoints;
|
||||
static std::vector<keycode> pressedKeys;
|
||||
static std::unordered_map<std::string, Binding> bindings;
|
||||
static std::unordered_map<keycode, util::RunnablesList> keyCallbacks;
|
||||
static std::unordered_map<keycode, util::HandlersList<>> keyCallbacks;
|
||||
|
||||
static void pollEvents();
|
||||
|
||||
|
|
@ -51,7 +53,7 @@ public:
|
|||
static bool active(const std::string& name);
|
||||
static bool jactive(const std::string& name);
|
||||
|
||||
static observer_handler addKeyCallback(keycode key, runnable callback);
|
||||
static observer_handler addKeyCallback(keycode key, KeyCallback callback);
|
||||
|
||||
static void setKey(int key, bool b);
|
||||
static void setButton(int button, bool b);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "util/RunnablesList.hpp"
|
||||
#include "util/HandlersList.hpp"
|
||||
|
||||
/// @brief Represents glfw3 keycode values.
|
||||
enum class keycode : int {
|
||||
|
|
@ -131,7 +131,7 @@ enum class inputtype {
|
|||
};
|
||||
|
||||
struct Binding {
|
||||
util::RunnablesList onactived;
|
||||
util::HandlersList<> onactived;
|
||||
|
||||
inputtype type;
|
||||
int code;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue