MayaFlux 1.0.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 76 of file WindowEventSource.cpp.

77{
78 if (m_pending_events.empty())
79 return std::nullopt;
80
81 if (!filter.event_type && !filter.key_code && !filter.button) {
82 auto ev = m_pending_events.front();
83 m_pending_events.pop_front();
84 --m_pending_counts[static_cast<uint8_t>(ev.type)];
85 return ev;
86 }
87
88 std::deque<Core::WindowEvent> tmp;
89 std::optional<Core::WindowEvent> result;
90
91 while (!m_pending_events.empty()) {
92 auto ev = m_pending_events.front();
93 m_pending_events.pop_front();
94
95 bool matches = true;
96
97 if (filter.event_type && ev.type != *filter.event_type)
98 matches = false;
99
100 if (matches && filter.key_code) {
101 if (auto* kd = std::get_if<Core::WindowEvent::KeyData>(&ev.data)) {
102 matches = kd->key == static_cast<int16_t>(*filter.key_code);
103 } else {
104 matches = false;
105 }
106 }
107
108 if (matches && filter.button) {
109 if (auto* bd = std::get_if<Core::WindowEvent::MouseButtonData>(&ev.data)) {
110 matches = bd->button == static_cast<int>(*filter.button);
111 } else {
112 matches = false;
113 }
114 }
115
116 if (matches && !result) {
117 result = ev;
118 } else {
119 tmp.push_back(ev);
120 }
121 }
122
123 m_pending_events = std::move(tmp);
124 if (result)
125 --m_pending_counts[static_cast<uint8_t>(result->type)];
126 return result;
127}
std::deque< Core::WindowEvent > m_pending_events
std::array< size_t, 256 > m_pending_counts

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

Referenced by MayaFlux::Kriya::WindowEventAwaiter::await_ready().

+ Here is the caller graph for this function: