Layout codes of InputEvent/WindowEvent
This commit is contained in:
parent
3f5baa99d0
commit
b78d31d8a0
@ -1,104 +1,99 @@
|
||||
#ifndef HGL_IO_INPUT_EVENT_INCLUDE
|
||||
#define HGL_IO_INPUT_EVENT_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/SortedSet.h>
|
||||
#include<hgl/io/event/InputEventSource.h>
|
||||
namespace hgl
|
||||
namespace hgl::io
|
||||
{
|
||||
namespace io
|
||||
struct EventHeader
|
||||
{
|
||||
struct EventHeader
|
||||
uint8 type; ///<输入源类型
|
||||
uint8 index; ///<输入源索引(比如同一设备有多个)
|
||||
uint16 id; ///<事件id
|
||||
};
|
||||
|
||||
constexpr size_t EventHeaderBytes=sizeof(EventHeader);
|
||||
|
||||
/**
|
||||
* 事件处理结果
|
||||
*/
|
||||
enum class EventProcResult
|
||||
{
|
||||
Continue,
|
||||
Break,
|
||||
};
|
||||
|
||||
class InputEvent
|
||||
{
|
||||
protected:
|
||||
|
||||
InputEventSource source_type;
|
||||
|
||||
SortedSet<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)
|
||||
{
|
||||
uint8 type; ///<输入源类型
|
||||
uint8 index; ///<输入源索引(比如同一设备有多个)
|
||||
uint16 id; ///<事件id
|
||||
};
|
||||
if(!RangeCheck((InputEventSource)header.type))
|
||||
return(EventProcResult::Break);
|
||||
|
||||
constexpr size_t EventHeaderBytes=sizeof(EventHeader);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件处理结果
|
||||
*/
|
||||
enum class EventProcResult
|
||||
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()
|
||||
{
|
||||
Continue,
|
||||
Break,
|
||||
};
|
||||
source_type=InputEventSource::Root;
|
||||
}
|
||||
|
||||
class InputEvent
|
||||
InputEvent(InputEventSource ies)
|
||||
{
|
||||
protected:
|
||||
source_type=ies;
|
||||
}
|
||||
|
||||
InputEventSource source_type;
|
||||
virtual ~InputEvent()=default;
|
||||
|
||||
SortedSet<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
|
||||
virtual bool Join(InputEvent *ie)
|
||||
{
|
||||
if(!ie)
|
||||
return(false);
|
||||
|
||||
public:
|
||||
const InputEventSource ies=ie->GetInputEventSource();
|
||||
|
||||
const InputEventSource GetInputEventSource()const{return source_type;}
|
||||
if(!RangeCheck(ies))
|
||||
return(false);
|
||||
|
||||
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data)
|
||||
{
|
||||
if(!RangeCheck((InputEventSource)header.type))
|
||||
return(EventProcResult::Break);
|
||||
return(sub_event_proc[size_t(ies)].Add(ie)!=-1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
bool Unjoin(InputEvent *ie)
|
||||
{
|
||||
if(!ie)return(false);
|
||||
|
||||
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;
|
||||
}
|
||||
const InputEventSource ies=ie->GetInputEventSource();
|
||||
|
||||
return(EventProcResult::Continue);
|
||||
}
|
||||
if(!RangeCheck(ies))
|
||||
return(false);
|
||||
|
||||
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
|
||||
return sub_event_proc[size_t(ies)].Delete(ie);
|
||||
}
|
||||
};//class InputEvent
|
||||
}//namespace hgl::io
|
||||
|
@ -1,24 +1,19 @@
|
||||
#ifndef HGL_IO_INPUT_DEVICE_SOURCE_INCLUDE
|
||||
#define HGL_IO_INPUT_DEVICE_SOURCE_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
namespace hgl
|
||||
namespace hgl::io
|
||||
{
|
||||
namespace io
|
||||
enum class InputEventSource
|
||||
{
|
||||
enum class InputEventSource
|
||||
{
|
||||
Root=0,
|
||||
Root=0,
|
||||
|
||||
OS,
|
||||
Window,
|
||||
OS,
|
||||
Window,
|
||||
|
||||
Keyboard,
|
||||
Mouse,
|
||||
Joystick,
|
||||
Keyboard,
|
||||
Mouse,
|
||||
Joystick,
|
||||
|
||||
ENUM_CLASS_RANGE(Root,Joystick)
|
||||
};
|
||||
}//namespace io
|
||||
}//namespace hgl
|
||||
#endif//HGL_IO_INPUT_DEVICE_SOURCE_INCLUDE
|
||||
ENUM_CLASS_RANGE(Root,Joystick)
|
||||
};
|
||||
}//namespace hgl::io
|
||||
|
@ -36,7 +36,7 @@ namespace hgl
|
||||
WindowEvent():InputEvent(InputEventSource::Window){}
|
||||
virtual ~WindowEvent()=default;
|
||||
|
||||
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
|
||||
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
|
||||
{
|
||||
wed=(WindowEventData *)&data;
|
||||
|
||||
@ -61,4 +61,4 @@ namespace hgl
|
||||
};//class WindowEvent:public InputEvent
|
||||
}//namespace io
|
||||
}//namespace hgl
|
||||
#endif//HGL_IO_WINDOW_EVENT_INCLUDE
|
||||
#endif//HGL_IO_WINDOW_EVENT_INCLUDE
|
||||
|
Loading…
x
Reference in New Issue
Block a user