Show keventhandlermanager.cpp syntax highlighted
/*
Copyright (C) 2003, 2004 by Luca Cappa
Written by Luca Cappa groton@users.sourceforge.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cssysdef.h"
#include "csutil/sysfunc.h"
#include "csutil/cscolor.h"
#include "csutil/cmdhelp.h"
#include "csutil/cspmeter.h"
#include "csutil/csstring.h"
#include "csutil/scfstr.h"
#include "csutil/dirtyaccessarray.h"
#include "csutil/xmltiny.h"
#include "csutil/array.h"
#include "cstool/csview.h"
#include "cstool/initapp.h"
#include "cstool/collider.h"
#include "iutil/vfs.h"
#include "iutil/eventq.h"
#include "iutil/event.h"
#include "iutil/objreg.h"
#include "iutil/csinput.h"
#include "iutil/virtclk.h"
#include "iutil/plugin.h"
#include "iutil/string.h"
#include "iengine/sector.h"
#include "iengine/engine.h"
#include "iengine/camera.h"
#include "iengine/light.h"
#include "iengine/texture.h"
#include "iengine/mesh.h"
#include "iengine/movable.h"
#include "iengine/material.h"
#include "imesh/thing.h"
#include "imesh/object.h"
#include "ivideo/graph3d.h"
#include "ivideo/graph2d.h"
#include "ivideo/natwin.h"
#include "ivideo/txtmgr.h"
#include "ivideo/texture.h"
#include "ivideo/material.h"
#include "ivideo/fontserv.h"
#include "igraphic/imageio.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "ivaria/conout.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "ivaria/collider.h"
#include "csgeom/quaterni.h"
#include "csgeom/transfrm.h"
#include "csgeom/math3d_d.h"
#include "csgeom/math3d.h"
#include "igeom/polymesh.h"
#include "igeom/objmodel.h"
#include "imap/loader.h"
#include "iaws/aws.h"
#include "iaws/awscnvs.h"
#include "ksprite3d.h"
#include "ske.h"
#include "korientation.h"
#include "kcamera.h"
#include "kblock.h"
#include "kmap.h"
#include "kblockid.h"
#include "kflags.h"
#include "kwireframe.h"
#include "kappstate.h"
#include "klandmark.h"
#include "klandmarklist.h"
#include "kutil.h"
#include "kcursor3d.h"
#include "kpath.h"
#include "kplayer.h"
#include "kxmlhelper.h"
//Includes for this file.
#include "keventhandlermanager.h"
//-----------------------------------------------------------------------
SCF_IMPLEMENT_IBASE (KEventHandlerManager)
SCF_IMPLEMENTS_INTERFACE (iEventHandler)
SCF_IMPLEMENT_IBASE_END
KEventHandlerManager::KEventHandlerManager ()
{
SCF_CONSTRUCT_IBASE (0);
//
//Register itself in the CS event queue.
csRef<iEventQueue> l_eQ = CS_QUERY_REGISTRY (g_objReg, iEventQueue);
CS_ASSERT (l_eQ != 0);
//
//(unsigned int)0xFFFFFFFF is "all flags are set to one"!
//(pretty ugly, isnt it? we should instead that add that symbol to
//event.h)
l_eQ->RegisterListener (this, (unsigned int)0xFFFFFFFF);
}
KEventHandlerManager::~KEventHandlerManager ()
{
}
bool KEventHandlerManager::HandleEvent (iEvent& p_e)
{
int const l_evMask = 1 << p_e.Type;
bool const l_canStop = ((p_e.Flags & CSEF_BROADCAST) == 0);
int i = 0, n = m_eventHandlers.Length();
for (; i < n; i++)
{
KEventHandler const& l_l = m_eventHandlers[i];
if ((l_l.m_trigger & l_evMask) != 0 &&
l_l.m_eH->HandleEvent (p_e) && l_canStop)
break;
}//for
return true;
};
/**
Lower priority means "get called first".
*/
bool KEventHandlerManager::AddEventHandler (iEventHandler* p_eH,
unsigned int p_trigger, unsigned int p_priority)
{
//
//Create the event listener.
KEventHandler l_eH;
l_eH.m_eH = p_eH;
l_eH.m_trigger = p_trigger;
l_eH.m_priority = p_priority;
//Push it.
m_eventHandlers.Push (l_eH);
//Reorder accordingly to the priority.
m_eventHandlers.Sort ();
return true;
}
bool KEventHandlerManager::RemoveAllEventHandlers ()
{
//
//Deregister itself in the CS event queue.
csRef<iEventQueue> l_eQ = CS_QUERY_REGISTRY (g_objReg, iEventQueue);
CS_ASSERT (l_eQ != 0);
l_eQ->RemoveListener (this);
return true;
}
See more files for this project here