mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Return std::optional<Event> from sf::WindowImpl::popEvent
This commit is contained in:
parent
bff2977f13
commit
1c873112ec
@ -159,30 +159,34 @@ bool WindowBase::isOpen() const
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::pollEvent(Event& event)
|
||||
{
|
||||
if (m_impl && m_impl->popEvent(event, false))
|
||||
if (!m_impl)
|
||||
return false;
|
||||
|
||||
if (const auto maybeEvent = m_impl->popEvent(false))
|
||||
{
|
||||
filterEvent(event);
|
||||
filterEvent(*maybeEvent);
|
||||
event = *maybeEvent;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::waitEvent(Event& event)
|
||||
{
|
||||
if (m_impl && m_impl->popEvent(event, true))
|
||||
if (!m_impl)
|
||||
return false;
|
||||
|
||||
if (const auto maybeEvent = m_impl->popEvent(true))
|
||||
{
|
||||
filterEvent(event);
|
||||
filterEvent(*maybeEvent);
|
||||
event = *maybeEvent;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,7 +171,7 @@ void WindowImpl::setMaximumSize(const std::optional<Vector2u>& maximumSize)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowImpl::popEvent(Event& event, bool block)
|
||||
std::optional<Event> WindowImpl::popEvent(bool block)
|
||||
{
|
||||
// If the event queue is empty, let's first check if new events are available from the OS
|
||||
if (m_events.empty())
|
||||
@ -200,13 +200,13 @@ bool WindowImpl::popEvent(Event& event, bool block)
|
||||
// Pop the first event of the queue, if it is not empty
|
||||
if (!m_events.empty())
|
||||
{
|
||||
event = m_events.front();
|
||||
const auto event = m_events.front();
|
||||
m_events.pop();
|
||||
|
||||
return true;
|
||||
return event;
|
||||
}
|
||||
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,7 +125,7 @@ public:
|
||||
/// \param block Use true to block the thread until an event arrives
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool popEvent(Event& event, bool block);
|
||||
std::optional<Event> popEvent(bool block);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OS-specific handle of the window
|
||||
|
Loading…
Reference in New Issue
Block a user