Make use of the new EnumMap class
This commit is contained in:
@@ -73,10 +73,10 @@ namespace Nz
|
||||
|
||||
bool Cursor::Initialize()
|
||||
{
|
||||
for (std::size_t i = 0; i < SystemCursorCount; ++i)
|
||||
for (auto&& [cursor, cursorPtr] : s_systemCursors.iter_kv())
|
||||
{
|
||||
s_systemCursors[i] = std::make_shared<Cursor>();
|
||||
s_systemCursors[i]->Create(static_cast<SystemCursor>(i));
|
||||
cursorPtr = std::make_shared<Cursor>();
|
||||
cursorPtr->Create(cursor);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -88,5 +88,5 @@ namespace Nz
|
||||
cursor.reset();
|
||||
}
|
||||
|
||||
std::array<std::shared_ptr<Cursor>, SystemCursorCount> Cursor::s_systemCursors;
|
||||
EnumMap<SystemCursor, std::shared_ptr<Cursor>> Cursor::s_systemCursors;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace
|
||||
namespace NAZARA_ANONYMOUS_NAMESPACE
|
||||
{
|
||||
std::array<SDL_SystemCursor, SystemCursorCount> s_systemCursorIds =
|
||||
constexpr EnumMap<SystemCursor, SDL_SystemCursor> s_systemCursorIds =
|
||||
{
|
||||
SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor::Crosshair
|
||||
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor::Default
|
||||
@@ -69,11 +69,13 @@ namespace Nz
|
||||
|
||||
CursorImpl::CursorImpl(SystemCursor cursor)
|
||||
{
|
||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||
|
||||
ErrorFlags errFlags(ErrorMode::ThrowException);
|
||||
|
||||
if (cursor != SystemCursor::None)
|
||||
{
|
||||
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[UnderlyingCast(cursor)]);
|
||||
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
|
||||
if (!m_cursor)
|
||||
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user