MayaFlux 1.0.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(uint32_t)> 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* text_data = std::get_if<Core::WindowEvent::TextData>(&event.data)) {
97 callback(text_data->codepoint);
98 }
99 }
100}
101
103 std::shared_ptr<Core::Window> window,
104 std::function<void(IO::Keys)> callback)
105{
106 auto& promise = co_await GetEventPromise {};
107 auto& source = window->get_event_source();
108
111
112 while (true) {
113 if (promise.should_terminate) {
114 break;
115 }
116
117 auto event = co_await WindowEventAwaiter(source, filter);
118
119 if (auto* key_data = std::get_if<Core::WindowEvent::KeyData>(&event.data)) {
120 callback(static_cast<IO::Keys>(key_data->key));
121 }
122 }
123}
124
126 std::shared_ptr<Core::Window> window,
127 IO::MouseButtons button,
128 std::function<void(double, double)> callback)
129{
130 auto& promise = co_await GetEventPromise {};
131 auto& source = window->get_event_source();
132
135 filter.button = button;
136
137 while (true) {
138 if (promise.should_terminate) {
139 break;
140 }
141
142 co_await WindowEventAwaiter(source, filter);
143
144 auto [x, y] = source.get_mouse_position();
145 callback(x, y);
146 }
147}
148
150 std::shared_ptr<Core::Window> window,
151 IO::MouseButtons button,
152 std::function<void(double, double)> callback)
153{
154 auto& promise = co_await GetEventPromise {};
155 auto& source = window->get_event_source();
156
159 filter.button = button;
160
161 while (true) {
162 if (promise.should_terminate) {
163 break;
164 }
165
166 co_await WindowEventAwaiter(source, filter);
167
168 auto [x, y] = source.get_mouse_position();
169 callback(x, y);
170 }
171}
172
174 std::shared_ptr<Core::Window> window,
175 std::function<void(double, double)> callback)
176{
177 auto& promise = co_await GetEventPromise {};
178 auto& source = window->get_event_source();
179
182
183 while (true) {
184 if (promise.should_terminate) {
185 break;
186 }
187
188 auto event = co_await WindowEventAwaiter(source, filter);
189
190 if (auto* pos_data = std::get_if<Core::WindowEvent::MousePosData>(&event.data)) {
191 callback(pos_data->x, pos_data->y);
192 }
193 }
194}
195
197 std::shared_ptr<Core::Window> window,
198 IO::MouseButtons button,
199 std::function<void(double, double)> callback)
200{
201 auto& promise = co_await GetEventPromise {};
202 auto& source = window->get_event_source();
203
206
207 while (true) {
208 if (promise.should_terminate)
209 break;
210
211 auto event = co_await WindowEventAwaiter(source, filter);
212
213 if (!source.is_mouse_pressed(static_cast<int>(button)))
214 continue;
215
216 if (auto* pos = std::get_if<Core::WindowEvent::MousePosData>(&event.data))
217 callback(pos->x, pos->y);
218 }
219}
220
222 std::shared_ptr<Core::Window> window,
223 std::function<void(double, double)> callback)
224{
225 auto& promise = co_await GetEventPromise {};
226 auto& source = window->get_event_source();
227
230
231 while (true) {
232 if (promise.should_terminate) {
233 break;
234 }
235
236 auto event = co_await WindowEventAwaiter(source, filter);
237
238 if (auto* scroll_data = std::get_if<Core::WindowEvent::ScrollData>(&event.data)) {
239 callback(scroll_data->x_offset, scroll_data->y_offset);
240 }
241 }
242}
243
245 std::shared_ptr<Core::Window> window,
246 std::function<void(uint32_t, uint32_t)> callback)
247{
248 auto& promise = co_await GetEventPromise {};
249 auto& source = window->get_event_source();
250
253
254 while (true) {
255 if (promise.should_terminate) {
256 break;
257 }
258
259 auto event = co_await WindowEventAwaiter(source, filter);
260
261 if (auto* resize_data = std::get_if<Core::WindowEvent::ResizeData>(&event.data)) {
262 callback(resize_data->width, resize_data->height);
263 }
264 }
265}
266
268 std::shared_ptr<Core::Window> window,
269 std::function<void()> callback)
270{
271 auto& promise = co_await GetEventPromise {};
272 auto& source = window->get_event_source();
273
276
277 while (true) {
278 if (promise.should_terminate)
279 break;
280
281 co_await WindowEventAwaiter(source, filter);
282 callback();
283 }
284}
285
286} // namespace MayaFlux::Kriya
PickCallback callback
Definition Picker.cpp:22
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
Awaiter for suspending on 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 window_closed(std::shared_ptr< Core::Window > window, std::function< void()> callback)
Creates an Event coroutine that triggers on window close.
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 window_resized(std::shared_ptr< Core::Window > window, std::function< void(uint32_t, uint32_t)> callback)
Creates an Event coroutine that triggers on window resize.
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.
Vruta::Event text_input(std::shared_ptr< Core::Window > window, std::function< void(uint32_t)> callback)
Creates an Event coroutine that triggers on resolved text input.
Event-domain promise accessor with optional NetworkSource ownership transfer.
std::optional< Core::WindowEventType > event_type
std::optional< IO::MouseButtons > button
Filter criteria for window input events.