event_listener.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_EVENT_LISTENER_H
00025 #define NL_EVENT_LISTENER_H
00026 
00027 #include "types_nl.h"
00028 #include "events.h"
00029 #include "bit_set.h"
00030 
00031 
00032 namespace NLMISC {
00033 
00034 class CEvent;
00035 class CEventServer;
00036 
00043 class IEventListener
00044 {
00045 public:
00046 
00048     IEventListener();
00050     virtual ~IEventListener() {}
00051 
00055     virtual void process(const CEvent& event)
00056     {
00057         if (_Hook)
00058         {
00059             _Hook->process(event);
00060         }
00061         else
00062         {
00063             (*this)(event);
00064         }
00065     }
00066 
00071     virtual void operator ()(const CEvent& event)=0;
00072 
00073     // Set a hook which can intercept msgs.
00074     void            setHook(IEventListener *hook) { _Hook = hook; }
00075     IEventListener *getHook() const  { return _Hook; }
00076 private:
00077     IEventListener *_Hook;
00078 };
00079 
00080 
00087 class CEventListenerAsync: public IEventListener
00088 {
00089 public:
00090 
00092     CEventListenerAsync();
00093     virtual ~CEventListenerAsync() {}
00094 
00098     void addToServer (CEventServer& server);
00099 
00103     void removeFromServer (CEventServer& server);
00104 
00109     bool isKeyDown(TKey key) const;
00110 
00118     bool isKeyPushed (TKey key, bool release=true);
00119 
00120 
00130     void reset ();
00131 
00132 
00133 protected:
00134     /*
00135      * Call back of the listener.
00136      * \param event is the event send to the listener
00137      */
00138     virtual void operator ()(const CEvent& event);
00139     CBitSet _KeyArray;
00140     // Must have 2 arrays because of key repetition...
00141     CBitSet _KeyDownArray, _KeyReleaseArray;
00142 };
00143 
00144 
00145 } // NLMISC
00146 
00147 
00148 #endif // NL_EVENT_LISTENER_H
00149 
00150 /* End of event_listener.h */
00151 

Generated on Thu Jan 7 08:26:22 2010 for NeL by  doxygen 1.6.1