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,
};
class EventDispatch
class EventDispatcher
{
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:
void SetParent(EventDispatch *ie){parent_input_event=ie;}
void SetParent(EventDispatcher *ie){parent_input_event=ie;}
public:
@@ -53,9 +53,9 @@ namespace hgl::io
if(!RangeCheck(header.type))
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)
return EventProcResult::Break;
}
@@ -65,25 +65,25 @@ namespace hgl::io
public:
EventDispatch()
EventDispatcher()
{
source_type=InputEventSource::Root;
parent_input_event=nullptr;
}
EventDispatch(InputEventSource ies)
EventDispatcher(InputEventSource ies)
{
source_type=ies;
parent_input_event=nullptr;
}
virtual ~EventDispatch()
virtual ~EventDispatcher()
{
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)
return(false);
@@ -95,10 +95,10 @@ namespace hgl::io
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);
@@ -109,9 +109,9 @@ namespace hgl::io
ie->SetParent(nullptr);
return event_dispatch_subscribers.Delete(ie);
return event_subscribers.Delete(ie);
}
virtual bool Update(){return true;}
};//class EventDispatch
};//class EventDispatcher
}//namespace hgl::io

View File

@@ -1,7 +1,7 @@
#ifndef 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 io
@@ -158,11 +158,11 @@ namespace hgl
os_char ch;
};
class KeyboardEvent:public EventDispatch
class KeyboardEvent:public EventDispatcher
{
public:
KeyboardEvent():EventDispatch(InputEventSource::Keyboard){}
KeyboardEvent():EventDispatcher(InputEventSource::Keyboard){}
virtual ~KeyboardEvent()=default;
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::Continue;

View File

@@ -1,6 +1,6 @@
#pragma once
#include<hgl/io/event/EventDispatch.h>
#include<hgl/io/event/EventDispatcher.h>
#include<hgl/math/Vector.h>
namespace hgl::io
{
@@ -42,7 +42,7 @@ namespace hgl::io
constexpr size_t MouseEventDataBytes=sizeof(MouseEventData);
class MouseEvent:public EventDispatch
class MouseEvent:public EventDispatcher
{
MouseEventData *med;
@@ -52,7 +52,7 @@ namespace hgl::io
public:
MouseEvent():EventDispatch(InputEventSource::Mouse)
MouseEvent():EventDispatcher(InputEventSource::Mouse)
{
med=nullptr;
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::Continue;

View File

@@ -1,7 +1,7 @@
#ifndef 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 io
@@ -27,13 +27,13 @@ namespace hgl
constexpr size_t WindowEventDataBytes=sizeof(WindowEventData);
class WindowEvent:public EventDispatch
class WindowEvent:public EventDispatcher
{
WindowEventData *wed;
public:
WindowEvent():EventDispatch(InputEventSource::Window){wed=nullptr;}
WindowEvent():EventDispatcher(InputEventSource::Window){wed=nullptr;}
virtual ~WindowEvent()=default;
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::Continue;
@@ -61,7 +61,7 @@ namespace hgl
virtual void OnResize(uint w,uint h){}
virtual void OnActive(bool){}
virtual void OnClose (){}
};//class WindowEvent:public EventDispatch
};//class WindowEvent:public EventDispatcher
}//namespace io
}//namespace hgl
#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
${IO_INCLUDE_PATH}/event/MouseEvent.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
)