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