1 #include <msp/time/units.h>
3 #include "eventdispatcher.h"
9 EventDispatcher::EventDispatcher()
12 void EventDispatcher::add(Base &obj)
14 SlotMap::iterator i = objects.find(&obj);
17 i = objects.insert(SlotMap::value_type(&obj, Slot(&obj))).first;
18 i->second.evch_conn = obj.signal_events_changed.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_events_changed), &obj));
19 i->second.del_conn = obj.signal_deleted.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_deleted), &obj));
22 poller.set_object(obj, obj.get_events());
26 void EventDispatcher::remove(Base &obj)
28 SlotMap::iterator i = objects.find(&obj);
31 i->second.evch_conn.disconnect();
32 i->second.del_conn.disconnect();
35 poller.set_object(obj, P_NONE);
39 void EventDispatcher::tick()
48 void EventDispatcher::tick(const Time::TimeDelta &dt)
57 void EventDispatcher::object_events_changed(PollEvent ev, Base *obj)
59 poller.set_object(*obj, ev);
62 void EventDispatcher::object_deleted(Base *obj)
67 void EventDispatcher::dispatch()
69 const Poller::SlotList &result = poller.get_result();
70 for(Poller::SlotList::const_iterator i=result.begin(); i!=result.end(); ++i)
71 i->object->event(i->events);