Something went wrong. Try again.
Massive multiplayer game aiming to create a collaborative musical environment.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243/*********************************************************************** filename: CEGUIEventSet.cpp created: 21/2/2004 author: Paul D Turner purpose: Implements the EventSet class*************************************************************************//*************************************************************************** * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/#include "CEGUIEventSet.h"#include "CEGUIExceptions.h"#include "CEGUIGlobalEventSet.h"#include "CEGUIScriptModule.h"#include "CEGUISystem.h"
// Start of CEGUI namespace sectionnamespace CEGUI{/************************************************************************* Constructor*************************************************************************/EventSet::EventSet() : d_muted(false){}
/************************************************************************* Destructor*************************************************************************/EventSet::~EventSet(void){ removeAllEvents();}
/************************************************************************* Add a new event to the EventSet*************************************************************************/void EventSet::addEvent(const String& name){ if (isEventPresent(name)) { throw AlreadyExistsException("An event named '" + name + "' already exists in the EventSet."); }
d_events[name] = new Event(name);}
/************************************************************************* Remove an event from the EventSet*************************************************************************/void EventSet::removeEvent(const String& name){ EventMap::iterator pos = d_events.find(name);
if (pos != d_events.end()) { delete pos->second; d_events.erase(pos); }
}
/************************************************************************* Remove all events from the EventSet*************************************************************************/void EventSet::removeAllEvents(void){ EventMap::iterator pos = d_events.begin(); EventMap::iterator end = d_events.end() ;
for (; pos != end; ++pos) { delete pos->second; }
d_events.clear();}
/************************************************************************* Check to see if an event is available*************************************************************************/bool EventSet::isEventPresent(const String& name){ return (d_events.find(name) != d_events.end());}
/************************************************************************* Subscribe to a scripted event (no group)*************************************************************************/Event::Connection EventSet::subscribeScriptedEvent(const String& name, const String& subscriber_name){ //return subscribeEvent(name, Event::Subscriber(ScriptFunctor(subscriber_name))); ScriptModule* sm = System::getSingletonPtr()->getScriptingModule(); if (!sm) { throw InvalidRequestException("[EventSet::subscribeScriptedEvent] No scripting module is available"); } return sm->subscribeEvent(this, name, subscriber_name);}
/************************************************************************* Subscribe to a scripted event*************************************************************************/Event::Connection EventSet::subscribeScriptedEvent(const String& name, Event::Group group, const String& subscriber_name){ //return subscribeEvent(name, group, Event::Subscriber(ScriptFunctor(subscriber_name))); ScriptModule* sm = System::getSingletonPtr()->getScriptingModule(); if (!sm) { throw InvalidRequestException("[EventSet::subscribeScriptedEvent] No scripting module is available"); } return sm->subscribeEvent(this, name, group, subscriber_name);}
/************************************************************************* Subscribe to an event (no group)*************************************************************************/Event::Connection EventSet::subscribeEvent(const String& name, Event::Subscriber subscriber){ // do subscription & return connection return getEventObject(name, true)->subscribe(subscriber);}
/************************************************************************* Subscribe to an event group*************************************************************************/Event::Connection EventSet::subscribeEvent(const String& name, Event::Group group, Event::Subscriber subscriber){ // do subscription with group & return connection return getEventObject(name, true)->subscribe(group, subscriber);}
/************************************************************************* Fire / Trigger an event*************************************************************************/void EventSet::fireEvent(const String& name, EventArgs& args, const String& eventNamespace){ // handle global events GlobalEventSet::getSingleton().fireEvent(name, args, eventNamespace); // handle local event fireEvent_impl(name, args);}
/************************************************************************* Return whether the EventSet is muted or not. *************************************************************************/bool EventSet::isMuted(void) const{ return d_muted;}
/************************************************************************* Set the mute state for this EventSet. *************************************************************************/void EventSet::setMutedState(bool setting){ d_muted = setting;}
/************************************************************************* Return the named Event object, optionally adding it to the set if needed*************************************************************************/Event* EventSet::getEventObject(const String& name, bool autoAdd){ EventMap::iterator pos = d_events.find(name);
// if event did not exist, add it and then find it. if (pos == d_events.end()) { if (autoAdd) { addEvent(name); return d_events.find(name)->second; } else { return 0; } }
return pos->second;}
/*************************************************************************
*************************************************************************/void EventSet::fireEvent_impl(const String& name, EventArgs& args){ // find event object Event* ev = getEventObject(name);
// fire the event if present and set is not muted if ((ev != 0) && !d_muted) (*ev)(args);}
/************************************************************************* Return a EventSet::EventIterator object to iterate over the available events.*************************************************************************/EventSet::Iterator EventSet::getIterator(void) const{ return Iterator(d_events.begin(), d_events.end());}
} // End of CEGUI namespace section