diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index 75f066bd8..af23be7f1 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -38,14 +38,14 @@ namespace Nz friend class Utility; public: - Window(); - Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default); - Window(WindowHandle handle); + inline Window(); + inline Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default); + inline Window(WindowHandle handle); Window(const Window&) = delete; - Window(Window&&) = delete; ///TODO + inline Window(Window&& window) noexcept; virtual ~Window(); - void Close(); + inline void Close(); bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default); bool Create(WindowHandle handle); @@ -66,9 +66,9 @@ namespace Nz bool HasFocus() const; bool IsMinimized() const; - bool IsOpen(bool checkClosed = true); - bool IsOpen() const; - bool IsValid() const; + inline bool IsOpen(bool checkClosed = true); + inline bool IsOpen() const; + inline bool IsValid() const; bool IsVisible() const; bool PollEvent(WindowEvent* event); @@ -93,7 +93,7 @@ namespace Nz bool WaitEvent(WindowEvent* event); Window& operator=(const Window&) = delete; - Window& operator=(Window&&) = delete; ///TODO + inline Window& operator=(Window&& window); protected: virtual bool OnWindowCreated(); @@ -104,7 +104,7 @@ namespace Nz private: void IgnoreNextMouseEvent(int mouseX, int mouseY) const; - void PushEvent(const WindowEvent& event); + inline void PushEvent(const WindowEvent& event); static bool Initialize(); static void Uninitialize(); @@ -122,4 +122,6 @@ namespace Nz }; } +#include + #endif // NAZARA_WINDOW_HPP diff --git a/include/Nazara/Utility/Window.inl b/include/Nazara/Utility/Window.inl new file mode 100644 index 000000000..ebf5dfbee --- /dev/null +++ b/include/Nazara/Utility/Window.inl @@ -0,0 +1,154 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +namespace Nz +{ + /*! + * \class Nz::Window + */ + + inline Window::Window() : + #if NAZARA_UTILITY_THREADED_WINDOW + m_impl(nullptr), + m_eventListener(true), + m_waitForEvent(false) + #else + m_impl(nullptr) + #endif + { + } + + inline Window::Window(VideoMode mode, const String& title, UInt32 style) : + #if NAZARA_UTILITY_THREADED_WINDOW + m_impl(nullptr), + m_eventListener(true), + m_waitForEvent(false) + #else + m_impl(nullptr) + #endif + { + ErrorFlags flags(ErrorFlag_ThrowException, true); + Create(mode, title, style); + } + + inline Window::Window(WindowHandle handle) : + #if NAZARA_UTILITY_THREADED_WINDOW + m_impl(nullptr), + m_eventListener(true), + m_waitForEvent(false) + #else + m_impl(nullptr) + #endif + { + ErrorFlags flags(ErrorFlag_ThrowException, true); + Create(handle); + } + + /*! + * \brief Constructs a Window object by moving another one + */ + inline Window::Window(Window&& window) noexcept : + m_impl(window.m_impl), + m_events(std::move(window.m_events)), + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventCondition(std::move(window.m_eventCondition)), + m_eventMutex(std::move(window.m_eventMutex)), + m_eventConditionMutex(std::move(window.m_eventConditionMutex)), + m_eventListener(window.m_eventListener), + m_waitForEvent(window.m_waitForEvent), + #endif + m_closed(window.m_closed), + m_ownsWindow(window.m_ownsWindow) + { + window.m_impl = nullptr; + } + + inline Window::~Window() + { + Destroy(); + } + + inline void Window::Close() + { + m_closed = true; // The window will be closed at the next non-const IsOpen() call + } + + inline bool Window::IsOpen(bool checkClosed) + { + if (!m_impl) + return false; + + if (checkClosed && m_closed) + { + Destroy(); + return false; + } + + return true; + } + + inline bool Window::IsOpen() const + { + return m_impl != nullptr; + } + + inline bool Window::IsValid() const + { + return m_impl != nullptr; + } + + inline void Window::PushEvent(const WindowEvent& event) + { + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventMutex.Lock(); + #endif + + m_events.push(event); + if (event.type == WindowEventType_Resized) + OnWindowResized(); + + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventMutex.Unlock(); + + if (m_waitForEvent) + { + m_eventConditionMutex.Lock(); + m_eventCondition.Signal(); + m_eventConditionMutex.Unlock(); + } + #endif + } + + /*! + * \brief Moves a window to another window object + * \return A reference to the object + */ + inline Window& Window::operator=(Window&& window) + { + Destroy(); + + m_closed = window.m_closed; + m_impl = window.m_impl; + m_events = std::move(window.m_events); + m_ownsWindow = window.m_ownsWindow; + + window.m_impl = nullptr; + + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventCondition = std::move(window.m_eventCondition); + m_eventMutex = std::move(window.m_eventMutex); + m_eventConditionMutex = std::move(window.m_eventConditionMutex); + m_eventListener = window.m_eventListener; + m_waitForEvent = window.m_waitForEvent; + #endif + + return *this; + } +} + +#include diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index fec1615af..e246144d2 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -28,53 +28,6 @@ namespace Nz Window* fullscreenWindow = nullptr; } - Window::Window() : - #if NAZARA_UTILITY_THREADED_WINDOW - m_impl(nullptr), - m_eventListener(true), - m_waitForEvent(false) - #else - m_impl(nullptr) - #endif - { - } - - Window::Window(VideoMode mode, const String& title, UInt32 style) : - #if NAZARA_UTILITY_THREADED_WINDOW - m_impl(nullptr), - m_eventListener(true), - m_waitForEvent(false) - #else - m_impl(nullptr) - #endif - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - Create(mode, title, style); - } - - Window::Window(WindowHandle handle) : - #if NAZARA_UTILITY_THREADED_WINDOW - m_impl(nullptr), - m_eventListener(true), - m_waitForEvent(false) - #else - m_impl(nullptr) - #endif - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - Create(handle); - } - - Window::~Window() - { - Destroy(); - } - - void Window::Close() - { - m_closed = true; // On retarde la fermeture jusqu'au prochain IsOpen - } - bool Window::Create(VideoMode mode, const String& title, UInt32 style) { // Si la fenêtre est déjà ouverte, nous conservons sa position @@ -317,27 +270,6 @@ namespace Nz return m_impl->HasFocus(); } - bool Window::IsOpen(bool checkClosed) - { - if (m_impl) - { - if (m_closed && checkClosed) - { - Destroy(); - return false; - } - else - return true; - } - else - return false; - } - - bool Window::IsOpen() const - { - return m_impl != nullptr; - } - bool Window::IsMinimized() const { #if NAZARA_UTILITY_SAFE @@ -351,11 +283,6 @@ namespace Nz return m_impl->IsMinimized(); } - bool Window::IsValid() const - { - return m_impl != nullptr; - } - bool Window::IsVisible() const { #if NAZARA_UTILITY_SAFE @@ -710,28 +637,6 @@ namespace Nz m_impl->IgnoreNextMouseEvent(mouseX, mouseY); } - void Window::PushEvent(const WindowEvent& event) - { - #if NAZARA_UTILITY_THREADED_WINDOW - m_eventMutex.Lock(); - #endif - - m_events.push(event); - if (event.type == WindowEventType_Resized) - OnWindowResized(); - - #if NAZARA_UTILITY_THREADED_WINDOW - m_eventMutex.Unlock(); - - if (m_waitForEvent) - { - m_eventConditionMutex.Lock(); - m_eventCondition.Signal(); - m_eventConditionMutex.Unlock(); - } - #endif - } - bool Window::Initialize() { return WindowImpl::Initialize();