From 1579ce274071159527a9af14da0b7ac4f2b0b31d Mon Sep 17 00:00:00 2001 From: DS Date: Sat, 12 Nov 2022 15:52:39 +0100 Subject: [PATCH] SDL: implement cursor icon API (#135) --- source/Irrlicht/CIrrDeviceSDL.cpp | 19 +++++++++++++++++++ source/Irrlicht/CIrrDeviceSDL.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 84a6d643..12574d5a 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -1197,6 +1197,25 @@ void CIrrDeviceSDL::createKeyMap() 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 #endif // _IRR_COMPILE_WITH_SDL_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index e8583997..ab809ddc 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -23,6 +23,8 @@ #include #include +#include + namespace irr { @@ -104,6 +106,7 @@ namespace irr CCursorControl(CIrrDeviceSDL* dev) : Device(dev), IsVisible(true) { + initCursors(); } //! 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: void updateCursorPos() @@ -222,9 +241,20 @@ namespace irr #endif } + void initCursors(); + CIrrDeviceSDL* Device; core::position2d CursorPos; bool IsVisible; + + struct CursorDeleter { + void operator()(SDL_Cursor *ptr) { + if (ptr) + SDL_FreeCursor(ptr); + } + }; + std::vector> Cursors; + gui::ECURSOR_ICON ActiveIcon; }; private: