Deep Learning Visualizer
Interactive visualization of basic applications of deep learning
Loading...
Searching...
No Matches
event_bus.h
Go to the documentation of this file.
1#pragma once
2
6#include <Eigen/Core>
7#include <functional>
8#include <vector>
9
10namespace engine::input {
11
15class event_bus {
16public:
23 void emit(key key, action action) {
24 for (auto &func : key_callbacks_) {
25 func(key, action);
26 }
27 }
28
35 void emit(mouse mouse, action action) {
36 for (auto &func : mouse_callbacks_) {
37 func(mouse, action);
38 }
39 }
40
46 void emit(const Eigen::Vector2f &cursor_pos) {
47 for (auto &func : cursor_callbacks_) {
48 func(cursor_pos);
49 }
50 }
51
57 void subscribe(std::function<void(key, action)> func) {
58 key_callbacks_.push_back(func);
59 }
60
66 void subscribe(std::function<void(mouse, action)> func) {
67 mouse_callbacks_.push_back(func);
68 }
69
75 void subscribe(std::function<void(Eigen::Vector2f)> func) {
76 cursor_callbacks_.push_back(func);
77 }
78
79private:
80 std::vector<std::function<void(key, action)>> key_callbacks_;
81 std::vector<std::function<void(mouse, action)>> mouse_callbacks_;
82 std::vector<std::function<void(Eigen::Vector2f)>> cursor_callbacks_;
83};
84
85} // namespace engine::input
An event dispatcher for input events.
Definition event_bus.h:15
void emit(const Eigen::Vector2f &cursor_pos)
Informs all subscribers of a new cursor movement event.
Definition event_bus.h:46
void emit(key key, action action)
Informs all subscribers of a new keyboard event.
Definition event_bus.h:23
void subscribe(std::function< void(Eigen::Vector2f)> func)
Attaches a subscriber to new cursor movement events.
Definition event_bus.h:75
void emit(mouse mouse, action action)
Informs all subscribers of a new mouse button event.
Definition event_bus.h:35
void subscribe(std::function< void(key, action)> func)
Attaches a subscriber to new keyboard events.
Definition event_bus.h:57
void subscribe(std::function< void(mouse, action)> func)
Attaches a subscriber to new mouse button events.
Definition event_bus.h:66
Defines input event related enums.