OMKKeyListener.cpp

Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 #include "OMKKeyListener.h"
00003 #include "OMKExtensibleSimulatedObject.h"
00004 #include "OMKParametersAccessor.inl"
00005 
00006 //-------------------------------------------------------------------------
00007 using namespace OMK ;
00008 using namespace OMK::Inp ;
00009 using namespace OMK::Type ;
00010 //-------------------------------------------------------------------------
00011 const EventIdentifier KeyListener::getKeyPressCode( const std::string& code ) 
00012 {
00013   return EventIdentifier( "Key_" + code + "_is_pressed" ) ;
00014 }
00015 //-------------------------------------------------------------------------
00016 const EventIdentifier KeyListener::getKeyReleaseCode( const std::string& code ) 
00017 {
00018   return EventIdentifier( "Key_" + code + "_is_released" ) ;
00019 }
00020 //-------------------------------------------------------------------------
00021 KeyListener::KeyListener( ExtensibleSimulatedObject* sender, 
00022                           const std::string& code, 
00023                                 const ConfigurationParameterDescriptor * node )
00024 : InputListener( sender, code, node ),
00025 _code( retrieveCode( code ) ),
00026 _keyPressedCode( getKeyPressCode( code ) ), 
00027 _keyReleasedCode( getKeyReleaseCode( code ) )
00028 {
00029   ParametersAccessor::get( node, code, _listeningObjects ) ;
00030 }
00031 //-------------------------------------------------------------------------
00032 KeyListener::~KeyListener()
00033 {
00034 }
00035 //-------------------------------------------------------------------------
00036 bool KeyListener::sendKeyEvent( OIS::KeyCode key, bool pressed )
00037 {
00038   if( _code == key )
00039   {
00040     for( std::vector< Name >::iterator i = _listeningObjects.begin() ;
00041          i != _listeningObjects.end() ;
00042          i++ )
00043     {
00044       sendEvent( *i, pressed ? _keyPressedCode : _keyReleasedCode ) ;
00045     }
00046   }
00047   return true ;
00048 }
00049 //-------------------------------------------------------------------------
00050 void KeyListener::addListeningObject( const Name& object ) 
00051 {
00052   _listeningObjects.insert( _listeningObjects.end(), object ) ;
00053 }
00054 //-------------------------------------------------------------------------

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007