diff options
Diffstat (limited to 'src/platform/gui/osx/Cursor.mm')
-rw-r--r-- | src/platform/gui/osx/Cursor.mm | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/platform/gui/osx/Cursor.mm b/src/platform/gui/osx/Cursor.mm new file mode 100644 index 00000000..fae1514c --- /dev/null +++ b/src/platform/gui/osx/Cursor.mm @@ -0,0 +1,93 @@ +#include "cru/platform/gui/osx/Cursor.h" +#include "CursorPrivate.h" + +#include "cru/platform/osx/Exception.h" +#include "cru/platform/gui/osx/Resource.h" +#include "cru/platform/gui/Cursor.h" +#include "cru/platform/gui/UiApplication.h" + +#include <memory> + +namespace cru::platform::gui::osx { +namespace details { +OsxCursorPrivate::OsxCursorPrivate(OsxCursor* cursor, SystemCursorType cursor_type) { + cursor_ = cursor; + + switch (cursor_type) { + case SystemCursorType::Arrow: + ns_cursor_ = [NSCursor arrowCursor]; + break; + case SystemCursorType::Hand: + ns_cursor_ = [NSCursor pointingHandCursor]; + break; + case SystemCursorType::IBeam: + ns_cursor_ = [NSCursor IBeamCursor]; + break; + default: + throw Exception(u"Unknown system cursor type."); + } +} + +OsxCursorPrivate::~OsxCursorPrivate() {} +} + +OsxCursor::OsxCursor(IUiApplication* ui_application, SystemCursorType cursor_type) + : OsxGuiResource(ui_application) { + p_ = std::make_unique<details::OsxCursorPrivate>(this, cursor_type); +} + +OsxCursor::~OsxCursor() {} + +namespace details { +class OsxCursorManagerPrivate { + friend OsxCursorManager; + + public: + explicit OsxCursorManagerPrivate(OsxCursorManager* cursor_manager); + + CRU_DELETE_COPY(OsxCursorManagerPrivate) + CRU_DELETE_MOVE(OsxCursorManagerPrivate) + + ~OsxCursorManagerPrivate(); + + private: + OsxCursorManager* cursor_manager_; + + std::shared_ptr<OsxCursor> arrow_cursor_; + std::shared_ptr<OsxCursor> hand_cursor_; + std::shared_ptr<OsxCursor> ibeam_cursor_; +}; + +OsxCursorManagerPrivate::OsxCursorManagerPrivate(OsxCursorManager* cursor_manager) { + cursor_manager_ = cursor_manager; + arrow_cursor_ = + std::make_shared<OsxCursor>(cursor_manager->GetUiApplication(), SystemCursorType::Arrow); + hand_cursor_ = + std::make_shared<OsxCursor>(cursor_manager->GetUiApplication(), SystemCursorType::Hand); + ibeam_cursor_ = + std::make_shared<OsxCursor>(cursor_manager->GetUiApplication(), SystemCursorType::IBeam); +} + +OsxCursorManagerPrivate::~OsxCursorManagerPrivate() {} +} + +OsxCursorManager::OsxCursorManager(IUiApplication* ui_application) + : OsxGuiResource(ui_application) { + p_ = std::make_unique<details::OsxCursorManagerPrivate>(this); +} + +OsxCursorManager::~OsxCursorManager() {} + +std::shared_ptr<ICursor> OsxCursorManager::GetSystemCursor(SystemCursorType type) { + switch (type) { + case SystemCursorType::Arrow: + return p_->arrow_cursor_; + case SystemCursorType::Hand: + return p_->hand_cursor_; + case SystemCursorType::IBeam: + return p_->ibeam_cursor_; + default: + throw Exception(u"Unknown system cursor type."); + } +} +} |