aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-22 22:37:24 +0800
committercrupest <crupest@outlook.com>2022-01-22 22:37:24 +0800
commit13860c88910c00478abe3001cc80125e76767381 (patch)
tree507f517467a4e3c851f87a1158f751c38d8644be /src/ui/mapper
parent14d9efc39635dab2c6c0f791d6b0a63c92d941ee (diff)
downloadcru-13860c88910c00478abe3001cc80125e76767381.tar.gz
cru-13860c88910c00478abe3001cc80125e76767381.tar.bz2
cru-13860c88910c00478abe3001cc80125e76767381.zip
...
Diffstat (limited to 'src/ui/mapper')
-rw-r--r--src/ui/mapper/CursorMapper.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/ui/mapper/CursorMapper.cpp b/src/ui/mapper/CursorMapper.cpp
index 2dd08219..d77da2a5 100644
--- a/src/ui/mapper/CursorMapper.cpp
+++ b/src/ui/mapper/CursorMapper.cpp
@@ -1,3 +1,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 {}
+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