Utility/Cursor: Rework Cursor as a handled object
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool Cursor::Create(const Image& cursor, const Vector2i& hotSpot)
|
||||
bool Cursor::Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
@@ -29,10 +29,24 @@ namespace Nz
|
||||
|
||||
m_cursorImage = cursor;
|
||||
m_impl = impl.release();
|
||||
m_systemCursor = placeholder;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cursor::Destroy()
|
||||
{
|
||||
m_cursorImage.Destroy();
|
||||
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Destroy();
|
||||
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Cursor::Create(SystemCursor cursor)
|
||||
{
|
||||
Destroy();
|
||||
@@ -46,31 +60,28 @@ namespace Nz
|
||||
|
||||
m_impl = impl.release();
|
||||
m_systemCursor = cursor;
|
||||
m_usesSystemCursor = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cursor::Destroy()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Destroy();
|
||||
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
m_usesSystemCursor = false;
|
||||
}
|
||||
|
||||
bool Cursor::Initialize()
|
||||
{
|
||||
return CursorImpl::Initialize();
|
||||
if (!CursorImpl::Initialize())
|
||||
return false;
|
||||
|
||||
for (std::size_t i = 0; i <= SystemCursor_Max; ++i)
|
||||
s_systemCursors[i].Create(static_cast<SystemCursor>(i));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cursor::Uninitialize()
|
||||
{
|
||||
for (Cursor& cursor : s_systemCursors)
|
||||
cursor.Destroy();
|
||||
|
||||
CursorImpl::Uninitialize();
|
||||
}
|
||||
|
||||
std::array<Cursor, SystemCursor_Max + 1> Cursor::s_systemCursors;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Nz
|
||||
m_eventPolling(false),
|
||||
m_waitForEvent(false)
|
||||
{
|
||||
m_cursorController.OnCursorUpdated.Connect([this](const CursorController*, const Cursor& cursor)
|
||||
m_cursorController.OnCursorUpdated.Connect([this](const CursorController*, const CursorRef& cursor)
|
||||
{
|
||||
if (IsValid())
|
||||
SetCursor(cursor);
|
||||
@@ -104,11 +104,12 @@ namespace Nz
|
||||
// Paramètres par défaut
|
||||
m_impl->EnableKeyRepeat(true);
|
||||
m_impl->EnableSmoothScrolling(false);
|
||||
m_impl->SetCursor(SystemCursor_Default);
|
||||
m_impl->SetMaximumSize(-1, -1);
|
||||
m_impl->SetMinimumSize(-1, -1);
|
||||
m_impl->SetVisible(true);
|
||||
|
||||
SetCursor(Cursor::Get(SystemCursor_Default));
|
||||
|
||||
if (opened)
|
||||
m_impl->SetPosition(position.x, position.y);
|
||||
|
||||
@@ -151,6 +152,8 @@ namespace Nz
|
||||
|
||||
void Window::Destroy()
|
||||
{
|
||||
m_cursor.Reset();
|
||||
|
||||
if (m_impl)
|
||||
{
|
||||
OnWindowDestroy();
|
||||
@@ -364,12 +367,13 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
void Window::SetCursor(const Cursor& cursor)
|
||||
void Window::SetCursor(CursorRef cursor)
|
||||
{
|
||||
NazaraAssert(m_impl, "Window not created");
|
||||
NazaraAssert(cursor.IsValid(), "Invalid cursor");
|
||||
NazaraAssert(cursor && cursor->IsValid(), "Invalid cursor");
|
||||
|
||||
m_impl->SetCursor(cursor);
|
||||
m_cursor = std::move(cursor);
|
||||
m_impl->SetCursor(*m_cursor);
|
||||
}
|
||||
|
||||
void Window::SetEventListener(bool listener)
|
||||
|
||||
Reference in New Issue
Block a user