重新命名EventDispatcher的添加/解决函数
This commit is contained in:
@@ -30,6 +30,9 @@ namespace hgl::io
|
||||
Break,
|
||||
};
|
||||
|
||||
/**
|
||||
* 事件分发器
|
||||
*/
|
||||
class EventDispatcher
|
||||
{
|
||||
protected:
|
||||
@@ -38,7 +41,7 @@ namespace hgl::io
|
||||
|
||||
EventDispatcher * parent_input_event;
|
||||
|
||||
SortedSet<EventDispatcher *> event_subscribers;
|
||||
SortedSet<EventDispatcher *> child_dispatchers;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -53,9 +56,9 @@ namespace hgl::io
|
||||
if(!RangeCheck(header.type))
|
||||
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)
|
||||
return EventProcResult::Break;
|
||||
}
|
||||
@@ -80,37 +83,11 @@ namespace hgl::io
|
||||
virtual ~EventDispatcher()
|
||||
{
|
||||
if(parent_input_event)
|
||||
parent_input_event->UnsubscribeEventDispatcher(this);
|
||||
parent_input_event->RemoveChildDispatcher(this);
|
||||
}
|
||||
|
||||
virtual bool SubscribeEventDispatcher(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 AddChildDispatcher(EventDispatcher *ie);
|
||||
virtual bool RemoveChildDispatcher(EventDispatcher *ie);
|
||||
|
||||
virtual bool Update(){return true;}
|
||||
};//class EventDispatcher
|
||||
|
@@ -44,66 +44,29 @@ namespace hgl::io
|
||||
|
||||
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:
|
||||
|
||||
MouseEvent():EventDispatcher(InputEventSource::Mouse)
|
||||
{
|
||||
med=nullptr;
|
||||
position.x=0;
|
||||
position.y=0;;
|
||||
hgl_zero(pressed_statues);
|
||||
}
|
||||
MouseEvent():EventDispatcher(InputEventSource::Mouse){}
|
||||
virtual ~MouseEvent()=default;
|
||||
|
||||
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;
|
||||
virtual EventProcResult OnEvent (const EventHeader &header,const uint64 data) override;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual bool OnMove (int,int){return false;}
|
||||
virtual bool OnWheel (int,int){return false;}
|
||||
|
||||
if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break)
|
||||
return EventProcResult::Break;
|
||||
|
||||
return EventProcResult::Continue;
|
||||
}
|
||||
|
||||
virtual bool OnMove (int,int){return false;}
|
||||
virtual bool OnWheel (int,int){return false;}
|
||||
|
||||
virtual bool OnPressed (int,int,MouseButton){return false;}
|
||||
virtual bool OnReleased (int,int,MouseButton){return false;}
|
||||
virtual bool OnDblClicked(int,int,MouseButton){return false;}
|
||||
virtual bool OnPressed (int,int,MouseButton){return false;}
|
||||
virtual bool OnReleased (int,int,MouseButton){return false;}
|
||||
virtual bool OnDblClicked(int,int,MouseButton){return false;}
|
||||
|
||||
/**
|
||||
* 某按键是否按下
|
||||
*/
|
||||
* 某按键是否按下
|
||||
*/
|
||||
const bool HasPressed(const MouseButton &mb)const
|
||||
{
|
||||
if(!RangeCheck(mb))return(false);
|
||||
|
Reference in New Issue
Block a user