aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-11 23:27:16 +0800
committer杨宇千 <crupest@outlook.com>2019-08-11 23:27:16 +0800
commit86e776eaebf7c45a269001ca7da0dfafba069d0a (patch)
tree64c0544d9839562a6fc6d08ea00682a94c5d222b /include/cru
parent99a322a6badf5b6d95be4944e80d92fc1cb2589e (diff)
downloadcru-86e776eaebf7c45a269001ca7da0dfafba069d0a.tar.gz
cru-86e776eaebf7c45a269001ca7da0dfafba069d0a.tar.bz2
cru-86e776eaebf7c45a269001ca7da0dfafba069d0a.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/platform/native/native_window.hpp6
-rw-r--r--include/cru/ui/window.hpp11
-rw-r--r--include/cru/win/native/native_window.hpp5
3 files changed, 22 insertions, 0 deletions
diff --git a/include/cru/platform/native/native_window.hpp b/include/cru/platform/native/native_window.hpp
index 22a2dce0..b557a0dd 100644
--- a/include/cru/platform/native/native_window.hpp
+++ b/include/cru/platform/native/native_window.hpp
@@ -56,6 +56,12 @@ class NativeWindow : public NativeResource {
// The lefttop of the rect is relative to screen lefttop.
virtual void SetWindowRect(const Rect& rect) = 0;
+ // Relative to client lefttop.
+ virtual Point GetMousePosition() = 0;
+
+ virtual bool CaptureMouse() = 0;
+ virtual bool ReleaseMouse() = 0;
+
virtual graph::Painter* BeginPaint() = 0;
virtual IEvent<std::nullptr_t>* DestroyEvent() = 0;
diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp
index 197198d2..ee6d2176 100644
--- a/include/cru/ui/window.hpp
+++ b/include/cru/ui/window.hpp
@@ -60,6 +60,14 @@ class Window final : public ContentControl, public SelfResolvable<Window> {
// Get the control that has focus.
Control* GetFocusControl();
+ //*************** region: focus ***************
+
+ // Pass nullptr to release capture.
+ bool CaptureMouseFor(Control* control);
+
+ // Return null if not captured.
+ Control* GetMouseCaptureControl();
+
protected:
void OnChildChanged(Control* old_child, Control* new_child) override;
@@ -86,6 +94,7 @@ 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);
@@ -100,6 +109,8 @@ class Window final : public ContentControl, public SelfResolvable<Window> {
Control* focus_control_; // "focus_control_" can't be nullptr
+ Control* mouse_captured_control_;
+
bool need_layout_ = false;
};
} // namespace cru::ui
diff --git a/include/cru/win/native/native_window.hpp b/include/cru/win/native/native_window.hpp
index ed678591..b044aef8 100644
--- a/include/cru/win/native/native_window.hpp
+++ b/include/cru/win/native/native_window.hpp
@@ -48,6 +48,11 @@ class WinNativeWindow : public NativeWindow {
// The lefttop of the rect is relative to screen lefttop.
void SetWindowRect(const Rect& rect) override;
+ Point GetMousePosition() override;
+
+ bool CaptureMouse() override;
+ bool ReleaseMouse() override;
+
graph::Painter* BeginPaint() override;
IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; }