aboutsummaryrefslogtreecommitdiff
path: root/src/theme_builder/components/stylers/CursorStylerEditor.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-16 20:22:25 +0800
committercrupest <crupest@outlook.com>2022-02-16 20:22:25 +0800
commit3cd44092c44651650a760752a3d374f610ca4f77 (patch)
treed3481e8d93d8d47674d0df46eb765ccf9100bca8 /src/theme_builder/components/stylers/CursorStylerEditor.cpp
parent6459edc7c8af9e5c9bafe4f1635194334f42f415 (diff)
downloadcru-3cd44092c44651650a760752a3d374f610ca4f77.tar.gz
cru-3cd44092c44651650a760752a3d374f610ca4f77.tar.bz2
cru-3cd44092c44651650a760752a3d374f610ca4f77.zip
...
Diffstat (limited to 'src/theme_builder/components/stylers/CursorStylerEditor.cpp')
-rw-r--r--src/theme_builder/components/stylers/CursorStylerEditor.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/theme_builder/components/stylers/CursorStylerEditor.cpp b/src/theme_builder/components/stylers/CursorStylerEditor.cpp
new file mode 100644
index 00000000..4cbd69cd
--- /dev/null
+++ b/src/theme_builder/components/stylers/CursorStylerEditor.cpp
@@ -0,0 +1,61 @@
+#include "CursorStylerEditor.h"
+#include "cru/platform/gui/Cursor.h"
+#include "cru/platform/gui/UiApplication.h"
+
+namespace cru::theme_builder::components::stylers {
+CursorStylerEditor::CursorStylerEditor() {
+ GetContainer()->AddChild(cursor_select_.GetRootControl());
+
+ cursor_select_.SetItems({u"arrow", u"hand", u"ibeam"});
+ cursor_select_.SetSelectedIndex(0);
+}
+
+CursorStylerEditor::~CursorStylerEditor() {}
+
+ClonablePtr<ui::style::CursorStyler> CursorStylerEditor::GetValue() {
+ auto cursor_manager =
+ platform::gui::IUiApplication::GetInstance()->GetCursorManager();
+
+ std::shared_ptr<platform::gui::ICursor> cursor;
+
+ switch (cursor_select_.GetSelectedIndex()) {
+ case 0:
+ cursor = cursor_manager->GetSystemCursor(
+ platform::gui::SystemCursorType::Arrow);
+ break;
+ case 1:
+ cursor = cursor_manager->GetSystemCursor(
+ platform::gui::SystemCursorType::Hand);
+ break;
+ case 2:
+ cursor = cursor_manager->GetSystemCursor(
+ platform::gui::SystemCursorType::IBeam);
+ break;
+ }
+
+ return ui::style::CursorStyler::Create(cursor);
+}
+
+void CursorStylerEditor::SetValue(ui::style::CursorStyler* styler,
+ bool trigger_change) {
+ auto cursor_manager =
+ platform::gui::IUiApplication::GetInstance()->GetCursorManager();
+
+ auto cursor = styler->GetCursor();
+
+ if (cursor ==
+ cursor_manager->GetSystemCursor(platform::gui::SystemCursorType::Arrow)) {
+ cursor_select_.SetSelectedIndex(0);
+ } else if (cursor == cursor_manager->GetSystemCursor(
+ platform::gui::SystemCursorType::Hand)) {
+ cursor_select_.SetSelectedIndex(1);
+ } else if (cursor == cursor_manager->GetSystemCursor(
+ platform::gui::SystemCursorType::IBeam)) {
+ cursor_select_.SetSelectedIndex(2);
+ }
+
+ if (trigger_change) {
+ change_event_.Raise(nullptr);
+ }
+}
+} // namespace cru::theme_builder::components::stylers