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

◆ pop_event()

std::optional< Core::WindowEvent > MayaFlux::Vruta::EventSource::pop_event ( const EventFilter filter)
private

Pop event matching filter from queue.

Parameters
filterFilter criteria
Returns
Event if found, nullopt otherwise

Searches the queue for an event matching all filter criteria. Removes and returns the first matching event, preserving order of non-matching events.

Definition at line 59 of file EventSource.cpp.

60{
61 if (m_pending_events.empty()) {
62 return std::nullopt;
63 }
64
65 if (!filter.event_type && !filter.key_code && !filter.button) {
66 auto event = m_pending_events.front();
67 m_pending_events.pop();
68 return event;
69 }
70
71 std::queue<Core::WindowEvent> temp_queue;
72 std::optional<Core::WindowEvent> result;
73
74 while (!m_pending_events.empty()) {
75 auto event = m_pending_events.front();
76 m_pending_events.pop();
77
78 bool matches = true;
79
80 if (filter.event_type && event.type != *filter.event_type) {
81 matches = false;
82 }
83
84 if (matches && filter.key_code) {
85 auto key_code = static_cast<int16_t>(*filter.key_code);
86 if (auto key_data = std::get_if<Core::WindowEvent::KeyData>(&event.data)) {
87 if (key_data->key != key_code) {
88 matches = false;
89 }
90 } else {
91 matches = false;
92 }
93 }
94
95 if (matches && filter.button) {
96 auto button_code = static_cast<int>(*filter.button);
97 if (auto* button_data = std::get_if<Core::WindowEvent::MouseButtonData>(&event.data)) {
98 if (button_data->button != button_code) {
99 matches = false;
100 }
101 } else {
102 matches = false;
103 }
104 }
105
106 if (matches && !result) {
107 result = event;
108 } else {
109 temp_queue.push(event);
110 }
111 }
112
113 m_pending_events = std::move(temp_queue);
114 return result;
115}
std::queue< Core::WindowEvent > m_pending_events

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

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

+ Here is the caller graph for this function: