3 This file is part of libmspio
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
7 #include <msp/time/units.h>
9 #include "eventdispatcher.h"
18 EventDispatcher::EventDispatcher()
21 void EventDispatcher::add(Base &obj)
23 //cout<<"evdisp add "<<&obj<<'\n';
24 SlotMap::iterator i=objects.find(&obj);
27 i=objects.insert(SlotMap::value_type(&obj, Slot(&obj))).first;
28 i->second.evch_conn=obj.signal_events_changed.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_events_changed), &obj));
29 i->second.del_conn=obj.signal_deleted.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_deleted), &obj));
32 poller.set_object(obj, obj.get_events());
36 void EventDispatcher::remove(Base &obj)
38 //cout<<"evdisp remove "<<&obj<<'\n';
39 SlotMap::iterator i=objects.find(&obj);
42 i->second.evch_conn.disconnect();
43 i->second.del_conn.disconnect();
46 poller.set_object(obj, P_NONE);
50 void EventDispatcher::tick()
59 void EventDispatcher::tick(const Time::TimeDelta &dt)
68 void EventDispatcher::object_events_changed(PollEvent ev, Base *obj)
70 poller.set_object(*obj, ev);
73 void EventDispatcher::object_deleted(Base *obj)
78 void EventDispatcher::dispatch()
80 const Poller::SlotSeq &result=poller.get_result();
81 for(Poller::SlotSeq::const_iterator i=result.begin(); i!=result.end(); ++i)
82 i->object->event(i->events);