EventDispatcht重命名

This commit is contained in:
2025-07-16 02:12:44 +08:00
parent a9e37e6219
commit 1862d04529
5 changed files with 30 additions and 30 deletions

View File

@@ -30,19 +30,19 @@ namespace hgl::io
Break, Break,
}; };
class EventDispatch class EventDispatcher
{ {
protected: protected:
InputEventSource source_type; InputEventSource source_type;
EventDispatch * parent_input_event; EventDispatcher * parent_input_event;
SortedSet<EventDispatch *> event_dispatch_subscribers; SortedSet<EventDispatcher *> event_subscribers;
protected: protected:
void SetParent(EventDispatch *ie){parent_input_event=ie;} void SetParent(EventDispatcher *ie){parent_input_event=ie;}
public: public:
@@ -53,9 +53,9 @@ namespace hgl::io
if(!RangeCheck(header.type)) if(!RangeCheck(header.type))
return(EventProcResult::Break); return(EventProcResult::Break);
if(!event_dispatch_subscribers.IsEmpty()) if(!event_subscribers.IsEmpty())
{ {
for(EventDispatch *ie:event_dispatch_subscribers) for(EventDispatcher *ie:event_subscribers)
if(ie->OnEvent(header,data)==EventProcResult::Break) if(ie->OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break; return EventProcResult::Break;
} }
@@ -65,25 +65,25 @@ namespace hgl::io
public: public:
EventDispatch() EventDispatcher()
{ {
source_type=InputEventSource::Root; source_type=InputEventSource::Root;
parent_input_event=nullptr; parent_input_event=nullptr;
} }
EventDispatch(InputEventSource ies) EventDispatcher(InputEventSource ies)
{ {
source_type=ies; source_type=ies;
parent_input_event=nullptr; parent_input_event=nullptr;
} }
virtual ~EventDispatch() virtual ~EventDispatcher()
{ {
if(parent_input_event) if(parent_input_event)
parent_input_event->UnregisterEventDispatch(this); parent_input_event->UnsubscribeEventDispatcher(this);
} }
virtual bool RegisterEventDispatch(EventDispatch *ie) virtual bool SubscribeEventDispatcher(EventDispatcher *ie)
{ {
if(!ie) if(!ie)
return(false); return(false);
@@ -95,10 +95,10 @@ namespace hgl::io
ie->SetParent(this); ie->SetParent(this);
return(event_dispatch_subscribers.Add(ie)!=-1); return(event_subscribers.Add(ie)!=-1);
} }
bool UnregisterEventDispatch(EventDispatch *ie) bool UnsubscribeEventDispatcher(EventDispatcher *ie)
{ {
if(!ie)return(false); if(!ie)return(false);
@@ -109,9 +109,9 @@ namespace hgl::io
ie->SetParent(nullptr); ie->SetParent(nullptr);
return event_dispatch_subscribers.Delete(ie); return event_subscribers.Delete(ie);
} }
virtual bool Update(){return true;} virtual bool Update(){return true;}
};//class EventDispatch };//class EventDispatcher
}//namespace hgl::io }//namespace hgl::io

View File

@@ -1,7 +1,7 @@
#ifndef HGL_IO_KEYBOARD_EVENT_INCLUDE #ifndef HGL_IO_KEYBOARD_EVENT_INCLUDE
#define HGL_IO_KEYBOARD_EVENT_INCLUDE #define HGL_IO_KEYBOARD_EVENT_INCLUDE
#include<hgl/io/event/EventDispatch.h> #include<hgl/io/event/EventDispatcher.h>
namespace hgl namespace hgl
{ {
namespace io namespace io
@@ -158,11 +158,11 @@ namespace hgl
os_char ch; os_char ch;
}; };
class KeyboardEvent:public EventDispatch class KeyboardEvent:public EventDispatcher
{ {
public: public:
KeyboardEvent():EventDispatch(InputEventSource::Keyboard){} KeyboardEvent():EventDispatcher(InputEventSource::Keyboard){}
virtual ~KeyboardEvent()=default; virtual ~KeyboardEvent()=default;
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
@@ -177,7 +177,7 @@ namespace hgl
} }
} }
if(EventDispatch::OnEvent(header,data)==EventProcResult::Break) if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break; return EventProcResult::Break;
return EventProcResult::Continue; return EventProcResult::Continue;

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include<hgl/io/event/EventDispatch.h> #include<hgl/io/event/EventDispatcher.h>
#include<hgl/math/Vector.h> #include<hgl/math/Vector.h>
namespace hgl::io namespace hgl::io
{ {
@@ -42,7 +42,7 @@ namespace hgl::io
constexpr size_t MouseEventDataBytes=sizeof(MouseEventData); constexpr size_t MouseEventDataBytes=sizeof(MouseEventData);
class MouseEvent:public EventDispatch class MouseEvent:public EventDispatcher
{ {
MouseEventData *med; MouseEventData *med;
@@ -52,7 +52,7 @@ namespace hgl::io
public: public:
MouseEvent():EventDispatch(InputEventSource::Mouse) MouseEvent():EventDispatcher(InputEventSource::Mouse)
{ {
med=nullptr; med=nullptr;
position.x=0; position.x=0;
@@ -88,7 +88,7 @@ namespace hgl::io
} }
} }
if(EventDispatch::OnEvent(header,data)==EventProcResult::Break) if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break; return EventProcResult::Break;
return EventProcResult::Continue; return EventProcResult::Continue;

View File

@@ -1,7 +1,7 @@
#ifndef HGL_IO_WINDOW_EVENT_INCLUDE #ifndef HGL_IO_WINDOW_EVENT_INCLUDE
#define HGL_IO_WINDOW_EVENT_INCLUDE #define HGL_IO_WINDOW_EVENT_INCLUDE
#include<hgl/io/event/EventDispatch.h> #include<hgl/io/event/EventDispatcher.h>
namespace hgl namespace hgl
{ {
namespace io namespace io
@@ -27,13 +27,13 @@ namespace hgl
constexpr size_t WindowEventDataBytes=sizeof(WindowEventData); constexpr size_t WindowEventDataBytes=sizeof(WindowEventData);
class WindowEvent:public EventDispatch class WindowEvent:public EventDispatcher
{ {
WindowEventData *wed; WindowEventData *wed;
public: public:
WindowEvent():EventDispatch(InputEventSource::Window){wed=nullptr;} WindowEvent():EventDispatcher(InputEventSource::Window){wed=nullptr;}
virtual ~WindowEvent()=default; virtual ~WindowEvent()=default;
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data) override virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
@@ -50,7 +50,7 @@ namespace hgl
} }
} }
if(EventDispatch::OnEvent(header,data)==EventProcResult::Break) if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
return EventProcResult::Break; return EventProcResult::Break;
return EventProcResult::Continue; return EventProcResult::Continue;
@@ -61,7 +61,7 @@ namespace hgl
virtual void OnResize(uint w,uint h){} virtual void OnResize(uint w,uint h){}
virtual void OnActive(bool){} virtual void OnActive(bool){}
virtual void OnClose (){} virtual void OnClose (){}
};//class WindowEvent:public EventDispatch };//class WindowEvent:public EventDispatcher
}//namespace io }//namespace io
}//namespace hgl }//namespace hgl
#endif//HGL_IO_WINDOW_EVENT_INCLUDE #endif//HGL_IO_WINDOW_EVENT_INCLUDE

View File

@@ -193,7 +193,7 @@ SET(IO_TEXT_FILES IO/TextOutputStream.cpp
SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h
${IO_INCLUDE_PATH}/event/MouseEvent.h ${IO_INCLUDE_PATH}/event/MouseEvent.h
${IO_INCLUDE_PATH}/event/JoystickEvent.h ${IO_INCLUDE_PATH}/event/JoystickEvent.h
${IO_INCLUDE_PATH}/event/EventDispatch.h ${IO_INCLUDE_PATH}/event/EventDispatcher.h
${IO_INCLUDE_PATH}/event/InputMapping.h ${IO_INCLUDE_PATH}/event/InputMapping.h
) )