Upgrade Platform

This commit is contained in:
Jérôme Leclercq
2021-05-24 21:06:55 +02:00
parent 8b0b5295f7
commit ba7c56ddfa
20 changed files with 322 additions and 389 deletions

View File

@@ -8,7 +8,6 @@
#define NAZARA_CURSOR_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Enums.hpp>
@@ -19,51 +18,42 @@ namespace Nz
{
class CursorImpl;
class Cursor;
using CursorConstRef = ObjectRef<const Cursor>;
using CursorRef = ObjectRef<Cursor>;
class NAZARA_PLATFORM_API Cursor : public RefCounted
class NAZARA_PLATFORM_API Cursor
{
friend class Platform;
friend class WindowImpl;
public:
inline Cursor();
inline Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
Cursor();
Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
Cursor(const Cursor&) = delete;
Cursor(Cursor&&) = delete;
inline ~Cursor();
Cursor(Cursor&&) noexcept;
~Cursor();
bool Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
void Destroy();
inline const Image& GetImage() const;
inline SystemCursor GetSystemCursor() const;
inline bool IsValid() const;
Cursor& operator=(const Cursor&) = delete;
Cursor& operator=(Cursor&&) = delete;
Cursor& operator=(Cursor&&) noexcept;
static inline Cursor* Get(SystemCursor cursor);
template<typename... Args> static CursorRef New(Args&&... args);
static inline std::shared_ptr<Cursor>& Get(SystemCursor cursor);
private:
inline explicit Cursor(SystemCursor systemCursor);
explicit Cursor(SystemCursor systemCursor);
bool Create(SystemCursor cursor);
static bool Initialize();
static void Uninitialize();
Image m_cursorImage;
SystemCursor m_systemCursor;
CursorImpl* m_impl;
std::unique_ptr<CursorImpl> m_impl;
static std::array<Cursor, SystemCursor_Max + 1> s_systemCursors;
static std::array<std::shared_ptr<Cursor>, SystemCursorCount> s_systemCursors;
};
}

View File

@@ -2,47 +2,11 @@
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
inline Cursor::Cursor() :
m_impl(nullptr)
{
}
inline Cursor::Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(cursor, hotSpot, placeholder);
}
inline Cursor* Cursor::Get(SystemCursor cursor)
{
return &s_systemCursors[cursor];
}
inline Cursor::Cursor(SystemCursor systemCursor) :
Cursor()
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(systemCursor);
}
inline Cursor::~Cursor()
{
Destroy();
}
inline const Image& Cursor::GetImage() const
{
NazaraAssert(IsValid(), "Invalid cursor");
NazaraAssert(m_cursorImage.IsValid(), "System cursors have no image");
return m_cursorImage;
}
inline SystemCursor Cursor::GetSystemCursor() const
{
NazaraAssert(IsValid(), "Invalid cursor");
@@ -55,13 +19,9 @@ namespace Nz
return m_impl != nullptr;
}
template<typename... Args>
CursorRef Cursor::New(Args&&... args)
inline std::shared_ptr<Cursor>& Cursor::Get(SystemCursor cursor)
{
std::unique_ptr<Cursor> object(new Cursor(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
return s_systemCursors[UnderlyingCast(cursor)];
}
}

View File

@@ -28,12 +28,12 @@ namespace Nz
CursorController(CursorController&&) noexcept = default;
~CursorController() = default;
inline void UpdateCursor(const CursorRef& cursor);
inline void UpdateCursor(const std::shared_ptr<Cursor>& cursor);
CursorController& operator=(const CursorController&) = delete;
CursorController& operator=(CursorController&&) noexcept = default;
NazaraSignal(OnCursorUpdated, const CursorController* /*cursorController*/, const CursorRef& /*cursor*/);
NazaraSignal(OnCursorUpdated, const CursorController* /*cursorController*/, const std::shared_ptr<Cursor>& /*cursor*/);
};
}

View File

@@ -7,7 +7,7 @@
namespace Nz
{
inline void CursorController::UpdateCursor(const CursorRef& cursor)
inline void CursorController::UpdateCursor(const std::shared_ptr<Cursor>& cursor)
{
OnCursorUpdated(this, cursor);
}

View File

@@ -11,75 +11,81 @@
namespace Nz
{
enum SystemCursor
enum class SystemCursor
{
SystemCursor_Crosshair,
SystemCursor_Default,
SystemCursor_Hand,
SystemCursor_Help,
SystemCursor_Move,
SystemCursor_None,
SystemCursor_Pointer,
SystemCursor_Progress,
SystemCursor_ResizeE,
SystemCursor_ResizeN,
SystemCursor_ResizeNE,
SystemCursor_ResizeNW,
SystemCursor_ResizeS,
SystemCursor_ResizeSE,
SystemCursor_ResizeSW,
SystemCursor_ResizeW,
SystemCursor_Text,
SystemCursor_Wait,
Crosshair,
Default,
Hand,
Help,
Move,
None,
Pointer,
Progress,
ResizeE,
ResizeN,
ResizeNE,
ResizeNW,
ResizeS,
ResizeSE,
ResizeSW,
ResizeW,
Text,
Wait,
SystemCursor_Max = SystemCursor_Wait
Max = Wait
};
enum WindowEventType
{
WindowEventType_GainedFocus,
WindowEventType_LostFocus,
WindowEventType_KeyPressed,
WindowEventType_KeyReleased,
WindowEventType_MouseButtonDoubleClicked,
WindowEventType_MouseButtonPressed,
WindowEventType_MouseButtonReleased,
WindowEventType_MouseEntered,
WindowEventType_MouseLeft,
WindowEventType_MouseMoved,
WindowEventType_MouseWheelMoved,
WindowEventType_Moved,
WindowEventType_Quit,
WindowEventType_Resized,
WindowEventType_TextEdited,
WindowEventType_TextEntered,
constexpr std::size_t SystemCursorCount = static_cast<std::size_t>(SystemCursor::Max) + 1;
WindowEventType_Max = WindowEventType_TextEntered
enum class WindowEventType
{
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
MouseButtonDoubleClicked,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
MouseLeft,
MouseMoved,
MouseWheelMoved,
Moved,
Quit,
Resized,
TextEdited,
TextEntered,
Max = TextEntered
};
enum WindowStyle
constexpr std::size_t WindowEventTypeCount = static_cast<std::size_t>(WindowEventType::Max) + 1;
enum class WindowStyle
{
WindowStyle_None, ///< Window has no border nor titlebar.
WindowStyle_Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
None, ///< Window has no border nor titlebar.
Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
WindowStyle_Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
WindowStyle_Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
WindowStyle_Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
WindowStyle_Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
WindowStyle_Max = WindowStyle_Threaded
Max = Threaded
};
constexpr std::size_t WindowStyleCount = static_cast<std::size_t>(WindowStyle::Max) + 1;
template<>
struct EnumAsFlags<WindowStyle>
{
static constexpr WindowStyle max = WindowStyle_Max;
static constexpr WindowStyle max = WindowStyle::Max;
};
using WindowStyleFlags = Flags<WindowStyle>;
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar;
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle::Closable | WindowStyle::Resizable | WindowStyle::Titlebar;
}
#endif // NAZARA_ENUMS_PLATFORM_HPP

View File

@@ -20,8 +20,8 @@ namespace Nz
struct WindowEvent
{
// Used by:
// -WindowEventType_KeyPressed
// -WindowEventType_KeyReleased
// -WindowEventType::KeyPressed
// -WindowEventType::KeyReleased
struct KeyEvent
{
Keyboard::Scancode scancode;
@@ -34,8 +34,8 @@ namespace Nz
};
// Used by:
// -WindowEventType_MouseButtonDoubleClicked
// -WindowEventType_MouseButtonPressed
// -WindowEventType::MouseButtonDoubleClicked
// -WindowEventType::MouseButtonPressed
struct MouseButtonEvent
{
Mouse::Button button;
@@ -44,7 +44,7 @@ namespace Nz
};
// Used by:
// -WindowEventType_MouseMoved
// -WindowEventType::MouseMoved
struct MouseMoveEvent
{
int deltaX;
@@ -54,7 +54,7 @@ namespace Nz
};
// Used by:
// -WindowEventType_MouseWheelMoved
// -WindowEventType::MouseWheelMoved
struct MouseWheelEvent
{
float delta;
@@ -63,7 +63,7 @@ namespace Nz
};
// Used by:
// -WindowEventType_Moved
// -WindowEventType::Moved
struct PositionEvent
{
int x;
@@ -71,7 +71,7 @@ namespace Nz
};
// Used by:
// -WindowEventType_Resized
// -WindowEventType::Resized
struct SizeEvent
{
unsigned int height;
@@ -79,7 +79,7 @@ namespace Nz
};
// Used by:
// -WindowEventType_TextEntered
// -WindowEventType::TextEntered
struct TextEvent
{
bool repeated;
@@ -87,7 +87,7 @@ namespace Nz
};
// Used by:
// -WindowEventType_TextEdited
// -WindowEventType::TextEdited
struct EditEvent
{
int length;
@@ -99,37 +99,37 @@ namespace Nz
union
{
// Used by:
// -WindowEventType_KeyPressed
// -WindowEventType_KeyReleased
// -WindowEventType::KeyPressed
// -WindowEventType::KeyReleased
KeyEvent key;
// Used by:
// -WindowEventType_MouseButtonDoubleClicked
// -WindowEventType_MouseButtonPressed
// -WindowEventType::MouseButtonDoubleClicked
// -WindowEventType::MouseButtonPressed
MouseButtonEvent mouseButton;
// Used by:
// -WindowEventType_MouseMoved
// -WindowEventType::MouseMoved
MouseMoveEvent mouseMove;
// Used by:
// -WindowEventType_MouseWheelMoved
// -WindowEventType::MouseWheelMoved
MouseWheelEvent mouseWheel;
// Used by:
// -WindowEventType_Moved
// -WindowEventType::Moved
PositionEvent position;
// Used by:
// -WindowEventType_Resized
// -WindowEventType::Resized
SizeEvent size;
// Used by:
// -WindowEventType_TextEntered
// -WindowEventType::TextEntered
TextEvent text;
// Used by:
// -WindowEventType_TextEntered
// -WindowEventType::TextEntered
EditEvent edit;
};
};

View File

@@ -19,67 +19,67 @@ namespace Nz
switch (event.type)
{
case WindowEventType_GainedFocus:
case WindowEventType::GainedFocus:
OnGainedFocus(this);
break;
case WindowEventType_KeyPressed:
case WindowEventType::KeyPressed:
OnKeyPressed(this, event.key);
break;
case WindowEventType_KeyReleased:
case WindowEventType::KeyReleased:
OnKeyReleased(this, event.key);
break;
case WindowEventType_LostFocus:
case WindowEventType::LostFocus:
OnLostFocus(this);
break;
case WindowEventType_MouseButtonDoubleClicked:
case WindowEventType::MouseButtonDoubleClicked:
OnMouseButtonDoubleClicked(this, event.mouseButton);
break;
case WindowEventType_MouseButtonPressed:
case WindowEventType::MouseButtonPressed:
OnMouseButtonPressed(this, event.mouseButton);
break;
case WindowEventType_MouseButtonReleased:
case WindowEventType::MouseButtonReleased:
OnMouseButtonReleased(this, event.mouseButton);
break;
case WindowEventType_MouseEntered:
case WindowEventType::MouseEntered:
OnMouseEntered(this);
break;
case WindowEventType_MouseLeft:
case WindowEventType::MouseLeft:
OnMouseLeft(this);
break;
case WindowEventType_MouseMoved:
case WindowEventType::MouseMoved:
OnMouseMoved(this, event.mouseMove);
break;
case WindowEventType_MouseWheelMoved:
case WindowEventType::MouseWheelMoved:
OnMouseWheelMoved(this, event.mouseWheel);
break;
case WindowEventType_Moved:
case WindowEventType::Moved:
OnMoved(this, event.position);
break;
case WindowEventType_Quit:
case WindowEventType::Quit:
OnQuit(this);
break;
case WindowEventType_Resized:
case WindowEventType::Resized:
OnResized(this, event.size);
break;
case WindowEventType_TextEntered:
case WindowEventType::TextEntered:
OnTextEntered(this, event.text);
break;
case WindowEventType_TextEdited:
case WindowEventType::TextEdited:
OnTextEdited(this, event.edit);
break;
}

View File

@@ -8,36 +8,35 @@
#define NAZARA_ICON_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Platform/Config.hpp>
#include <memory>
namespace Nz
{
class Image;
class IconImpl;
class Icon;
using IconRef = ObjectRef<Icon>;
class NAZARA_PLATFORM_API Icon : public RefCounted
class NAZARA_PLATFORM_API Icon
{
friend class WindowImpl;
public:
inline Icon();
inline explicit Icon(const Image& icon);
inline ~Icon();
Icon();
explicit Icon(const Image& icon);
Icon(const Icon&) = delete;
Icon(Icon&&) noexcept;
~Icon();
bool Create(const Image& icon);
void Destroy();
inline bool IsValid() const;
template<typename... Args> static IconRef New(Args&&... args);
Icon& operator=(const Icon&) = delete;
Icon& operator=(Icon&&) noexcept;
private:
IconImpl* m_impl;
std::unique_ptr<IconImpl> m_impl;
};
}

View File

@@ -7,35 +7,10 @@
namespace Nz
{
Icon::Icon() :
m_impl(nullptr)
{
}
inline Icon::Icon(const Image& icon)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(icon);
}
Icon::~Icon()
{
Destroy();
}
bool Icon::IsValid() const
{
return m_impl != nullptr;
}
template<typename... Args>
IconRef Icon::New(Args&&... args)
{
std::unique_ptr<Icon> object(new Icon(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Platform/DebugOff.hpp>

View File

@@ -58,7 +58,7 @@ namespace Nz
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
inline const CursorRef& GetCursor() const;
inline const std::shared_ptr<Cursor>& GetCursor() const;
inline CursorController& GetCursorController();
inline EventHandler& GetEventHandler();
Vector2i GetPosition() const;
@@ -82,11 +82,11 @@ namespace Nz
void ProcessEvents(bool block = false);
void SetCursor(CursorRef cursor);
void SetCursor(std::shared_ptr<Cursor> cursor);
inline void SetCursor(SystemCursor systemCursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(IconRef icon);
void SetIcon(std::shared_ptr<Icon> icon);
void SetMaximumSize(const Vector2i& maxSize);
void SetMaximumSize(int width, int height);
void SetMinimumSize(const Vector2i& minSize);
@@ -133,9 +133,9 @@ namespace Nz
std::vector<WindowEvent> m_pendingEvents;
std::condition_variable m_eventCondition;
CursorController m_cursorController;
CursorRef m_cursor;
std::shared_ptr<Cursor> m_cursor;
EventHandler m_eventHandler;
IconRef m_icon;
std::shared_ptr<Icon> m_icon;
std::mutex m_eventMutex;
std::mutex m_eventConditionMutex;
bool m_asyncWindow;

View File

@@ -46,7 +46,7 @@ namespace Nz
}
}
inline const CursorRef& Window::GetCursor() const
inline const std::shared_ptr<Cursor>& Window::GetCursor() const
{
return m_cursor;
}