Skip to content

Commit

Permalink
Utility/Window: Window now automatically close on quit event
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Aug 27, 2016
1 parent 08fd05d commit 2e67a96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/Nazara/Utility/Window.hpp
Expand Up @@ -52,6 +52,7 @@ namespace Nz

void Destroy();

inline void EnableCloseOnQuit(bool closeOnQuit);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system") inline void EnableEventPolling(bool enable);
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
Expand Down Expand Up @@ -122,6 +123,7 @@ namespace Nz
#endif
EventHandler m_eventHandler;
bool m_closed;
bool m_closeOnQuit;
bool m_eventPolling;
bool m_ownsWindow;
};
Expand Down
13 changes: 12 additions & 1 deletion include/Nazara/Utility/Window.inl
Expand Up @@ -16,6 +16,7 @@ namespace Nz
#if NAZARA_UTILITY_THREADED_WINDOW
m_waitForEvent(false),
#endif
m_closeOnQuit(true),
m_eventPolling(false)
{
}
Expand Down Expand Up @@ -44,10 +45,11 @@ namespace Nz
m_eventCondition(std::move(window.m_eventCondition)),
m_eventMutex(std::move(window.m_eventMutex)),
m_eventConditionMutex(std::move(window.m_eventConditionMutex)),
m_eventPolling(window.m_eventPolling),
m_waitForEvent(window.m_waitForEvent),
#endif
m_closed(window.m_closed),
m_closeOnQuit(window.m_closeOnQuit),
m_eventPolling(window.m_eventPolling),
m_ownsWindow(window.m_ownsWindow)
{
window.m_impl = nullptr;
Expand All @@ -63,6 +65,11 @@ namespace Nz
m_closed = true; // The window will be closed at the next non-const IsOpen() call
}

inline void Window::EnableCloseOnQuit(bool closeOnQuit)
{
m_closeOnQuit = closeOnQuit;
}

inline void Window::EnableEventPolling(bool enable)
{
m_eventPolling = enable;
Expand Down Expand Up @@ -116,6 +123,9 @@ namespace Nz
if (event.type == WindowEventType_Resized)
OnWindowResized();

if (event.type == WindowEventType_Quit && m_closeOnQuit)
Close();

#if NAZARA_UTILITY_THREADED_WINDOW
m_eventMutex.Unlock();

Expand All @@ -137,6 +147,7 @@ namespace Nz
Destroy();

m_closed = window.m_closed;
m_closeOnQuit = window.m_closeOnQuit;
m_eventPolling = window.m_eventPolling;
m_impl = window.m_impl;
m_events = std::move(window.m_events);
Expand Down

0 comments on commit 2e67a96

Please sign in to comment.