MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InputEvents.cpp
Go to the documentation of this file.
1#include "InputEvents.hpp"
2
7
8namespace MayaFlux::Kriya {
9
11 std::shared_ptr<Core::Window> window,
12 IO::Keys key,
13 std::function<void()> callback)
14{
15 auto& promise = co_await GetEventPromise {};
16 auto& source = window->get_event_source();
17
20 filter.key_code = key;
21
22 while (true) {
23 if (promise.should_terminate) {
24 break;
25 }
26
27 co_await WindowEventAwaiter(source, filter);
28 callback();
29 }
30}
31
33 std::shared_ptr<Core::Window> window,
34 IO::Keys key,
35 std::function<void()> callback)
36{
37 auto& promise = co_await GetEventPromise {};
38 auto& source = window->get_event_source();
39
42 filter.key_code = key;
43
44 while (true) {
45 if (promise.should_terminate) {
46 break;
47 }
48
49 co_await WindowEventAwaiter(source, filter);
50 callback();
51 }
52}
53
55 std::shared_ptr<Core::Window> window,
56 IO::Keys key,
57 std::function<void()> callback)
58{
59 auto& promise = co_await GetEventPromise {};
60 auto& source = window->get_event_source();
61
63 filter.key_code = key;
64
65 while (true) {
66 if (promise.should_terminate)
67 break;
68
69 auto ev = co_await WindowEventAwaiter(source, filter);
70
72 continue;
73 }
74
75 callback();
76 }
77}
78
80 std::shared_ptr<Core::Window> window,
81 std::function<void(IO::Keys)> callback)
82{
83 auto& promise = co_await GetEventPromise {};
84 auto& source = window->get_event_source();
85
88
89 while (true) {
90 if (promise.should_terminate) {
91 break;
92 }
93
94 auto event = co_await WindowEventAwaiter(source, filter);
95
96 if (auto* key_data = std::get_if<Core::WindowEvent::KeyData>(&event.data)) {
97 callback(static_cast<IO::Keys>(key_data->key));
98 }
99 }
100}
101
103 std::shared_ptr<Core::Window> window,
104 IO::MouseButtons button,
105 std::function<void(double, double)> callback)
106{
107 auto& promise = co_await GetEventPromise {};
108 auto& source = window->get_event_source();
109
112 filter.button = button;
113
114 while (true) {
115 if (promise.should_terminate) {
116 break;
117 }
118
119 co_await WindowEventAwaiter(source, filter);
120
121 auto [x, y] = source.get_mouse_position();
122 callback(x, y);
123 }
124}
125
127 std::shared_ptr<Core::Window> window,
128 IO::MouseButtons button,
129 std::function<void(double, double)> callback)
130{
131 auto& promise = co_await GetEventPromise {};
132 auto& source = window->get_event_source();
133
136 filter.button = button;
137
138 while (true) {
139 if (promise.should_terminate) {
140 break;
141 }
142
143 co_await WindowEventAwaiter(source, filter);
144
145 auto [x, y] = source.get_mouse_position();
146 callback(x, y);
147 }
148}
149
151 std::shared_ptr<Core::Window> window,
152 std::function<void(double, double)> callback)
153{
154 auto& promise = co_await GetEventPromise {};
155 auto& source = window->get_event_source();
156
159
160 while (true) {
161 if (promise.should_terminate) {
162 break;
163 }
164
165 auto event = co_await WindowEventAwaiter(source, filter);
166
167 if (auto* pos_data = std::get_if<Core::WindowEvent::MousePosData>(&event.data)) {
168 callback(pos_data->x, pos_data->y);
169 }
170 }
171}
172
174 std::shared_ptr<Core::Window> window,
175 IO::MouseButtons button,
176 std::function<void(double, double)> callback)
177{
178 auto& promise = co_await GetEventPromise {};
179 auto& source = window->get_event_source();
180
183
184 while (true) {
185 if (promise.should_terminate)
186 break;
187
188 auto event = co_await WindowEventAwaiter(source, filter);
189
190 if (!source.is_mouse_pressed(static_cast<int>(button)))
191 continue;
192
193 if (auto* pos = std::get_if<Core::WindowEvent::MousePosData>(&event.data))
194 callback(pos->x, pos->y);
195 }
196}
197
199 std::shared_ptr<Core::Window> window,
200 std::function<void(double, double)> callback)
201{
202 auto& promise = co_await GetEventPromise {};
203 auto& source = window->get_event_source();
204
207
208 while (true) {
209 if (promise.should_terminate) {
210 break;
211 }
212
213 auto event = co_await WindowEventAwaiter(source, filter);
214
215 if (auto* scroll_data = std::get_if<Core::WindowEvent::ScrollData>(&event.data)) {
216 callback(scroll_data->x_offset, scroll_data->y_offset);
217 }
218 }
219}
220
221} // namespace MayaFlux::Kriya
Awaiter for suspending on GLFW window input events with optional filtering.
Coroutine type for event-driven suspension.
Definition Event.hpp:26
MouseButtons
Enumeration for mouse buttons.
Definition Keys.hpp:147
Vruta::Event key_released(std::shared_ptr< Core::Window > window, IO::Keys key, std::function< void()> callback)
Creates an Event coroutine that triggers on specific key release.
Vruta::Event any_key(std::shared_ptr< Core::Window > window, std::function< void(IO::Keys)> callback)
Creates an Event coroutine that triggers on any key press.
Vruta::Event key_pressed(std::shared_ptr< Core::Window > window, IO::Keys key, std::function< void()> callback)
Creates an Event coroutine that triggers on specific key press.
Vruta::Event mouse_moved(std::shared_ptr< Core::Window > window, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on mouse movement.
Vruta::Event mouse_scrolled(std::shared_ptr< Core::Window > window, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on mouse scroll.
Vruta::Event key_held(std::shared_ptr< Core::Window > window, IO::Keys key, std::function< void()> callback)
Creates an Event coroutine that triggers on key press and repeats while held.
Vruta::Event mouse_released(std::shared_ptr< Core::Window > window, IO::MouseButtons button, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on specific mouse button release.
Vruta::Event mouse_pressed(std::shared_ptr< Core::Window > window, IO::MouseButtons button, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on specific mouse button press.
Vruta::Event mouse_dragged(std::shared_ptr< Core::Window > window, IO::MouseButtons button, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on mouse drag with specific button.
Event-domain promise accessor with optional NetworkSource ownership transfer.
std::optional< Core::WindowEventType > event_type
std::optional< IO::MouseButtons > button
Filter criteria for GLFW window input events.