重新命名EventDispatcher的添加/解决函数
This commit is contained in:
@@ -30,6 +30,9 @@ namespace hgl::io
|
|||||||
Break,
|
Break,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件分发器
|
||||||
|
*/
|
||||||
class EventDispatcher
|
class EventDispatcher
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@@ -38,7 +41,7 @@ namespace hgl::io
|
|||||||
|
|
||||||
EventDispatcher * parent_input_event;
|
EventDispatcher * parent_input_event;
|
||||||
|
|
||||||
SortedSet<EventDispatcher *> event_subscribers;
|
SortedSet<EventDispatcher *> child_dispatchers;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -53,9 +56,9 @@ namespace hgl::io
|
|||||||
if(!RangeCheck(header.type))
|
if(!RangeCheck(header.type))
|
||||||
return(EventProcResult::Break);
|
return(EventProcResult::Break);
|
||||||
|
|
||||||
if(!event_subscribers.IsEmpty())
|
if(!child_dispatchers.IsEmpty())
|
||||||
{
|
{
|
||||||
for(EventDispatcher *ie:event_subscribers)
|
for(EventDispatcher *ie:child_dispatchers)
|
||||||
if(ie->OnEvent(header,data)==EventProcResult::Break)
|
if(ie->OnEvent(header,data)==EventProcResult::Break)
|
||||||
return EventProcResult::Break;
|
return EventProcResult::Break;
|
||||||
}
|
}
|
||||||
@@ -80,37 +83,11 @@ namespace hgl::io
|
|||||||
virtual ~EventDispatcher()
|
virtual ~EventDispatcher()
|
||||||
{
|
{
|
||||||
if(parent_input_event)
|
if(parent_input_event)
|
||||||
parent_input_event->UnsubscribeEventDispatcher(this);
|
parent_input_event->RemoveChildDispatcher(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool SubscribeEventDispatcher(EventDispatcher *ie)
|
virtual bool AddChildDispatcher(EventDispatcher *ie);
|
||||||
{
|
virtual bool RemoveChildDispatcher(EventDispatcher *ie);
|
||||||
if(!ie)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
const InputEventSource ies=ie->GetInputEventSource();
|
|
||||||
|
|
||||||
if(!RangeCheck(ies))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
ie->SetParent(this);
|
|
||||||
|
|
||||||
return(event_subscribers.Add(ie)!=-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UnsubscribeEventDispatcher(EventDispatcher *ie)
|
|
||||||
{
|
|
||||||
if(!ie)return(false);
|
|
||||||
|
|
||||||
const InputEventSource ies=ie->GetInputEventSource();
|
|
||||||
|
|
||||||
if(!RangeCheck(ies))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
ie->SetParent(nullptr);
|
|
||||||
|
|
||||||
return event_subscribers.Delete(ie);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Update(){return true;}
|
virtual bool Update(){return true;}
|
||||||
};//class EventDispatcher
|
};//class EventDispatcher
|
||||||
|
@@ -44,55 +44,18 @@ namespace hgl::io
|
|||||||
|
|
||||||
class MouseEvent:public EventDispatcher
|
class MouseEvent:public EventDispatcher
|
||||||
{
|
{
|
||||||
MouseEventData *med;
|
MouseEventData *med=nullptr;
|
||||||
|
|
||||||
Vector2i position;
|
Vector2i position{};
|
||||||
|
|
||||||
bool pressed_statues[size_t(MouseButton::RANGE_SIZE)];
|
bool pressed_statues[size_t(MouseButton::RANGE_SIZE)]{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MouseEvent():EventDispatcher(InputEventSource::Mouse)
|
MouseEvent():EventDispatcher(InputEventSource::Mouse){}
|
||||||
{
|
|
||||||
med=nullptr;
|
|
||||||
position.x=0;
|
|
||||||
position.y=0;;
|
|
||||||
hgl_zero(pressed_statues);
|
|
||||||
}
|
|
||||||
virtual ~MouseEvent()=default;
|
virtual ~MouseEvent()=default;
|
||||||
|
|
||||||
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
|
virtual EventProcResult OnEvent (const EventHeader &header,const uint64 data) override;
|
||||||
{
|
|
||||||
if(header.type==InputEventSource::Mouse)
|
|
||||||
{
|
|
||||||
med=(MouseEventData *)&data;
|
|
||||||
|
|
||||||
if(MouseEventID(header.id)==MouseEventID::Wheel)
|
|
||||||
{
|
|
||||||
if(OnWheel (med->x,med->y) )return EventProcResult::Break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
position.x=med->x;
|
|
||||||
position.y=med->y;
|
|
||||||
|
|
||||||
switch(MouseEventID(header.id))
|
|
||||||
{
|
|
||||||
case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break;
|
|
||||||
case MouseEventID::Pressed: pressed_statues[med->button]=true;
|
|
||||||
if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
|
||||||
case MouseEventID::Released: pressed_statues[med->button]=false;
|
|
||||||
if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
|
||||||
case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
|
|
||||||
return EventProcResult::Break;
|
|
||||||
|
|
||||||
return EventProcResult::Continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool OnMove (int,int){return false;}
|
virtual bool OnMove (int,int){return false;}
|
||||||
virtual bool OnWheel (int,int){return false;}
|
virtual bool OnWheel (int,int){return false;}
|
||||||
|
@@ -195,6 +195,8 @@ SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h
|
|||||||
${IO_INCLUDE_PATH}/event/JoystickEvent.h
|
${IO_INCLUDE_PATH}/event/JoystickEvent.h
|
||||||
${IO_INCLUDE_PATH}/event/EventDispatcher.h
|
${IO_INCLUDE_PATH}/event/EventDispatcher.h
|
||||||
${IO_INCLUDE_PATH}/event/InputMapping.h
|
${IO_INCLUDE_PATH}/event/InputMapping.h
|
||||||
|
IO/Event/MouseEvent.cpp
|
||||||
|
IO/Event/EventDispatcher.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SOURCE_GROUP("IO\\Event" FILES ${INPUT_EVENT_FILES})
|
SOURCE_GROUP("IO\\Event" FILES ${INPUT_EVENT_FILES})
|
||||||
@@ -247,10 +249,10 @@ SOURCE_GROUP("Thread" FILES ${BASE_THREAD_HEADER_FILES}
|
|||||||
${BASE_THREAD_SOURCE_FILES})
|
${BASE_THREAD_SOURCE_FILES})
|
||||||
|
|
||||||
FILE(GLOB BASE_EVENT_HEADER_FILES ${CMCORE_ROOT_INCLUDE_PATH}/hgl/event/*.*)
|
FILE(GLOB BASE_EVENT_HEADER_FILES ${CMCORE_ROOT_INCLUDE_PATH}/hgl/event/*.*)
|
||||||
FILE(GLOB BASE_EVENT_SOURCE_FILES Event/*.*)
|
#FILE(GLOB BASE_EVENT_SOURCE_FILES Event/*.*)
|
||||||
|
|
||||||
SOURCE_GROUP("Event" FILES ${BASE_EVENT_HEADER_FILES}
|
SOURCE_GROUP("Event" FILES ${BASE_EVENT_HEADER_FILES})
|
||||||
${BASE_EVENT_SOURCE_FILES})
|
#${BASE_EVENT_SOURCE_FILES})
|
||||||
|
|
||||||
file(GLOB BASE_PLUG_IN_HEADER ${CMCORE_ROOT_INCLUDE_PATH}/hgl/plugin/*.h)
|
file(GLOB BASE_PLUG_IN_HEADER ${CMCORE_ROOT_INCLUDE_PATH}/hgl/plugin/*.h)
|
||||||
file(GLOB BASE_PLUG_IN_SOURCE PlugIn/*.cpp)
|
file(GLOB BASE_PLUG_IN_SOURCE PlugIn/*.cpp)
|
||||||
|
33
src/IO/Event/EventDispatcher.cpp
Normal file
33
src/IO/Event/EventDispatcher.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include<hgl/io/event/EventDispatcher.h>
|
||||||
|
|
||||||
|
namespace hgl::io
|
||||||
|
{
|
||||||
|
bool EventDispatcher::AddChildDispatcher(EventDispatcher *ie)
|
||||||
|
{
|
||||||
|
if(!ie)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
const InputEventSource ies=ie->GetInputEventSource();
|
||||||
|
|
||||||
|
if(!RangeCheck(ies))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
ie->SetParent(this);
|
||||||
|
|
||||||
|
return(child_dispatchers.Add(ie)!=-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EventDispatcher::RemoveChildDispatcher(EventDispatcher *ie)
|
||||||
|
{
|
||||||
|
if(!ie)return(false);
|
||||||
|
|
||||||
|
const InputEventSource ies=ie->GetInputEventSource();
|
||||||
|
|
||||||
|
if(!RangeCheck(ies))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
ie->SetParent(nullptr);
|
||||||
|
|
||||||
|
return child_dispatchers.Delete(ie);
|
||||||
|
}
|
||||||
|
}//namespace hgl::io
|
37
src/IO/Event/MouseEvent.cpp
Normal file
37
src/IO/Event/MouseEvent.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include<hgl/io/event/MouseEvent.h>
|
||||||
|
|
||||||
|
namespace hgl::io
|
||||||
|
{
|
||||||
|
EventProcResult MouseEvent::OnEvent(const EventHeader &header,const uint64 data)
|
||||||
|
{
|
||||||
|
if(header.type==InputEventSource::Mouse)
|
||||||
|
{
|
||||||
|
med=(MouseEventData *)&data;
|
||||||
|
|
||||||
|
if(MouseEventID(header.id)==MouseEventID::Wheel)
|
||||||
|
{
|
||||||
|
if(OnWheel (med->x,med->y) )return EventProcResult::Break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
position.x=med->x;
|
||||||
|
position.y=med->y;
|
||||||
|
|
||||||
|
switch(MouseEventID(header.id))
|
||||||
|
{
|
||||||
|
case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break;
|
||||||
|
case MouseEventID::Pressed: pressed_statues[med->button]=true;
|
||||||
|
if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
||||||
|
case MouseEventID::Released: pressed_statues[med->button]=false;
|
||||||
|
if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
||||||
|
case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
|
||||||
|
return EventProcResult::Break;
|
||||||
|
|
||||||
|
return EventProcResult::Continue;
|
||||||
|
}
|
||||||
|
}//namespace hgl::io
|
Reference in New Issue
Block a user