SDL: implement cursor icon API (#135)

This commit is contained in:
DS 2022-11-12 15:52:39 +01:00 committed by GitHub
parent b9e0641203
commit 1579ce2740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -1197,6 +1197,25 @@ void CIrrDeviceSDL::createKeyMap()
KeyMap.sort(); KeyMap.sort();
} }
void CIrrDeviceSDL::CCursorControl::initCursors()
{
Cursors.reserve(gui::ECI_COUNT);
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW)); // ECI_NORMAL
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR)); // ECI_CROSS
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND)); // ECI_HAND
Cursors.emplace_back(nullptr); // ECI_HELP
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM)); // ECI_IBEAM
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO)); // ECI_NO
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT)); // ECI_WAIT
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL)); // ECI_SIZEALL
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW)); // ECI_SIZENESW
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE)); // ECI_SIZENWSE
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS)); // ECI_SIZENS
Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE)); // ECI_SIZEWE
Cursors.emplace_back(nullptr); // ECI_UP
}
} // end namespace irr } // end namespace irr
#endif // _IRR_COMPILE_WITH_SDL_DEVICE_ #endif // _IRR_COMPILE_WITH_SDL_DEVICE_

View File

@ -23,6 +23,8 @@
#include <SDL.h> #include <SDL.h>
#include <SDL_syswm.h> #include <SDL_syswm.h>
#include <memory>
namespace irr namespace irr
{ {
@ -104,6 +106,7 @@ namespace irr
CCursorControl(CIrrDeviceSDL* dev) CCursorControl(CIrrDeviceSDL* dev)
: Device(dev), IsVisible(true) : Device(dev), IsVisible(true)
{ {
initCursors();
} }
//! Changes the visible state of the mouse cursor. //! Changes the visible state of the mouse cursor.
@ -186,6 +189,22 @@ namespace irr
} }
} }
void setActiveIcon(gui::ECURSOR_ICON iconId) override
{
ActiveIcon = iconId;
if (iconId > Cursors.size() || !Cursors[iconId]) {
iconId = gui::ECI_NORMAL;
if (iconId > Cursors.size() || !Cursors[iconId])
return;
}
SDL_SetCursor(Cursors[iconId].get());
}
gui::ECURSOR_ICON getActiveIcon() const override
{
return ActiveIcon;
}
private: private:
void updateCursorPos() void updateCursorPos()
@ -222,9 +241,20 @@ namespace irr
#endif #endif
} }
void initCursors();
CIrrDeviceSDL* Device; CIrrDeviceSDL* Device;
core::position2d<s32> CursorPos; core::position2d<s32> CursorPos;
bool IsVisible; bool IsVisible;
struct CursorDeleter {
void operator()(SDL_Cursor *ptr) {
if (ptr)
SDL_FreeCursor(ptr);
}
};
std::vector<std::unique_ptr<SDL_Cursor, CursorDeleter>> Cursors;
gui::ECURSOR_ICON ActiveIcon;
}; };
private: private: