aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-09-08 19:09:38 +0800
committer杨宇千 <crupest@outlook.com>2019-09-08 19:09:38 +0800
commit8b9a306d6f24dbc08aeee16b115260406e79126d (patch)
treedb37b8c3441a28b7150b1f40ddf79c7fa9dcda79 /src/ui/control.cpp
parent2c40085dd30d6e7370a0974ad1f642a61acc6e30 (diff)
downloadcru-8b9a306d6f24dbc08aeee16b115260406e79126d.tar.gz
cru-8b9a306d6f24dbc08aeee16b115260406e79126d.tar.bz2
cru-8b9a306d6f24dbc08aeee16b115260406e79126d.zip
...
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 7bd33d84..50628883 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -1,14 +1,22 @@
#include "cru/ui/control.hpp"
#include "cru/platform/native/basic_types.hpp"
+#include "cru/platform/native/cursor.hpp"
+#include "cru/platform/native/native_window.hpp"
+#include "cru/platform/native/ui_applicaition.hpp"
#include "cru/ui/base.hpp"
#include "cru/ui/event/ui_event.hpp"
#include "cru/ui/window.hpp"
#include "routed_event_dispatch.hpp"
#include <cassert>
+#include <memory>
namespace cru::ui {
+using platform::native::Cursor;
+using platform::native::SystemCursor;
+using platform::native::UiApplication;
+
Control::Control() {
MouseEnterEvent()->Direct()->AddHandler(
[this](event::MouseEventArgs&) { this->is_mouse_over_ = true; });
@@ -69,18 +77,35 @@ bool Control::HasFocus() {
return window->GetFocusControl() == this;
}
-bool Control::CaptureMouse() {
- return GetWindow()->CaptureMouseFor(this);
-}
+bool Control::CaptureMouse() { return GetWindow()->CaptureMouseFor(this); }
-bool Control::ReleaseMouse() {
- return GetWindow()->CaptureMouseFor(nullptr);
-}
+bool Control::ReleaseMouse() { return GetWindow()->CaptureMouseFor(nullptr); }
bool Control::IsMouseCaptured() {
return GetWindow()->GetMouseCaptureControl() == this;
}
+std::shared_ptr<Cursor> Control::GetCursor() { return cursor_; }
+
+std::shared_ptr<Cursor> Control::GetInheritedCursor() {
+ Control* control = this;
+ while (control != nullptr) {
+ const auto cursor = control->GetCursor();
+ if (cursor != nullptr) return cursor;
+ control = control->GetParent();
+ }
+ return UiApplication::GetInstance()->GetCursorManager()->GetSystemCursor(
+ SystemCursor::Arrow);
+}
+
+void Control::SetCursor(std::shared_ptr<Cursor> cursor) {
+ cursor_ = std::move(cursor);
+ const auto window = GetWindow();
+ if (window != nullptr) {
+ window->UpdateCursor();
+ }
+}
+
void Control::OnParentChanged(Control* old_parent, Control* new_parent) {}
void Control::OnAttachToWindow(Window* window) {}