blob: 3a916fd19be70f0ec2ee1364530d1c571d37f6a0 (
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
|
#include "cru/ui/mapper/CursorMapper.h"
#include "../Helper.h"
#include "cru/common/Exception.h"
#include "cru/platform/gui/Cursor.h"
#include "cru/platform/gui/UiApplication.h"
namespace cru::ui::mapper {
using cru::platform::gui::ICursor;
using cru::platform::gui::SystemCursorType;
bool CursorMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) {
return node->GetTag().CaseInsensitiveCompare(u"Cursor") == 0;
}
std::shared_ptr<ICursor> CursorMapper::DoMapFromString(String str) {
if (str.empty()) return nullptr;
auto cursor_manager = GetUiApplication()->GetCursorManager();
if (str.CaseInsensitiveCompare(u"arrow") == 0) {
return cursor_manager->GetSystemCursor(SystemCursorType::Arrow);
} else if (str.CaseInsensitiveCompare(u"hand") == 0) {
return cursor_manager->GetSystemCursor(SystemCursorType::Hand);
} else if (str.CaseInsensitiveCompare(u"ibeam") == 0) {
return cursor_manager->GetSystemCursor(SystemCursorType::IBeam);
} else {
throw Exception(u"Unsupported cursor type.");
}
}
std::shared_ptr<ICursor> CursorMapper::DoMapFromXml(xml::XmlElementNode *node) {
auto value_attr = node->GetOptionalAttributeCaseInsensitive(u"value");
if (!value_attr) return nullptr;
return DoMapFromString(*value_attr);
}
} // namespace cru::ui::mapper
|