diff options
author | 杨宇千 <crupest@outlook.com> | 2019-09-08 19:09:38 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-09-08 19:09:38 +0800 |
commit | 8b9a306d6f24dbc08aeee16b115260406e79126d (patch) | |
tree | db37b8c3441a28b7150b1f40ddf79c7fa9dcda79 /include | |
parent | 2c40085dd30d6e7370a0974ad1f642a61acc6e30 (diff) | |
download | cru-8b9a306d6f24dbc08aeee16b115260406e79126d.tar.gz cru-8b9a306d6f24dbc08aeee16b115260406e79126d.tar.bz2 cru-8b9a306d6f24dbc08aeee16b115260406e79126d.zip |
...
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/ui/control.hpp | 26 | ||||
-rw-r--r-- | include/cru/ui/window.hpp | 23 |
2 files changed, 44 insertions, 5 deletions
diff --git a/include/cru/ui/control.hpp b/include/cru/ui/control.hpp index f312272e..cf4f9053 100644 --- a/include/cru/ui/control.hpp +++ b/include/cru/ui/control.hpp @@ -3,8 +3,10 @@ #include "cru/common/base.hpp" #include "cru/platform/native/basic_types.hpp" +#include "cru/platform/native/cursor.hpp" #include "event/ui_event.hpp" +#include <memory> #include <string_view> #include <vector> @@ -68,13 +70,31 @@ class Control : public Object { bool IsMouseCaptured(); + //*************** region: cursor *************** + // Cursor is inherited from parent recursively if not set. + public: + // null for not set + std::shared_ptr<platform::native::Cursor> GetCursor(); + + // will not return nullptr + std::shared_ptr<platform::native::Cursor> GetInheritedCursor(); + + // null to unset + void SetCursor(std::shared_ptr<platform::native::Cursor> cursor); + //*************** region: events *************** public: - // Raised when mouse enter the control. + // Raised when mouse enter the control. Even when the control itself captures + // the mouse, this event is raised as regular. But if mouse is captured by + // another control, the control will not receive any mouse enter event. You + // can use `IsMouseCaptured` to get more info. event::RoutedEvent<event::MouseEventArgs>* MouseEnterEvent() { return &mouse_enter_event_; } - // Raised when mouse is leave the control. + // Raised when mouse is leave the control. Even when the control itself + // captures the mouse, this event is raised as regular. But if mouse is + // captured by another control, the control will not receive any mouse leave + // event. You can use `IsMouseCaptured` to get more info. event::RoutedEvent<event::MouseEventArgs>* MouseLeaveEvent() { return &mouse_leave_event_; } @@ -142,5 +162,7 @@ class Control : public Object { bool middle; bool right; } click_map_; + + std::shared_ptr<platform::native::Cursor> cursor_ = nullptr; }; } // namespace cru::ui diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp index ee6d2176..1325100f 100644 --- a/include/cru/ui/window.hpp +++ b/include/cru/ui/window.hpp @@ -18,6 +18,8 @@ class WindowRenderObject; } class Window final : public ContentControl, public SelfResolvable<Window> { + friend class Control; + public: static constexpr auto control_type = L"Window"; @@ -45,6 +47,10 @@ class Window final : public ContentControl, public SelfResolvable<Window> { return native_window_; } + // Get current control that mouse hovers on. This ignores the mouse-capture + // control. Even when mouse is captured by another control, this function + // return the control under cursor. You can use `GetMouseCaptureControl` to + // get more info. Control* GetMouseHoverControl() const { return mouse_hover_control_; } //*************** region: layout *************** @@ -62,7 +68,16 @@ class Window final : public ContentControl, public SelfResolvable<Window> { //*************** region: focus *************** - // Pass nullptr to release capture. + // Pass nullptr to release capture. If mouse is already capture by a control, + // this capture will fail and return false. If control is identical to the + // capturing control, capture is not changed and this function will return + // true. + // + // When capturing control changes, + // appropriate event will be sent. If mouse is not on the capturing control + // and capture is released, mouse enter event will be sent to the mouse-hover + // control. If mouse is not on the capturing control and capture is set, mouse + // leave event will be sent to the mouse-hover control. bool CaptureMouseFor(Control* control); // Return null if not captured. @@ -94,10 +109,12 @@ class Window final : public ContentControl, public SelfResolvable<Window> { //*************** region: event dispatcher helper *************** - // dispatch enter is useful when mouse is captured. void DispatchMouseHoverControlChangeEvent(Control* old_control, Control* new_control, - const Point& point); + const Point& point, bool no_leave, + bool no_enter); + + void UpdateCursor(); private: platform::native::NativeWindow* native_window_; |