blob: ec364fa7d1c3f83a0cae40eb91da2131385bb517 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include "cru/platform/gui/osx/Cursor.h"
#include "CursorPrivate.h"
#include "cru/base/Exception.h"
#include "cru/platform/gui/Cursor.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/platform/gui/osx/Resource.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() {}
} // namespace details
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() {}
} // namespace details
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.");
}
}
} // namespace cru::platform::gui::osx
|