Skip to content

Commit

Permalink
Add helper function pointerTypeToCursorId
Browse files Browse the repository at this point in the history
I was kind of hoping for an explicit conversion operator on `PointerType` to convert to a `CursorId` struct, but sadly such conversion operators are not possible with `enum class`. A free standing function is I suppose close enough.
  • Loading branch information
DanRStevens committed Feb 3, 2025
1 parent fdd7d35 commit b54d80f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions appOPHD/PointerType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
#include <NAS2D/Utility.h>


constexpr NAS2D::CursorId pointerTypeToCursorId(PointerType pointerType)
{
return NAS2D::CursorId{static_cast<int>(pointerType)};
}


void setCursor(PointerType pointerType)
{
NAS2D::Utility<NAS2D::Renderer>::get().setCursor(NAS2D::CursorId{static_cast<int>(pointerType)});
NAS2D::Utility<NAS2D::Renderer>::get().setCursor(pointerTypeToCursorId(pointerType));
}


void addCursor(PointerType pointerType, const std::string& fileName, NAS2D::Vector<int> hotOffset)
{
NAS2D::Utility<NAS2D::Renderer>::get().addCursor(NAS2D::CursorId{static_cast<int>(pointerType)}, fileName, hotOffset);
NAS2D::Utility<NAS2D::Renderer>::get().addCursor(pointerTypeToCursorId(pointerType), fileName, hotOffset);
}
4 changes: 4 additions & 0 deletions appOPHD/PointerType.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NAS2D
{
template <typename BaseType>
class Vector;

struct CursorId;
}


Expand All @@ -17,5 +19,7 @@ enum class PointerType
};


constexpr NAS2D::CursorId pointerTypeToCursorId(PointerType pointerType);

void setCursor(PointerType pointerType);
void addCursor(PointerType pointerType, const std::string& fileName, NAS2D::Vector<int> hotOffset);

0 comments on commit b54d80f

Please sign in to comment.