]> git.lizzy.rs Git - irrlicht.git/commitdiff
SDL: implement cursor icon API (#135)
authorDS <vorunbekannt75@web.de>
Sat, 12 Nov 2022 14:52:39 +0000 (15:52 +0100)
committerGitHub <noreply@github.com>
Sat, 12 Nov 2022 14:52:39 +0000 (15:52 +0100)
source/Irrlicht/CIrrDeviceSDL.cpp
source/Irrlicht/CIrrDeviceSDL.h

index 84a6d6438ebe6e806a529523255da3ab2e95700c..12574d5a72f468ddbbc5085035c70579ede070c6 100644 (file)
@@ -1197,6 +1197,25 @@ void CIrrDeviceSDL::createKeyMap()
        KeyMap.sort();\r
 }\r
 \r
+void CIrrDeviceSDL::CCursorControl::initCursors()\r
+{\r
+       Cursors.reserve(gui::ECI_COUNT);\r
+\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW));     // ECI_NORMAL\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR)); // ECI_CROSS\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND));      // ECI_HAND\r
+       Cursors.emplace_back(nullptr);                                             // ECI_HELP\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM));     // ECI_IBEAM\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO));        // ECI_NO\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT));      // ECI_WAIT\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL));   // ECI_SIZEALL\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW));  // ECI_SIZENESW\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE));  // ECI_SIZENWSE\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS));    // ECI_SIZENS\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE));    // ECI_SIZEWE\r
+       Cursors.emplace_back(nullptr);                                             // ECI_UP\r
+}\r
+\r
 } // end namespace irr\r
 \r
 #endif // _IRR_COMPILE_WITH_SDL_DEVICE_\r
index e85839978c42daa86b9fc548b39e5d843a333cbd..ab809ddc7befbde4b4623f02d167566cf46f289f 100644 (file)
@@ -23,6 +23,8 @@
 #include <SDL.h>\r
 #include <SDL_syswm.h>\r
 \r
+#include <memory>\r
+\r
 namespace irr\r
 {\r
 \r
@@ -104,6 +106,7 @@ namespace irr
                        CCursorControl(CIrrDeviceSDL* dev)\r
                                : Device(dev), IsVisible(true)\r
                        {\r
+                               initCursors();\r
                        }\r
 \r
                        //! Changes the visible state of the mouse cursor.\r
@@ -186,6 +189,22 @@ namespace irr
                                }\r
                        }\r
 \r
+                       void setActiveIcon(gui::ECURSOR_ICON iconId) override\r
+                       {\r
+                               ActiveIcon = iconId;\r
+                               if (iconId > Cursors.size() || !Cursors[iconId]) {\r
+                                       iconId = gui::ECI_NORMAL;\r
+                                       if (iconId > Cursors.size() || !Cursors[iconId])\r
+                                               return;\r
+                               }\r
+                               SDL_SetCursor(Cursors[iconId].get());\r
+                       }\r
+\r
+                       gui::ECURSOR_ICON getActiveIcon() const override\r
+                       {\r
+                               return ActiveIcon;\r
+                       }\r
+\r
                private:\r
 \r
                        void updateCursorPos()\r
@@ -222,9 +241,20 @@ namespace irr
 #endif\r
                        }\r
 \r
+                       void initCursors();\r
+\r
                        CIrrDeviceSDL* Device;\r
                        core::position2d<s32> CursorPos;\r
                        bool IsVisible;\r
+\r
+                       struct CursorDeleter {\r
+                               void operator()(SDL_Cursor *ptr) {\r
+                                       if (ptr)\r
+                                               SDL_FreeCursor(ptr);\r
+                               }\r
+                       };\r
+                       std::vector<std::unique_ptr<SDL_Cursor, CursorDeleter>> Cursors;\r
+                       gui::ECURSOR_ICON ActiveIcon;\r
                };\r
 \r
        private:\r