NLMISC::CEventListenerAsync Class Reference

#include <event_listener.h>

Inheritance diagram for NLMISC::CEventListenerAsync:

NLMISC::IEventListener

Detailed Description

CEventListenerAsync
Author:
Stephane Coutelas

Nevrax France

Date:
2000

Definition at line 66 of file event_listener.h.

Public Member Functions

void addToServer (CEventServer &server)
 CEventListenerAsync ()
 Constructor.

bool isKeyDown (TKey key) const
bool isKeyPushed (TKey key, bool release=true)
void removeFromServer (CEventServer &server)
void reset ()
virtual ~CEventListenerAsync ()

Protected Member Functions

virtual void operator() (const CEvent &event)

Protected Attributes

CBitSet _KeyArray
CBitSet _KeyDownArray
CBitSet _KeyReleaseArray


Constructor & Destructor Documentation

NLMISC::CEventListenerAsync::CEventListenerAsync  ) 
 

Constructor.

Definition at line 50 of file event_listener.cpp.

References _KeyArray, _KeyDownArray, _KeyReleaseArray, NLMISC::KeyCount, reset(), and NLMISC::CBitSet::resize().

00051 {
00052         _KeyArray.resize (KeyCount);
00053         _KeyDownArray.resize (KeyCount);
00054         _KeyReleaseArray.resize (KeyCount);
00055         reset ();
00056 }

virtual NLMISC::CEventListenerAsync::~CEventListenerAsync  )  [inline, virtual]
 

Definition at line 72 of file event_listener.h.

00072 {}


Member Function Documentation

void NLMISC::CEventListenerAsync::addToServer CEventServer server  ) 
 

Register the listener to the server.

Definition at line 58 of file event_listener.cpp.

References NLMISC::CEventServer::addListener(), NLMISC::EventKeyDownId, NLMISC::EventKeyUpId, and NLMISC::EventSetFocusId.

Referenced by NL3D::CEvent3dMouseListener::addToServer(), and NL3D::CDriverUser::setDisplay().

00059 {
00060         server.addListener (EventKeyDownId, this);
00061         server.addListener (EventSetFocusId, this);
00062         server.addListener (EventKeyUpId, this);
00063 }

bool NLMISC::CEventListenerAsync::isKeyDown TKey  key  )  const
 

Get a key down instant state.

Parameters:
key is the key to check.

Definition at line 72 of file event_listener.cpp.

References _KeyArray, and NLMISC::CBitSet::get().

Referenced by NL3D::CEvent3dMouseListener::getViewMatrix().

00073 {
00074         return _KeyArray.get(key);
00075 }

bool NLMISC::CEventListenerAsync::isKeyPushed TKey  key,
bool  release = true
 

Get if a the state of key has pushed since the last call of isKeyPushed with release=true.

Parameters:
key is the key to check.
release if true, the pushed state of the key is released (force to be false). It will return to true next time only if key is released and then re-pushed.
See also:
reset()

Definition at line 78 of file event_listener.cpp.

References _KeyDownArray, _KeyReleaseArray, NLMISC::CBitSet::get(), and NLMISC::CBitSet::set().

Referenced by NL3D::CNELU::screenshot().

00079 {
00080         bool    ret= _KeyDownArray.get(key) && !(_KeyReleaseArray.get(key));
00081         if(ret && release)
00082         {
00083                 _KeyReleaseArray.set(key, true);
00084         }
00085         return ret;
00086 }

void NLMISC::CEventListenerAsync::operator() const CEvent event  )  [protected, virtual]
 

Call back of the listener.

Parameters:
event is the event send to the listener

Implements NLMISC::IEventListener.

Definition at line 89 of file event_listener.cpp.

References _KeyArray, _KeyDownArray, _KeyReleaseArray, NLMISC::CBitSet::clear(), NLMISC::CBitSet::clearAll(), NLMISC::EventKeyDownId, NLMISC::EventKeyUpId, NLMISC::EventSetFocusId, NLMISC::CEventSetFocus::Get, NLMISC::CBitSet::get(), NLMISC::CEventKeyUp::Key, NLMISC::CEventKeyDown::Key, NLMISC::KeyCONTROL, NLMISC::KeyLCONTROL, NLMISC::KeyLMENU, NLMISC::KeyLSHIFT, NLMISC::KeyMENU, NLMISC::KeyRCONTROL, NLMISC::KeyRMENU, NLMISC::KeyRSHIFT, NLMISC::KeySHIFT, and NLMISC::CBitSet::set().

00090 {
00091         // Key down ?
00092         if (event==EventKeyDownId)
00093         {
00094                 CEventKeyDown *pEvent=(CEventKeyDown*)&event;
00095                 _KeyArray.set (pEvent->Key);
00096                 _KeyDownArray.set (pEvent->Key);
00097                 switch(pEvent->Key)
00098                 {
00099                         case KeyRCONTROL:
00100                         case KeyLCONTROL:
00101                                 _KeyArray.set (KeyCONTROL);
00102                                 _KeyDownArray.set (KeyCONTROL);
00103                         break;
00104                         case KeyRSHIFT:
00105                         case KeyLSHIFT:
00106                                 _KeyArray.set (KeySHIFT);
00107                                 _KeyDownArray.set (KeySHIFT);
00108                         break;
00109                         case KeyRMENU:
00110                         case KeyLMENU:
00111                                 _KeyArray.set (KeyMENU);
00112                                 _KeyDownArray.set (KeyMENU);
00113                         break;
00114                         default:
00115                         break;
00116                 }
00117         }
00118         // Key up ?
00119         if (event==EventKeyUpId)
00120         {
00121                 CEventKeyUp *pEvent=(CEventKeyUp*)&event;
00122                 
00123                 _KeyArray.clear (pEvent->Key);
00124                 
00125                 switch(pEvent->Key)
00126                 {
00127                         case KeyRCONTROL:
00128                         case KeyLCONTROL:
00129                                 // Do not "raise up" the key, until someone has get the state of this key.                                              
00130                                 if (!_KeyArray[KeyLCONTROL] && !_KeyArray[KeyRCONTROL])
00131                                 {
00132                                         _KeyArray.clear(KeyCONTROL);                                    
00133 
00134                                         if(_KeyReleaseArray.get(KeyCONTROL))
00135                                         {                                               
00136                                                 _KeyDownArray.clear (KeyCONTROL);                                               
00137                                                 _KeyReleaseArray.clear (KeyCONTROL);
00138                                         }
00139                                 }
00140                         break;
00141                         case KeyRSHIFT:
00142                         case KeyLSHIFT:
00143                                 if (!_KeyArray[KeyLSHIFT] && !_KeyArray[KeyRSHIFT])
00144                                 {
00145                                         _KeyArray.clear(KeySHIFT);                                      
00146 
00147                                         if(_KeyReleaseArray.get(KeySHIFT))
00148                                         {                                               
00149                                                 _KeyDownArray.clear (KeySHIFT);                                         
00150                                                 _KeyReleaseArray.clear (KeySHIFT);
00151                                         }
00152                                 }
00153                         break;
00154                         case KeyRMENU:
00155                         case KeyLMENU:
00156                                 if (!_KeyArray[KeyLMENU] && !_KeyArray[KeyRMENU])
00157                                 {
00158                                         _KeyArray.clear(KeyMENU);                                       
00159 
00160                                         if(_KeyReleaseArray.get(KeyMENU))
00161                                         {                                               
00162                                                 _KeyDownArray.clear (KeyMENU);                                          
00163                                                 _KeyReleaseArray.clear (KeyMENU);
00164                                         }
00165                                 }
00166                         break;                  
00167                         default: break;
00168                 }
00169 
00170 
00171                 // Do not "raise up" the key, until someone has get the state of this key.
00172                 if(_KeyReleaseArray.get(pEvent->Key))
00173                 {                       
00174                         _KeyDownArray.clear (pEvent->Key);
00175                         _KeyReleaseArray.clear (pEvent->Key);
00176                 }
00177 
00178         }
00179         // Activate false ?
00180         if (event==EventSetFocusId)
00181         {
00182                 CEventSetFocus *pEvent=(CEventSetFocus *)&event;
00183                 if (!pEvent->Get)
00184                 {
00185                         // Disactive all keys
00186                         _KeyArray.clearAll ();
00187                         _KeyDownArray.clearAll ();
00188                         _KeyReleaseArray.clearAll ();                   
00189                 }
00190         }
00191 }

void NLMISC::CEventListenerAsync::removeFromServer CEventServer server  ) 
 

Unregister the listener to the server.

Definition at line 65 of file event_listener.cpp.

References NLMISC::EventKeyDownId, NLMISC::EventKeyUpId, NLMISC::EventSetFocusId, and NLMISC::CEventServer::removeListener().

Referenced by NL3D::CDriverUser::release(), and NL3D::CEvent3dMouseListener::removeFromServer().

00066 {
00067         server.removeListener (EventKeyUpId, this);
00068         server.removeListener (EventKeyDownId, this);
00069         server.removeListener (EventSetFocusId, this);
00070 }

void NLMISC::CEventListenerAsync::reset  ) 
 

Clear all the Down states to false. Usefull sometimes when you don't bother what have been pushed before. e.g.: your app listen/test to the key 'A' and 'B' for a certain long period. Then, it test 'C' and 'D' later. If the user has press (by error) the key 'C' during the first period, this API has record it, and then, at the second period, isKeyDown(KeyC) will return true the first time the key is tested, unless if you do a reset() at the beggining of the second period. Clear all the pushed states to false too.

See also:
isKeyDown()

Definition at line 195 of file event_listener.cpp.

References _KeyArray, _KeyDownArray, _KeyReleaseArray, and NLMISC::CBitSet::clearAll().

Referenced by CEventListenerAsync(), and NL3D::CDriverUser::setDisplay().

00196 {
00197         _KeyArray.clearAll ();
00198         _KeyDownArray.clearAll ();
00199         _KeyReleaseArray.clearAll ();
00200 }


Field Documentation

CBitSet NLMISC::CEventListenerAsync::_KeyArray [protected]
 

Definition at line 118 of file event_listener.h.

Referenced by CEventListenerAsync(), isKeyDown(), operator()(), and reset().

CBitSet NLMISC::CEventListenerAsync::_KeyDownArray [protected]
 

Definition at line 120 of file event_listener.h.

Referenced by CEventListenerAsync(), isKeyPushed(), operator()(), and reset().

CBitSet NLMISC::CEventListenerAsync::_KeyReleaseArray [protected]
 

Definition at line 120 of file event_listener.h.

Referenced by CEventListenerAsync(), isKeyPushed(), operator()(), and reset().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:10:56 2004 for NeL by doxygen 1.3.6