Utility: Rework cursors
-Rename WindowCursor to SystemCursor -Merged Cursor class with SystemCursor enum
This commit is contained in:
@@ -22,18 +22,32 @@ namespace Nz
|
||||
|
||||
public:
|
||||
inline Cursor();
|
||||
inline Cursor(SystemCursor systemCursor); //< implicit conversion intended
|
||||
Cursor(const Cursor&) = delete;
|
||||
inline Cursor(Cursor&& cursor) noexcept;
|
||||
inline ~Cursor();
|
||||
|
||||
bool Create(const Image& cursor, int hotSpotX = 0, int hotSpotY = 0);
|
||||
bool Create(const Image& cursor, const Vector2i& hotSpot);
|
||||
bool Create(SystemCursor cursor);
|
||||
|
||||
void Destroy();
|
||||
|
||||
inline const Image& GetImage() const;
|
||||
inline SystemCursor GetSystemCursor() const;
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
Cursor& operator=(const Cursor&) = delete;
|
||||
inline Cursor& operator=(Cursor&& cursor);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
Image m_cursorImage;
|
||||
SystemCursor m_systemCursor;
|
||||
CursorImpl* m_impl;
|
||||
bool m_usesSystemCursor;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,30 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Cursor.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Cursor::Cursor() :
|
||||
m_impl(nullptr)
|
||||
m_impl(nullptr),
|
||||
m_usesSystemCursor(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline Cursor::Cursor(SystemCursor systemCursor) :
|
||||
Cursor()
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
Create(systemCursor);
|
||||
}
|
||||
|
||||
inline Cursor::Cursor(Cursor&& cursor) noexcept :
|
||||
Cursor()
|
||||
{
|
||||
operator=(std::move(cursor));
|
||||
}
|
||||
|
||||
inline Cursor::~Cursor()
|
||||
{
|
||||
Destroy();
|
||||
@@ -19,13 +34,36 @@ namespace Nz
|
||||
|
||||
inline const Image& Cursor::GetImage() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid cursor");
|
||||
NazaraAssert(!m_usesSystemCursor, "System cursors have no image");
|
||||
|
||||
return m_cursorImage;
|
||||
}
|
||||
|
||||
inline SystemCursor Cursor::GetSystemCursor() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid cursor");
|
||||
NazaraAssert(m_usesSystemCursor, "Custom cursor uses an image");
|
||||
|
||||
return m_systemCursor;
|
||||
}
|
||||
|
||||
inline bool Cursor::IsValid() const
|
||||
{
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
inline Cursor& Cursor::operator=(Cursor&& cursor)
|
||||
{
|
||||
m_cursorImage = std::move(cursor.m_cursorImage);
|
||||
m_systemCursor = cursor.m_systemCursor;
|
||||
m_impl = cursor.m_impl;
|
||||
m_usesSystemCursor = cursor.m_usesSystemCursor;
|
||||
|
||||
cursor.m_impl = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
|
||||
@@ -307,6 +307,31 @@ namespace Nz
|
||||
SamplerWrap_Max = SamplerWrap_Repeat
|
||||
};
|
||||
|
||||
enum SystemCursor
|
||||
{
|
||||
SystemCursor_None,
|
||||
SystemCursor_Default,
|
||||
|
||||
SystemCursor_Crosshair,
|
||||
SystemCursor_Hand,
|
||||
SystemCursor_Help,
|
||||
SystemCursor_Move,
|
||||
SystemCursor_Pointer,
|
||||
SystemCursor_Progress,
|
||||
SystemCursor_ResizeE,
|
||||
SystemCursor_ResizeN,
|
||||
SystemCursor_ResizeNE,
|
||||
SystemCursor_ResizeNW,
|
||||
SystemCursor_ResizeS,
|
||||
SystemCursor_ResizeSE,
|
||||
SystemCursor_ResizeSW,
|
||||
SystemCursor_ResizeW,
|
||||
SystemCursor_Text,
|
||||
SystemCursor_Wait,
|
||||
|
||||
SystemCursor_Max = SystemCursor_Wait
|
||||
};
|
||||
|
||||
enum StencilOperation
|
||||
{
|
||||
StencilOperation_Decrement,
|
||||
@@ -393,31 +418,6 @@ namespace Nz
|
||||
VertexLayout_Max = VertexLayout_Matrix4
|
||||
};
|
||||
|
||||
enum WindowCursor
|
||||
{
|
||||
WindowCursor_None,
|
||||
WindowCursor_Default,
|
||||
|
||||
WindowCursor_Crosshair,
|
||||
WindowCursor_Hand,
|
||||
WindowCursor_Help,
|
||||
WindowCursor_Move,
|
||||
WindowCursor_Pointer,
|
||||
WindowCursor_Progress,
|
||||
WindowCursor_ResizeE,
|
||||
WindowCursor_ResizeN,
|
||||
WindowCursor_ResizeNE,
|
||||
WindowCursor_ResizeNW,
|
||||
WindowCursor_ResizeS,
|
||||
WindowCursor_ResizeSE,
|
||||
WindowCursor_ResizeSW,
|
||||
WindowCursor_ResizeW,
|
||||
WindowCursor_Text,
|
||||
WindowCursor_Wait,
|
||||
|
||||
WindowCursor_Max = WindowCursor_Wait
|
||||
};
|
||||
|
||||
enum WindowEventType
|
||||
{
|
||||
WindowEventType_GainedFocus,
|
||||
|
||||
@@ -79,7 +79,6 @@ namespace Nz
|
||||
|
||||
void ProcessEvents(bool block = false);
|
||||
|
||||
void SetCursor(WindowCursor cursor);
|
||||
void SetCursor(const Cursor& cursor);
|
||||
void SetEventListener(bool listener);
|
||||
void SetFocus();
|
||||
|
||||
Reference in New Issue
Block a user