aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-04-04 18:23:00 +0800
committercrupest <crupest@outlook.com>2019-04-04 18:23:00 +0800
commitdbda5a8e4f0d59ad95be8fc3ee7b21e9122cc474 (patch)
treec8426a7aa086bf69b54b91328af0c160f933fa49
parent4d650160a388b0192e04c454ba1a3de21b0d4cc3 (diff)
downloadcru-dbda5a8e4f0d59ad95be8fc3ee7b21e9122cc474.tar.gz
cru-dbda5a8e4f0d59ad95be8fc3ee7b21e9122cc474.tar.bz2
cru-dbda5a8e4f0d59ad95be8fc3ee7b21e9122cc474.zip
...
-rw-r--r--include/cru/common/event.hpp6
-rw-r--r--include/cru/ui/window.hpp2
-rw-r--r--src/ui/window.cpp26
3 files changed, 24 insertions, 10 deletions
diff --git a/include/cru/common/event.hpp b/include/cru/common/event.hpp
index 52d75a7b..763f8378 100644
--- a/include/cru/common/event.hpp
+++ b/include/cru/common/event.hpp
@@ -57,6 +57,12 @@ class Event {
return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token));
}
+ EventHandlerRevoker AddHandler(EventHandler&& handler) {
+ const auto token = current_token_++;
+ handlers_.emplace(token, std::move(handler));
+ return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token));
+ }
+
template <typename... Args>
EventHandlerRevoker AddHandler(Args&& args...) {
const auto token = current_token_++;
diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp
index f0c790be..94deb4c5 100644
--- a/include/cru/ui/window.hpp
+++ b/include/cru/ui/window.hpp
@@ -64,8 +64,8 @@ class Window final : public ContentControl {
void OnNativeFocus(bool focus);
+ void OnNativeMouseEnterLeave(bool enter);
void OnNativeMouseMove(const Point& point);
- void OnNativeMouseLeave();
void OnNativeMouseDown(platform::MouseButton button, const Point& point);
void OnNativeMouseUp(platform::MouseButton button, const Point& point);
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index bad704ae..c0ee1a83 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -104,10 +104,16 @@ Window::Window(tag_overlapped_constructor) {
render_object_.reset(new render::WindowRenderObject(this));
event_revokers_.push_back(native_window_->DestroyEvent()->AddHandler(
- this, Window::OnNativeDestroy));
- event_revokers_.push_back(
- native_window_->PaintEvent()->AddHandler(this, Window::OnNativePaint));
- //TODO
+ std::bind(&Window::OnNativeDestroy, this)));
+ event_revokers_.push_back(native_window_->PaintEvent()->AddHandler(
+ std::bind(&Window::OnNativePaint, this)));
+ event_revokers_.push_back(native_window_->ResizeEvent()->AddHandler(
+ std::bind(&Window::OnNativeResize, this)));
+ event_revokers_.push_back(native_window_->FocusEvent()->AddHandler(
+ std::bind(&Window::OnNativeFocus, this)));
+ event_revokers_.push_back(native_window_->FocusEvent()->AddHandler(
+ std::bind(&Window::OnNativeFocus, this)));
+ //TODO!
}
Window::~Window() {
@@ -166,6 +172,13 @@ void Window::OnNativeFocus(bool focus) {
: DispatchEvent(focus_control_, &Control::LoseFocusEvent, nullptr, true);
}
+void Window::OnNativeMouseEnterLeave(bool enter) {
+ if (!enter) {
+ DispatchEvent(mouse_hover_control_, &Control::MouseLeaveEvent, nullptr);
+ mouse_hover_control_ = nullptr;
+ }
+}
+
void Window::OnNativeMouseMove(const Point& point) {
// Find the first control that hit test succeed.
const auto new_control_mouse_hover = HitTest(point);
@@ -178,11 +191,6 @@ void Window::OnNativeMouseMove(const Point& point) {
point);
}
-void Window::OnNativeMouseLeave() {
- DispatchEvent(mouse_hover_control_, &Control::MouseLeaveEvent, nullptr);
- mouse_hover_control_ = nullptr;
-}
-
void Window::OnNativeMouseDown(platform::MouseButton button,
const Point& point) {
Control* control = HitTest(point);