Utility/Window: Make Window moveable
Former-commit-id: 8c780562acc61d15437ed21c16eed92b6dd97373
This commit is contained in:
parent
40e12ebffa
commit
36067e31c4
|
|
@ -38,14 +38,14 @@ namespace Nz
|
||||||
friend class Utility;
|
friend class Utility;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window();
|
inline Window();
|
||||||
Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
inline Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
||||||
Window(WindowHandle handle);
|
inline Window(WindowHandle handle);
|
||||||
Window(const Window&) = delete;
|
Window(const Window&) = delete;
|
||||||
Window(Window&&) = delete; ///TODO
|
inline Window(Window&& window) noexcept;
|
||||||
virtual ~Window();
|
virtual ~Window();
|
||||||
|
|
||||||
void Close();
|
inline void Close();
|
||||||
|
|
||||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
||||||
bool Create(WindowHandle handle);
|
bool Create(WindowHandle handle);
|
||||||
|
|
@ -66,9 +66,9 @@ namespace Nz
|
||||||
bool HasFocus() const;
|
bool HasFocus() const;
|
||||||
|
|
||||||
bool IsMinimized() const;
|
bool IsMinimized() const;
|
||||||
bool IsOpen(bool checkClosed = true);
|
inline bool IsOpen(bool checkClosed = true);
|
||||||
bool IsOpen() const;
|
inline bool IsOpen() const;
|
||||||
bool IsValid() const;
|
inline bool IsValid() const;
|
||||||
bool IsVisible() const;
|
bool IsVisible() const;
|
||||||
|
|
||||||
bool PollEvent(WindowEvent* event);
|
bool PollEvent(WindowEvent* event);
|
||||||
|
|
@ -93,7 +93,7 @@ namespace Nz
|
||||||
bool WaitEvent(WindowEvent* event);
|
bool WaitEvent(WindowEvent* event);
|
||||||
|
|
||||||
Window& operator=(const Window&) = delete;
|
Window& operator=(const Window&) = delete;
|
||||||
Window& operator=(Window&&) = delete; ///TODO
|
inline Window& operator=(Window&& window);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool OnWindowCreated();
|
virtual bool OnWindowCreated();
|
||||||
|
|
@ -104,7 +104,7 @@ namespace Nz
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
|
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
|
||||||
void PushEvent(const WindowEvent& event);
|
inline void PushEvent(const WindowEvent& event);
|
||||||
|
|
||||||
static bool Initialize();
|
static bool Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
|
|
@ -122,4 +122,6 @@ namespace Nz
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Utility/Window.inl>
|
||||||
|
|
||||||
#endif // NAZARA_WINDOW_HPP
|
#endif // NAZARA_WINDOW_HPP
|
||||||
|
|
|
||||||
|
|
@ -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 <Nazara/Utility/Window.hpp>
|
||||||
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
|
#include <Nazara/Utility/Debug.hpp>
|
||||||
|
|
||||||
|
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 <Nazara/Utility/DebugOff.hpp>
|
||||||
|
|
@ -28,53 +28,6 @@ namespace Nz
|
||||||
Window* fullscreenWindow = nullptr;
|
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)
|
bool Window::Create(VideoMode mode, const String& title, UInt32 style)
|
||||||
{
|
{
|
||||||
// Si la fenêtre est déjà ouverte, nous conservons sa position
|
// Si la fenêtre est déjà ouverte, nous conservons sa position
|
||||||
|
|
@ -317,27 +270,6 @@ namespace Nz
|
||||||
return m_impl->HasFocus();
|
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
|
bool Window::IsMinimized() const
|
||||||
{
|
{
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
|
@ -351,11 +283,6 @@ namespace Nz
|
||||||
return m_impl->IsMinimized();
|
return m_impl->IsMinimized();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::IsValid() const
|
|
||||||
{
|
|
||||||
return m_impl != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::IsVisible() const
|
bool Window::IsVisible() const
|
||||||
{
|
{
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
|
@ -710,28 +637,6 @@ namespace Nz
|
||||||
m_impl->IgnoreNextMouseEvent(mouseX, mouseY);
|
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()
|
bool Window::Initialize()
|
||||||
{
|
{
|
||||||
return WindowImpl::Initialize();
|
return WindowImpl::Initialize();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue