From 9eabdaf1d1bca692b2b0c9755d7661274493a0c8 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 27 Jun 2025 02:58:00 +0800 Subject: [PATCH] =?UTF-8?q?InputEvent=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E3=80=81=E5=8F=98=E9=87=8F=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/io/event/InputEvent.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/inc/hgl/io/event/InputEvent.h b/inc/hgl/io/event/InputEvent.h index 1541a2e..df73bbc 100644 --- a/inc/hgl/io/event/InputEvent.h +++ b/inc/hgl/io/event/InputEvent.h @@ -2,13 +2,14 @@ #include #include + namespace hgl::io { struct EventHeader { - InputEventSource type; ///<输入源类型 - uint8 index; ///<输入源索引(比如同一设备有多个) - uint16 id; ///<事件id + InputEventSource type; ///<输入源类型 + uint8 index; ///<输入源索引(比如同一设备有多个) + uint16 id; ///<事件id }; constexpr size_t EventHeaderBytes=sizeof(EventHeader); @@ -26,11 +27,13 @@ namespace hgl::io { protected: - InputEventSource source_type; + InputEventSource source_type; - InputEvent *parent_input_event; + InputEvent * parent_input_event; - SortedSet sub_event_proc; + SortedSet event_dispatch_subscribers; + + protected: void SetParent(InputEvent *ie){parent_input_event=ie;} @@ -43,9 +46,9 @@ namespace hgl::io if(!RangeCheck(header.type)) return(EventProcResult::Break); - if(!sub_event_proc.IsEmpty()) + if(!event_dispatch_subscribers.IsEmpty()) { - for(InputEvent *ie:sub_event_proc) + for(InputEvent *ie:event_dispatch_subscribers) if(ie->OnEvent(header,data)==EventProcResult::Break) return EventProcResult::Break; } @@ -70,10 +73,10 @@ namespace hgl::io virtual ~InputEvent() { if(parent_input_event) - parent_input_event->Unjoin(this); + parent_input_event->UnregistryEventDispatch(this); } - virtual bool Join(InputEvent *ie) + virtual bool RegistryEventDispatch(InputEvent *ie) { if(!ie) return(false); @@ -85,10 +88,10 @@ namespace hgl::io ie->SetParent(this); - return(sub_event_proc.Add(ie)!=-1); + return(event_dispatch_subscribers.Add(ie)!=-1); } - bool Unjoin(InputEvent *ie) + bool UnregistryEventDispatch(InputEvent *ie) { if(!ie)return(false); @@ -99,7 +102,7 @@ namespace hgl::io ie->SetParent(nullptr); - return sub_event_proc.Delete(ie); + return event_dispatch_subscribers.Delete(ie); } virtual bool Update(){return true;}