MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ pop_event()

std::optional< Core::WindowEvent > MayaFlux::Vruta::WindowEventSource::pop_event ( const WindowEventFilter filter)
private

Removes and returns the first pending event matching the filter.

Parameters
filterFilter criteria.

Definition at line 44 of file WindowEventSource.cpp.

45{
46 if (m_pending_events.empty())
47 return std::nullopt;
48
49 if (!filter.event_type && !filter.key_code && !filter.button) {
50 auto ev = m_pending_events.front();
51 m_pending_events.pop();
52 return ev;
53 }
54
55 std::queue<Core::WindowEvent> tmp;
56 std::optional<Core::WindowEvent> result;
57
58 while (!m_pending_events.empty()) {
59 auto ev = m_pending_events.front();
60 m_pending_events.pop();
61
62 bool matches = true;
63
64 if (filter.event_type && ev.type != *filter.event_type)
65 matches = false;
66
67 if (matches && filter.key_code) {
68 if (auto* kd = std::get_if<Core::WindowEvent::KeyData>(&ev.data)) {
69 matches = kd->key == static_cast<int16_t>(*filter.key_code);
70 } else {
71 matches = false;
72 }
73 }
74
75 if (matches && filter.button) {
76 if (auto* bd = std::get_if<Core::WindowEvent::MouseButtonData>(&ev.data)) {
77 matches = bd->button == static_cast<int>(*filter.button);
78 } else {
79 matches = false;
80 }
81 }
82
83 if (matches && !result) {
84 result = ev;
85 } else {
86 tmp.push(ev);
87 }
88 }
89
90 m_pending_events = std::move(tmp);
91 return result;
92}
std::queue< Core::WindowEvent > m_pending_events

References MayaFlux::Vruta::WindowEventFilter::button, MayaFlux::Vruta::WindowEventFilter::event_type, MayaFlux::Vruta::WindowEventFilter::key_code, and m_pending_events.

Referenced by MayaFlux::Kriya::WindowEventAwaiter::await_ready(), and MayaFlux::Kriya::WindowEventAwaiter::try_resume().

+ Here is the caller graph for this function: