added files of io/event
This commit is contained in:
104
inc/hgl/io/event/InputEvent.h
Normal file
104
inc/hgl/io/event/InputEvent.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef HGL_IO_INPUT_EVENT_INCLUDE
|
||||
#define HGL_IO_INPUT_EVENT_INCLUDE
|
||||
|
||||
#include<hgl/type/Sets.h>
|
||||
#include<hgl/io/event/InputEventSource.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
struct EventHeader
|
||||
{
|
||||
uint8 type; ///<<3C><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
||||
uint8 index; ///<<3C><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>ͬһ<CDAC>豸<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>)
|
||||
uint16 id; ///<<3C>¼<EFBFBD>id
|
||||
};
|
||||
|
||||
constexpr size_t EventHeaderBytes=sizeof(EventHeader);
|
||||
|
||||
/**
|
||||
* <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
enum class EventProcResult
|
||||
{
|
||||
Continue,
|
||||
Break,
|
||||
};
|
||||
|
||||
class InputEvent
|
||||
{
|
||||
protected:
|
||||
|
||||
InputEventSource source_type;
|
||||
|
||||
Sets<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
|
||||
|
||||
public:
|
||||
|
||||
const InputEventSource GetInputEventSource()const{return source_type;}
|
||||
|
||||
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data)
|
||||
{
|
||||
if(!RangeCheck((InputEventSource)header.type))
|
||||
return(EventProcResult::Break);
|
||||
|
||||
if(sub_event_proc[header.type].GetCount()>0)
|
||||
{
|
||||
for(InputEvent *ie:sub_event_proc[header.type])
|
||||
if(ie->OnEvent(header,data)==EventProcResult::Break)
|
||||
return EventProcResult::Break;
|
||||
|
||||
if(sub_event_proc[size_t(InputEventSource::Root)].GetCount()>0
|
||||
&&InputEventSource(header.type)!=InputEventSource::Root)
|
||||
{
|
||||
for(InputEvent *ie:sub_event_proc[size_t(InputEventSource::Root)])
|
||||
if(ie->OnEvent(header,data)==EventProcResult::Break)
|
||||
return EventProcResult::Break;
|
||||
}
|
||||
}
|
||||
|
||||
return(EventProcResult::Continue);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
InputEvent()
|
||||
{
|
||||
source_type=InputEventSource::Root;
|
||||
}
|
||||
|
||||
InputEvent(InputEventSource ies)
|
||||
{
|
||||
source_type=ies;
|
||||
}
|
||||
|
||||
virtual ~InputEvent()=default;
|
||||
|
||||
virtual bool Join(InputEvent *ie)
|
||||
{
|
||||
if(!ie)
|
||||
return(false);
|
||||
|
||||
const InputEventSource ies=ie->GetInputEventSource();
|
||||
|
||||
if(!RangeCheck(ies))
|
||||
return(false);
|
||||
|
||||
return(sub_event_proc[size_t(ies)].Add(ie)!=-1);
|
||||
}
|
||||
|
||||
bool Unjoin(InputEvent *ie)
|
||||
{
|
||||
if(!ie)return(false);
|
||||
|
||||
const InputEventSource ies=ie->GetInputEventSource();
|
||||
|
||||
if(!RangeCheck(ies))
|
||||
return(false);
|
||||
|
||||
return sub_event_proc[size_t(ies)].Delete(ie);
|
||||
}
|
||||
};//class InputEvent
|
||||
}//namespace io
|
||||
}//namespace hgl
|
||||
#endif//HGL_IO_INPUT_EVENT_INCLUDE
|
Reference in New Issue
Block a user