aboutsummaryrefslogtreecommitdiff
path: root/src/osx/gui/Cursor.mm
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-10-15 20:35:17 +0800
committercrupest <crupest@outlook.com>2021-10-15 20:35:17 +0800
commited368423531b24e8735db0afe38c7486145caa56 (patch)
tree2a88be9ce9062ac3c7e5c4ceb496d687102815ec /src/osx/gui/Cursor.mm
parentd3e2a751353e6c5b0e4d7c0a2af1cdbc09d3ea95 (diff)
downloadcru-ed368423531b24e8735db0afe38c7486145caa56.tar.gz
cru-ed368423531b24e8735db0afe38c7486145caa56.tar.bz2
cru-ed368423531b24e8735db0afe38c7486145caa56.zip
...
Diffstat (limited to 'src/osx/gui/Cursor.mm')
-rw-r--r--src/osx/gui/Cursor.mm93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/osx/gui/Cursor.mm b/src/osx/gui/Cursor.mm
new file mode 100644
index 00000000..30b0f0fd
--- /dev/null
+++ b/src/osx/gui/Cursor.mm
@@ -0,0 +1,93 @@
+#include "cru/osx/gui/Cursor.hpp"
+#include "CursorPrivate.h"
+
+#include "cru/osx/Exception.hpp"
+#include "cru/osx/gui/Resource.hpp"
+#include "cru/platform/gui/Cursor.hpp"
+#include "cru/platform/gui/UiApplication.hpp"
+
+#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.");
+ }
+}
+}