#include <OMKInputExtension.h>
Inheritance diagram for OMK::Inp::InputExtension:
Initialisation | |
See How to initialise an extension ? for details. | |
class | InputCreatorListener |
InputExtension (const InputExtension &vis) | |
Copy constructor, private and not defined to prevent from copying. | |
const InputExtension & | operator= (const InputExtension &vis) |
Assigment operator, private and not defined to prevent from copying. | |
void | setWindowExtents (int width, int height) |
define the size of the region for the mouse. | |
void | capture () |
Capture/update each device. | |
void | createOISInputSystem (const ConfigurationParameterDescriptor *node) |
Initialize OIS. | |
void | initOIS () |
Initialize OIS. | |
Public Member Functions | |
DECLARE_EXTENSION_FACTORY (InputExtension) | |
Factory and constructor/destructor. | |
Inherited | |
virtual bool | loadExtensionParameters (const ConfigurationParameterDescriptor *node) |
Configuration parameters loader of OMK::Extension Extension. | |
virtual void | preComputeParameters () |
Called at each step to capture the OIS input devices. | |
Inherited | |
bool | addListener (const Name &id, InputListener *listener) |
Adds an input listener. | |
bool | addListener (const Name &id, const Name &classId, const ConfigurationParameterDescriptor *configParam) |
Creates and adds an input listener. | |
bool | addListener (const AddInputListenerPrm &prm) |
Process the message. | |
bool | removeListener (const Name &id) |
Process the message to remove an input listener. | |
bool | addKeyListener (const std::string &key, const Name &listeningObject) |
Adds the listening object to the key listener. | |
bool | addKeyListener (const AddInputKeyPrm &prm) |
Static Public Member Functions | |
Utilitary methods | |
template<class CallerClass> | |
static EventListenerCallBack< CallerClass > * | initCallBackForKey (const ConfigurationParameterDescriptor *node, const std::string &keyId, std::string &key, CallerClass *caller, typename EventListenerCallBack< CallerClass >::CallBackFct fct, SimulatedObject *sender, const std::string &visuName) |
Initialise and add a listener which calls a call back method when a key is pressed. | |
Static Public Attributes | |
static EventIdentifier | ADD_INPUT |
The event id for the event "add input listener". | |
static EventIdentifier | REMOVE_INPUT |
The event id for the event "remove input listener". | |
static EventIdentifier | ADD_KEY |
The event id for the event "add key listener". | |
Protected Attributes | |
InputCreatorListener * | _inputCreatorListener |
Associated listener. | |
unsigned int | _currentWidth |
currentWidth to update OISMouse and so 2D picking | |
unsigned int | _currentHeight |
currentHeight to update OISMouse and so 2D picking | |
Ogre::RenderWindow * | _window |
Ogre RenderWindow. | |
OIS Part | |
OIS::InputManager * | _inputSystem |
the OIS input manager | |
OIS Input devices | |
OIS::Keyboard * | _keyboard |
The keyboard. | |
OIS::Mouse * | _mouse |
The mouse. | |
std::vector< OIS::JoyStick * > | _joysticks |
The joysticks. | |
OIS Input listeners | |
std::map< Name, InputListener * > | _inputListeners |
The input listeners. | |
std::map< Name, OIS::KeyListener * > | _keyListeners |
The keyboard listeners. | |
std::map< Name, OIS::MouseListener * > | _mouseListeners |
The mouse listeners. | |
std::map< Name, OIS::JoyStickListener * > | _joystickListeners |
The joysticks listeners. | |
Private Member Functions | |
OIS call back for events | |
virtual bool | keyPressed (const OIS::KeyEvent &e) |
Dispatches key pressed event. | |
virtual bool | keyReleased (const OIS::KeyEvent &e) |
Dispatches key released event. | |
virtual bool | mouseMoved (const OIS::MouseEvent &e) |
Dispatches mouse moved event. | |
virtual bool | mousePressed (const OIS::MouseEvent &e, OIS::MouseButtonID id) |
Dispatches mouse button pressed event. | |
virtual bool | mouseReleased (const OIS::MouseEvent &e, OIS::MouseButtonID id) |
Dispatches mouse button released event. | |
virtual bool | povMoved (const OIS::JoyStickEvent &e, int pov) |
Dispatches pov moved event. | |
virtual bool | axisMoved (const OIS::JoyStickEvent &e, int axis) |
Dispatches axis moved event. | |
virtual bool | sliderMoved (const OIS::JoyStickEvent &e, int sliderID) |
Dispatches slider moved event. | |
virtual bool | buttonPressed (const OIS::JoyStickEvent &e, int button) |
Dispatches joystick button pressed event. | |
virtual bool | buttonReleased (const OIS::JoyStickEvent &e, int button) |
Dispatches joystick button released event. |
bool registered = InputExtension::registerInFactory() ;
... visualisation { ... Class OgreVis ... Extensions { inputExtension { ... } } } ...
inputExtension { Class InputExtension inputName { Class InputListnerClassId ... } Keys { A [aListener anotherAListener] } ExitOnEsc ON }
inputExtension { Class InputExtension ExitOnEsc ON }
inputExtension { Class InputExtension Keys { F1 [helpObject] } }
#Key code# [#name of the first object# #name of the second object# ... ]
code | details | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ESCAPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MINUS | "-" on main keyboard, ")" for AZERTY keyboard | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EQUALS
BACK | "backspace" | TAB
| Q | "A" for AZERTY keyboard | W | "Z" for AZERTY keyboard | E | R | T | Y | U | I | O | P | LBRACKET | "^" for AZERTY keyboard | RBRACKET | "$" for AZERTY keyboard | RETURN | "Enter" on main keyboard | LCONTROL | A | "Q" for AZERTY keyboard | S | D | F | G | H | J | K | L | SEMICOLON | "M" for AZERTY keyboard | APOSTROPHE | "ù" for AZERTY keyboard | GRAVE | accent, "²" for AZERTY keyboard | LSHIFT
| BACKSLASH | "\" on main keyboard, "*" for AZERTY keyboard | Z | "W" for AZERTY keyboard | X | C | V | B | N | M | "," for AZERTY keyboard | COMMA | ";" for AZERTY keyboard | PERIOD | "." on main keyboard, ":" for AZERTY keyboard | SLASH | "/" on main keyboard, "!" for AZERTY keyboard | RSHIFT | MULTIPLY | "*" on numeric keypad | LMENU | left Alt | SPACE | CAPITAL | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | NUMLOCK | SCROLL | Scroll Lock | NUMPAD7 | NUMPAD8 | NUMPAD9 | SUBTRACT | "-" on numeric keypad | NUMPAD4 | NUMPAD5 | NUMPAD6 | ADD | "+" on numeric keypad | NUMPAD1 | NUMPAD2 | NUMPAD3 | NUMPAD0 | DECIMAL | "." on numeric keypad | OEM_102 | "<" ">" on UK/Germany/AZERTY keyboards | F11 | F12 | F13 | (NEC PC98) | F14 | (NEC PC98) | F15 | (NEC PC98) | KANA | (Japanese keyboard) | ABNT_C1 | "?" on Portugese (Brazilian) keyboards | CONVERT | (Japanese keyboard) | NOCONVERT | (Japanese keyboard) | YEN | (Japanese keyboard) | ABNT_C2 | Numpad . on Portugese (Brazilian) keyboards | NUMPADEQUALS | "=" on numeric keypad (NEC PC98) | PREVTRACK | Previous Track (CIRCUMFLEX on Japanese keyboard) | AT | (NEC PC98) | COLON | (NEC PC98) | UNDERLINE | (NEC PC98) | KANJI | (Japanese keyboard) | STOP | (NEC PC98) | AX | (Japan AX) | UNLABELED | (J3100) | NEXTTRACK | Next Track | NUMPADENTER | "Enter" on numeric keypad | RCONTROL | MUTE | Mute | CALCULATOR | Calculator | PLAYPAUSE | Play / Pause | MEDIASTOP | Media Stop | VOLUMEDOWN | Volume - | VOLUMEUP | Volume + | WEBHOME | Web home | NUMPADCOMMA | ";" on numeric keypad (NEC PC98) | DIVIDE | "/" on numeric keypad | SYSRQ | RMENU | right Alt | PAUSE | Pause | HOME | Home on arrow keypad | UP | UpArrow on arrow keypad | PGUP | PgUp on arrow keypad | LEFT | LeftArrow on arrow keypad | RIGHT | RightArrow on arrow keypad | END | End on arrow keypad | DOWN | DownArrow on arrow keypad | PGDOWN | PgDn on arrow keypad | INSERT | Insert on arrow keypad | DELETE | Delete on arrow keypad | LWIN | Left Windows key | RWIN | Right Windows key | APPS | AppMenu key | POWER | System Power | SLEEP | System Sleep | WAKE | System Wake | WEBSEARCH | Web Search | WEBFAVORITES | Web Favorites | WEBREFRESH | Web Refresh | WEBSTOP | Web Stop | WEBFORWARD | Web Forward | WEBBACK | Web Back | MYCOMPUTER | My Computer | MAIL | Mail | MEDIASELECT | Media Select | |
Definition at line 288 of file OMKInputExtension.h.
OMK::Inp::InputExtension::InputExtension | ( | const InputExtension & | vis | ) | [private] |
Copy constructor, private and not defined to prevent from copying.
OMK::Inp::InputExtension::DECLARE_EXTENSION_FACTORY | ( | InputExtension | ) |
Factory and constructor/destructor.
bool InputExtension::loadExtensionParameters | ( | const ConfigurationParameterDescriptor * | node | ) | [virtual] |
Configuration parameters loader of OMK::Extension Extension.
Reimplemented from OMK::Extension.
Definition at line 56 of file OMKInputExtension.cpp.
References _inputCreatorListener, OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, OMK::SimulatedObject::addEventListener(), addListener(), createOISInputSystem(), OMK::ParametersAccessor::get(), OMK::ConfigurationParameterDescriptor::getNumberOfSubItems(), initOIS(), and InputCreatorListener.
00057 { 00058 // Init input devices 00059 createOISInputSystem(node) ; 00060 initOIS() ; 00061 00062 //Insertion in OpenMASK event processing 00063 _inputCreatorListener = new InputCreatorListener( _owner, this ) ; 00064 _owner->addEventListener( *_inputCreatorListener ) ; 00065 00066 // creation of the input listeners defined 00067 // Retrieve the extension fields to create the extensions which defined a "Class" 00068 if( node ) 00069 { 00070 int nbItems = node->getNumberOfSubItems() ; 00071 for( int i = 0 ; i < nbItems ; ++i ) 00072 { 00073 // Retrieves parameters sets for each extension 00074 std::string id( static_cast<const MultipleConfigurationParameter *>( node )->getNameOfSubDescriptor( i ) ) ; 00075 if( "ExitOnEsc" == id ) 00076 { 00077 // For exit on escape 00078 bool exitOnEsc = false ; 00079 ParametersAccessor::get( node, "ExitOnEsc", exitOnEsc ) ; 00080 if( exitOnEsc ) 00081 { 00082 Name id( "exitOnEsc" ) ; 00083 addListener( Name( id ), new EscListener( _owner, id ) ) ; 00084 } 00085 } 00086 if( "Keys" == id ) 00087 { 00088 const ConfigurationParameterDescriptor * keyParam = node->getSubDescriptorByPosition( i ) ; 00089 int nbKeys = keyParam->getNumberOfSubItems() ; 00090 for( int k = 0 ; k < nbKeys ; ++k ) 00091 { 00092 std::string key( static_cast<const MultipleConfigurationParameter *>( keyParam )->getNameOfSubDescriptor( k ) ) ; 00093 addListener( Name( "Key_" + key ), new OMK::Inp::KeyListener( _owner, key, keyParam ) ) ; 00094 } 00095 } 00096 else 00097 { 00098 const ConfigurationParameterDescriptor * inputParam = node->getSubDescriptorByPosition( i ) ; 00099 // Try to retrieve the class id to create the extension 00100 Name classId ; 00101 if( ParametersAccessor::get( inputParam, "Class", classId ) ) 00102 { // ClassId is ok => Create the extension 00103 addListener( Name( id ), classId, inputParam ) ; 00104 } 00105 } 00106 } 00107 } 00108 00109 return true ; 00110 }
void InputExtension::preComputeParameters | ( | ) | [virtual] |
Called at each step to capture the OIS input devices.
Reimplemented from OMK::Extension.
Definition at line 262 of file OMKInputExtension.cpp.
References _currentHeight, _currentWidth, _mouse, _window, capture(), and setWindowExtents().
00263 { 00264 // Need to capture devices every compute 00265 capture() ; 00266 //Update Mouse 00267 if ( _mouse && 00268 ( ( _window->getWidth() != _currentWidth ) 00269 || (_window->getHeight() != _currentHeight ) ) ) 00270 setWindowExtents ( _window->getWidth(), _window->getHeight()); 00271 }
bool InputExtension::addListener | ( | const Name & | id, | |
InputListener * | listener | |||
) |
Adds an input listener.
Definition at line 482 of file OMKInputExtension.cpp.
References _inputListeners, _joystickListeners, _joysticks, _keyListeners, _mouse, _mouseListeners, OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, OMK::debugMsg(), OMK_DEBUG_INP_EXT, and OMTRACEID.
Referenced by addKeyListener(), addListener(), loadExtensionParameters(), and OMK::Inp::InputCreatorListener::processEvent().
00483 { 00484 std::ostringstream errorMsg ; 00485 // return value 00486 bool ok = false ; // Will be ok, if at least one listener (keyboard, mouse or joystick) can be registered 00487 // Add the new input listener to the visualisation 00488 if( listener ) 00489 { 00490 std::map< Name, InputListener* >::iterator i = _inputListeners.find( id ); 00491 if( i == _inputListeners.end() ) 00492 { 00493 // It is a really new item, adds it in the main list 00494 _inputListeners[ id ] = listener ; 00495 00496 //Is it a keyboard listener ? 00497 if( _keyboard ) 00498 { 00499 OIS::KeyListener* keyListener = dynamic_cast< OIS::KeyListener* >( listener ) ; 00500 if( keyListener ) 00501 { 00502 _keyListeners[ id ] = keyListener ; 00503 ok = true ; 00504 } 00505 } 00506 else 00507 { 00508 errorMsg << "Unable to register the keyboard listener \"" << id << "\" because there is no keyboard" << std::endl ; 00509 } 00510 00511 //Is it a mouse listener ? 00512 if( _mouse ) 00513 { 00514 OIS::MouseListener* mouseListener = dynamic_cast< OIS::MouseListener* >( listener ) ; 00515 if( mouseListener ) 00516 { 00517 _mouseListeners[ id ] = mouseListener ; 00518 ok = true ; 00519 } 00520 } 00521 else 00522 { 00523 errorMsg << "Unable to register the mouse listener \"" << id << "\" because there is no mouse" << std::endl; 00524 } 00525 00526 //Is it a joystick listener ? 00527 if( 0 < _joysticks.size() ) 00528 { 00529 OIS::JoyStickListener* joystickListener = dynamic_cast< OIS::JoyStickListener* >( listener ) ; 00530 if( joystickListener ) 00531 { 00532 _joystickListeners[ id ] = joystickListener ; 00533 ok = true ; 00534 } 00535 } 00536 else 00537 { 00538 errorMsg << "Unable to register the joystick listener listener \"" << id << "\" because there is no joystickListener" << std::endl; 00539 } 00540 } 00541 else 00542 { 00543 // Duplicate Item 00544 errorMsg << "The listener \"" << id<< "\" is a duplicate one" << std::endl ; 00545 } 00546 } 00547 else 00548 { 00549 errorMsg << "Unable to create the input listener \"" << id << "\"" << std::endl ; 00550 } 00551 // Unable to process event => error message 00552 if( !ok ) 00553 { 00554 OMTRACEID(OMK_DEBUG_INP_EXT, "Error for " << OMK::debugMsg( _owner ) << std::endl 00555 << ">>> " << errorMsg.str() ) ; 00556 delete listener ; 00557 } 00558 return ok ; 00559 }
bool InputExtension::addListener | ( | const Name & | id, | |
const Name & | classId, | |||
const ConfigurationParameterDescriptor * | configParam | |||
) |
Creates and adds an input listener.
Definition at line 474 of file OMKInputExtension.cpp.
References OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, and addListener().
00477 { 00478 // Creates the listener 00479 return addListener( id, InputListenerFactory::getInstance().create( classId )( _owner, id, configParam ) ) ; 00480 }
bool InputExtension::addListener | ( | const AddInputListenerPrm & | prm | ) |
Process the message.
Definition at line 467 of file OMKInputExtension.cpp.
References addListener(), OMK::Inp::AddInputListenerPrm::getClassId(), OMK::Inp::AddInputListenerPrm::getConfigParam(), and OMK::Inp::AddInputListenerPrm::getListenerId().
00468 { 00469 return addListener( prm.getListenerId(), 00470 prm.getClassId(), 00471 prm.getConfigParam() ); 00472 }
Process the message to remove an input listener.
Definition at line 562 of file OMKInputExtension.cpp.
References _inputListeners, _joystickListeners, _keyListeners, _mouseListeners, OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, OMK::debugMsg(), OMK_DEBUG_INP_EXT, and OMTRACEID.
Referenced by OMK::Inp::InputCreatorListener::processEvent().
00563 { 00564 bool ok = false ; 00565 std::map< Name, InputListener* >::iterator i = _inputListeners.find( id ); 00566 if( i != _inputListeners.end() ) 00567 { 00568 _inputListeners.erase( i ) ; 00569 // remove form keyboard listener list 00570 std::map< Name, OIS::KeyListener* >::iterator ik = _keyListeners.find( id ); 00571 if( ik != _keyListeners.end() ) _keyListeners.erase( ik ) ; 00572 // remove form mouse listener list 00573 std::map< Name, OIS::MouseListener* >::iterator im = _mouseListeners.find( id ); 00574 if( im != _mouseListeners.end() ) _mouseListeners.erase( im ) ; 00575 // remove form joystick listener list 00576 std::map< Name, OIS::JoyStickListener* >::iterator ij = _joystickListeners.find( id ); 00577 if( ij != _joystickListeners.end() ) _joystickListeners.erase( ij ) ; 00578 00579 // delete the listener 00580 delete i->second ; 00581 } 00582 else 00583 { 00584 OMTRACEID(OMK_DEBUG_INP_EXT, "Error for " << OMK::debugMsg( _owner ) << std::endl 00585 << ">>> Unable to remove \"" << id << "\", this listener is not registered." << std::endl ) ; 00586 } 00587 return ok ; 00588 }
Adds the listening object to the key listener.
Definition at line 441 of file OMKInputExtension.cpp.
References _inputListeners, OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, addListener(), and OMK::Inp::KeyListener::addListeningObject().
Referenced by addKeyListener(), and OMK::Inp::InputCreatorListener::processEvent().
00443 { 00444 // return value 00445 bool ok = false ; 00446 00447 Name listenerId( "Key_" + key ) ; 00448 std::map< Name, InputListener* >::iterator i = _inputListeners.find( listenerId ); 00449 OMK::Inp::KeyListener* keyListener = 0 ; 00450 if( i == _inputListeners.end() ) 00451 { 00452 // not yet implemented 00453 keyListener = new OMK::Inp::KeyListener( _owner, key, 0 ) ; 00454 addListener( listenerId, keyListener ) ; 00455 } 00456 else 00457 { 00458 // Already created 00459 keyListener = dynamic_cast< OMK::Inp::KeyListener* >( i->second ) ; 00460 } 00461 // Appends the object to the listener 00462 keyListener->addListeningObject( listeningObject ) ; 00463 00464 return ok ; 00465 }
bool InputExtension::addKeyListener | ( | const AddInputKeyPrm & | prm | ) |
Definition at line 436 of file OMKInputExtension.cpp.
References addKeyListener(), OMK::Inp::AddInputKeyPrm::getKey(), and OMK::Inp::AddInputKeyPrm::getListeningObjectId().
00437 { 00438 return addKeyListener( prm.getKey(), prm.getListeningObjectId() ) ; 00439 }
EventListenerCallBack< CallerClass > * OMK::Inp::InputExtension::initCallBackForKey | ( | const ConfigurationParameterDescriptor * | node, | |
const std::string & | keyId, | |||
std::string & | key, | |||
CallerClass * | caller, | |||
typename EventListenerCallBack< CallerClass >::CallBackFct | fct, | |||
SimulatedObject * | sender, | |||
const std::string & | visuName | |||
) | [inline, static] |
Initialise and add a listener which calls a call back method when a key is pressed.
[in] | node | The configuration node to find (or not) the keyId |
[in] | keyId | The name of the key in the configuration node |
in/out] | key The default key, returns the key really used, read in the configuration node if there is one or leave it unchanged | |
[in] | caller | The owner of the call-back method, its class is the template parameter |
[in] | fct | The call-back method to call when the key is pressed |
[in] | sender | The one which will send the message to the visualisation to create the key listener |
[in] | visuName | The name of the visualisation object |
You have to include file InputExtension.inl to use this method.
Example of use in an extension:
bool MyExtension::loadExtensionParameters( const ConfigurationParameterDescriptor * node ) { bool ok = OMK::Extension::loadExtensionParameters( node ) ; _message = "You pressed the T key" ) ; ParametersAccessor::get( node, "Message", _message, _owner ) ) std::string visuName ; if( ParametersAccessor::get( node, "VisuName", visuName, _owner ) ) { std::string defaultKey( "T" ); OMK::Inp::InputExtension::initCallBackForKey( node, "TheKeyWhichTriggersTheAction", defaultKey, this, &MyExtension::wantActionWhenKeyIsPressed, _owner, visuName ) ; } else { OMERROR( "Need \"VisuName\" configuration parameter to activate the keyboard listener" ) ; ok = false ; } return ok ; } bool MyExtension::wantActionWhenKeyIsPressed( Event* e ) { OMMESSAGE( _message ) ; return true ; }
...
Extensions
{
myExtension
{
Class MyExtension
TheKeyWhichTriggersTheAction R
Message "You pressed the R key"
}
...
Definition at line 37 of file OMKInputExtension.inl.
References ADD_KEY, OMK::ParametersAccessor::get(), and OMK::Inp::KeyListener::getKeyReleaseCode().
00045 { 00046 ParametersAccessor::get( node, keyId, key ) ; 00047 EventListenerCallBack< CallerClass >* listener = new EventListenerCallBack< CallerClass > 00048 ( *sender, caller, fct, OMK::Inp::KeyListener::getKeyReleaseCode( key ) ) ; 00049 sender->sendValuedEvent( visuName, OMK::Inp::InputExtension::ADD_KEY, OMK::Inp::AddInputKeyPrm( key, sender->getName() ) ) ; 00050 return listener ; 00051 }
const InputExtension& OMK::Inp::InputExtension::operator= | ( | const InputExtension & | vis | ) | [private] |
Assigment operator, private and not defined to prevent from copying.
define the size of the region for the mouse.
Set mouse region (if window resizes, we should alter this to reflect as well)
Definition at line 294 of file OMKInputExtension.cpp.
References _currentHeight, _currentWidth, and _mouse.
Referenced by initOIS(), and preComputeParameters().
00295 { 00296 const OIS::MouseState &mouseState = _mouse->getMouseState(); 00297 mouseState.width = width; 00298 mouseState.height = height; 00299 _currentWidth = width; 00300 _currentHeight = height; 00301 }
void InputExtension::capture | ( | ) | [private] |
Capture/update each device.
Definition at line 274 of file OMKInputExtension.cpp.
References _joysticks, and _mouse.
Referenced by preComputeParameters().
00275 { 00276 // Capture/update each device 00277 if( _keyboard ) 00278 { 00279 _keyboard->capture() ; 00280 } 00281 if( _mouse ) 00282 { 00283 _mouse->capture() ; 00284 } 00285 for( std::vector< OIS::JoyStick* >::iterator i = _joysticks.begin() ; 00286 i != _joysticks.end() ; 00287 ++i ) 00288 { 00289 (*i)->capture() ; 00290 } 00291 }
void InputExtension::createOISInputSystem | ( | const ConfigurationParameterDescriptor * | node | ) | [private] |
Initialize OIS.
Definition at line 115 of file OMKInputExtension.cpp.
References _inputSystem, _joysticks, _keyboard, _mouse, OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, OMK::ParametersAccessor::get(), OMASSERTM, and OMK::Vis::OgreVis::touchRoot().
Referenced by loadExtensionParameters().
00116 { 00117 OMASSERTM( _owner, "Must have a valid visualisation object !" ) ; 00118 OMASSERTM( _owner->touchRoot().getAutoCreatedWindow(), "Must have a valid visualisation window !" ) ; 00119 OMASSERTM( !_inputSystem && !_keyboard && !_mouse && _joysticks.empty(), "Must uninitialized !" ) ; 00120 OIS::ParamList paramList ; 00121 // Setup basic variables 00122 // Get window handle 00123 size_t theWindow = 0; 00124 _owner->touchRoot().getAutoCreatedWindow()->getCustomAttribute( "WINDOW", &theWindow ); 00125 #if defined WIN32 00126 // Uncomment these two lines to allow users to switch keyboards via the language bar 00127 paramList.insert(std::make_pair( std::string( "w32_keyboard" ), std::string( "DISCL_FOREGROUND" ) ) ); 00128 paramList.insert(std::make_pair( std::string( "w32_keyboard" ), std::string( "DISCL_NONEXCLUSIVE" ) ) ); 00129 00130 #elif defined OIS_LINUX_PLATFORM 00131 paramList.insert( std::make_pair( std::string( "XAutoRepeatOn" ), std::string( "true") ) ); 00132 paramList.insert( std::make_pair( std::string( "x11_mouse_hide" ), std::string( "false" ) ) ); 00133 paramList.insert( std::make_pair( std::string( "x11_mouse_grab" ), std::string( "false" ) ) ); 00134 00135 std::string grabKeyboard ="false"; 00136 ParametersAccessor::get ( node, "x11_keyboard_grab", grabKeyboard); 00137 OMASSERTM( (grabKeyboard == "false") || (grabKeyboard == "true"), 00138 " parameter x11_keyboard_grab must be true or false"); 00139 paramList.insert( std::make_pair( std::string( "x11_keyboard_grab" ),grabKeyboard ) ); 00140 #endif 00141 // Fill parameter list 00142 std::ostringstream theWindowStr; 00143 theWindowStr << theWindow ; 00144 paramList.insert( std::make_pair( std::string( "WINDOW" ), theWindowStr.str() ) ); 00145 00146 // Create inputsystem 00147 _inputSystem = OIS::InputManager::createInputSystem( paramList ); 00148 }
void InputExtension::initOIS | ( | ) | [private] |
Initialize OIS.
Definition at line 150 of file OMKInputExtension.cpp.
References _inputSystem, _joysticks, _keyboard, _mouse, OMK::ExtensionT< OMK::Vis::OgreVis >::_owner, _window, OMASSERT, OMK_DEBUG_INP_EXT, OMTRACEID, setWindowExtents(), and OMK::Vis::OgreVis::touchRoot().
Referenced by loadExtensionParameters().
00151 { 00152 OMASSERT( _inputSystem && "Must initialized !" ) ; 00153 // If possible create a buffered keyboard 00154 if( 0 < _inputSystem->numKeyboards() ) 00155 // Future OIS Version 00156 // if( 0 < _inputSystem->getNumberOfDevices(OIS::OISKeyboard) ) 00157 { 00158 _keyboard = static_cast<OIS::Keyboard*>( _inputSystem->createInputObject( OIS::OISKeyboard, true ) ); 00159 _keyboard->setEventCallback( this ); 00160 } 00161 else 00162 { 00163 OMTRACEID(OMK_DEBUG_INP_EXT, ">>>No keyboard to listen !" << std::endl ) ; 00164 } 00165 00166 // If possible create a buffered mouse 00167 if( 0 < _inputSystem->numMice() ) 00168 // Future OIS Version 00169 // if( 0 < _inputSystem->getNumberOfDevices(OIS::OISMouse) ) 00170 { 00171 _mouse = static_cast< OIS::Mouse* >( _inputSystem->createInputObject( OIS::OISMouse, true ) ); 00172 _mouse->setEventCallback( this ); 00173 00174 // Get window size 00175 unsigned int width, height, depth; 00176 int left, top; 00177 _window = _owner->touchRoot().getAutoCreatedWindow(); 00178 OMASSERT ( _window && "No RenderWindow" ); 00179 _window->getMetrics( width, height, depth, left, top ); 00180 00181 // Set mouse region 00182 setWindowExtents( width, height ); 00183 } 00184 else 00185 { 00186 OMTRACEID(OMK_DEBUG_INP_EXT, ">>>No mouse to listen !" << std::endl ) ; 00187 } 00188 00189 // If possible create all joysticks in buffered mode 00190 if( 0 < _inputSystem->numJoySticks() ) 00191 // Future OIS Version 00192 // if( 0 < _inputSystem->getNumberOfDevices(OIS::OISJoyStick) ) 00193 { 00194 _joysticks.resize( _inputSystem->numJoySticks() ); 00195 // Future OIS Version 00196 // _joysticks.resize( _inputSystem->getNumberOfDevices(OIS::OISJoyStick) ); 00197 for( std::vector< OIS::JoyStick* >::iterator i = _joysticks.begin() ; 00198 i != _joysticks.end() ; 00199 ++i ) 00200 { 00201 (*i) = static_cast< OIS::JoyStick* >( _inputSystem->createInputObject( OIS::OISJoyStick, true ) ); 00202 (*i)->setEventCallback( this ); 00203 } 00204 } 00205 else 00206 { 00207 OMTRACEID(OMK_DEBUG_INP_EXT, ">>>No joystick to listen !" << std::endl ) ; 00208 } 00209 }
bool InputExtension::keyPressed | ( | const OIS::KeyEvent & | e | ) | [private, virtual] |
Dispatches key pressed event.
Definition at line 306 of file OMKInputExtension.cpp.
References _keyListeners.
00307 { 00308 for( std::map< Name, OIS::KeyListener* >::iterator i = _keyListeners.begin(); 00309 i != _keyListeners.end() ; 00310 ++i ) 00311 { 00312 i->second->keyPressed( e ); 00313 } 00314 00315 return true; 00316 }
bool InputExtension::keyReleased | ( | const OIS::KeyEvent & | e | ) | [private, virtual] |
Dispatches key released event.
Definition at line 319 of file OMKInputExtension.cpp.
References _keyListeners.
00320 { 00321 for( std::map< Name, OIS::KeyListener* >::iterator i = _keyListeners.begin(); 00322 i != _keyListeners.end() ; 00323 ++i ) 00324 { 00325 i->second->keyReleased( e ); 00326 } 00327 00328 return true; 00329 }
bool InputExtension::mouseMoved | ( | const OIS::MouseEvent & | e | ) | [private, virtual] |
Dispatches mouse moved event.
Definition at line 332 of file OMKInputExtension.cpp.
References _mouseListeners.
00333 { 00334 for( std::map< Name, OIS::MouseListener* >::iterator i = _mouseListeners.begin(); 00335 i != _mouseListeners.end() ; 00336 ++i ) 00337 { 00338 i->second->mouseMoved( e ); 00339 } 00340 00341 return true; 00342 }
bool InputExtension::mousePressed | ( | const OIS::MouseEvent & | e, | |
OIS::MouseButtonID | id | |||
) | [private, virtual] |
Dispatches mouse button pressed event.
Definition at line 345 of file OMKInputExtension.cpp.
References _mouseListeners.
00346 { 00347 for( std::map< Name, OIS::MouseListener* >::iterator i = _mouseListeners.begin(); 00348 i != _mouseListeners.end() ; 00349 ++i ) 00350 { 00351 i->second->mousePressed( e, id ); 00352 } 00353 00354 return true; 00355 }
bool InputExtension::mouseReleased | ( | const OIS::MouseEvent & | e, | |
OIS::MouseButtonID | id | |||
) | [private, virtual] |
Dispatches mouse button released event.
Definition at line 358 of file OMKInputExtension.cpp.
References _mouseListeners.
00359 { 00360 for( std::map< Name, OIS::MouseListener* >::iterator i = _mouseListeners.begin(); 00361 i != _mouseListeners.end() ; 00362 ++i ) 00363 { 00364 i->second->mouseReleased( e, id ); 00365 } 00366 00367 return true; 00368 }
Dispatches pov moved event.
Definition at line 371 of file OMKInputExtension.cpp.
References _joystickListeners.
00372 { 00373 for( std::map< Name, OIS::JoyStickListener* >::iterator i = _joystickListeners.begin(); 00374 i != _joystickListeners.end() ; 00375 ++i ) 00376 { 00377 i->second->povMoved( e, pov ); 00378 } 00379 00380 return true; 00381 }
Dispatches axis moved event.
Definition at line 384 of file OMKInputExtension.cpp.
References _joystickListeners.
00385 { 00386 for( std::map< Name, OIS::JoyStickListener* >::iterator i = _joystickListeners.begin(); 00387 i != _joystickListeners.end() ; 00388 ++i ) 00389 { 00390 i->second->axisMoved( e, axis ); 00391 } 00392 00393 return true; 00394 }
Dispatches slider moved event.
Definition at line 397 of file OMKInputExtension.cpp.
References _joystickListeners.
00398 { 00399 for( std::map< Name, OIS::JoyStickListener* >::iterator i = _joystickListeners.begin(); 00400 i != _joystickListeners.end() ; 00401 ++i ) 00402 { 00403 i->second->sliderMoved( e, sliderID ); 00404 } 00405 00406 return true; 00407 }
Dispatches joystick button pressed event.
Definition at line 410 of file OMKInputExtension.cpp.
References _joystickListeners.
00411 { 00412 for( std::map< Name, OIS::JoyStickListener* >::iterator i = _joystickListeners.begin(); 00413 i != _joystickListeners.end() ; 00414 ++i ) 00415 { 00416 i->second->buttonPressed( e, button ); 00417 } 00418 00419 return true; 00420 }
Dispatches joystick button released event.
Definition at line 423 of file OMKInputExtension.cpp.
References _joystickListeners.
00424 { 00425 for( std::map< Name, OIS::JoyStickListener* >::iterator i = _joystickListeners.begin(); 00426 i != _joystickListeners.end() ; 00427 ++i ) 00428 { 00429 i->second->buttonReleased( e, button ); 00430 } 00431 00432 return true; 00433 }
friend class InputCreatorListener [friend] |
EventIdentifier InputExtension::ADD_INPUT [static] |
The event id for the event "add input listener".
Definition at line 296 of file OMKInputExtension.h.
Referenced by OMK::Inp::InputCreatorListener::processEvent(), and OMK::Inp::InputCreatorListener::registerEvents().
The event id for the event "remove input listener".
Definition at line 298 of file OMKInputExtension.h.
Referenced by OMK::Inp::InputCreatorListener::processEvent(), and OMK::Inp::InputCreatorListener::registerEvents().
EventIdentifier InputExtension::ADD_KEY [static] |
The event id for the event "add key listener".
Definition at line 300 of file OMKInputExtension.h.
Referenced by initCallBackForKey(), OMK::Inp::GenericKeyExtension< OMK::ExtensibleSimulatedObject >::loadExtensionParameters(), OMK::Inp::InputCreatorListener::processEvent(), and OMK::Inp::InputCreatorListener::registerEvents().
OIS::InputManager* OMK::Inp::InputExtension::_inputSystem [protected] |
the OIS input manager
Definition at line 454 of file OMKInputExtension.h.
Referenced by createOISInputSystem(), and initOIS().
OIS::Keyboard* OMK::Inp::InputExtension::_keyboard [protected] |
The keyboard.
Definition at line 459 of file OMKInputExtension.h.
Referenced by createOISInputSystem(), and initOIS().
OIS::Mouse* OMK::Inp::InputExtension::_mouse [protected] |
The mouse.
Definition at line 461 of file OMKInputExtension.h.
Referenced by addListener(), capture(), createOISInputSystem(), initOIS(), preComputeParameters(), and setWindowExtents().
std::vector< OIS::JoyStick* > OMK::Inp::InputExtension::_joysticks [protected] |
The joysticks.
Definition at line 463 of file OMKInputExtension.h.
Referenced by addListener(), capture(), createOISInputSystem(), and initOIS().
std::map< Name, InputListener* > OMK::Inp::InputExtension::_inputListeners [protected] |
The input listeners.
Definition at line 469 of file OMKInputExtension.h.
Referenced by addKeyListener(), addListener(), and removeListener().
std::map< Name, OIS::KeyListener* > OMK::Inp::InputExtension::_keyListeners [protected] |
The keyboard listeners.
Definition at line 471 of file OMKInputExtension.h.
Referenced by addListener(), keyPressed(), keyReleased(), and removeListener().
std::map< Name, OIS::MouseListener* > OMK::Inp::InputExtension::_mouseListeners [protected] |
The mouse listeners.
Definition at line 473 of file OMKInputExtension.h.
Referenced by addListener(), mouseMoved(), mousePressed(), mouseReleased(), and removeListener().
std::map< Name, OIS::JoyStickListener* > OMK::Inp::InputExtension::_joystickListeners [protected] |
The joysticks listeners.
Definition at line 475 of file OMKInputExtension.h.
Referenced by addListener(), axisMoved(), buttonPressed(), buttonReleased(), povMoved(), removeListener(), and sliderMoved().
Associated listener.
Definition at line 478 of file OMKInputExtension.h.
Referenced by loadExtensionParameters().
unsigned int OMK::Inp::InputExtension::_currentWidth [protected] |
currentWidth to update OISMouse and so 2D picking
Definition at line 480 of file OMKInputExtension.h.
Referenced by preComputeParameters(), and setWindowExtents().
unsigned int OMK::Inp::InputExtension::_currentHeight [protected] |
currentHeight to update OISMouse and so 2D picking
Definition at line 482 of file OMKInputExtension.h.
Referenced by preComputeParameters(), and setWindowExtents().
Ogre::RenderWindow* OMK::Inp::InputExtension::_window [protected] |
Ogre RenderWindow.
Definition at line 484 of file OMKInputExtension.h.
Referenced by initOIS(), and preComputeParameters().
Documentation generated on Mon Jun 9 11:46:04 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |