From f78458173c1baf567cc96880571b380e95a1039a Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 28 Nov 2018 19:18:00 +0800 Subject: Refactor event system. --- src/ui/window.hpp | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) (limited to 'src/ui/window.hpp') diff --git a/src/ui/window.hpp b/src/ui/window.hpp index e82aa585..d7301eb5 100644 --- a/src/ui/window.hpp +++ b/src/ui/window.hpp @@ -4,6 +4,7 @@ #include "pre.hpp" #include "system_headers.hpp" +#include #include #include @@ -241,10 +242,10 @@ namespace cru::ui public: //*************** region: events *************** - events::UiEvent activated_event; - events::UiEvent deactivated_event; - - events::WindowNativeMessageEvent native_message_event; + Event activated_event; + Event deactivated_event; + + Event native_message_event; private: //*************** region: native operations *************** @@ -281,30 +282,6 @@ namespace cru::ui //*************** region: event dispatcher helper *************** - template - using EventMethod = void (Control::*)(EventArgs&); - - // Dispatch the event. - // - // This will invoke the "event_method" of the control and its parent and parent's - // parent ... (until "last_receiver" if it's not nullptr) with appropriate args. - // - // Args is of type "EventArgs". The first init argument is "sender", which is - // automatically bound to each receiving control. The second init argument is - // "original_sender", which is unchanged. And "args" will be perfectly forwarded - // as the rest arguments. - template - void DispatchEvent(Control* original_sender, EventMethod event_method, Control* last_receiver, Args&&... args) - { - auto control = original_sender; - while (control != nullptr && control != last_receiver) - { - EventArgs event_args(control, original_sender, std::forward(args)...); - (control->*event_method)(event_args); - control = control->GetParent(); - } - } - void DispatchMouseHoverControlChangeEvent(Control* old_control, Control * new_control, const Point& point); private: -- cgit v1.2.3