diff --git a/include/osgPresentation/Timeout b/include/osgPresentation/Timeout index 2c80ac03f..58829270b 100644 --- a/include/osgPresentation/Timeout +++ b/include/osgPresentation/Timeout @@ -50,14 +50,32 @@ class OSGPRESENTATION_EXPORT Timeout : public osg::Transform META_Node(osgPresentation, Timeout); + void setIdleDurationBeforeTimeoutDisplay(double t) { _idleDurationBeforeTimeoutDisplay = t; } double getIdleDurationBeforeTimeoutDisplay() const { return _idleDurationBeforeTimeoutDisplay; } - + void setIdleDurationBeforeTimeoutAction(double t) { _idleDurationBeforeTimeoutAction = t; } double getIdleDurationBeforeTimeoutAction() const { return _idleDurationBeforeTimeoutAction; } - void setJumpData(const JumpData& jumpData) { _jumpData = jumpData; } - const JumpData& getJumpData() const { return _jumpData; } + + void setKeyStartsTimoutDisplay(int key) { _keyStartsTimoutDisplay = key; } + int getKeyStartsTimoutDisplay() const { return _keyStartsTimoutDisplay; } + + void setKeyDismissTimoutDisplay(int key) { _keyDismissTimoutDisplay = key; } + int getKeyDismissTimoutDisplay() const { return _keyDismissTimoutDisplay; } + + void setKeyRunTimoutAction(int key) { _keyRunTimeoutAction = key; } + int getKeyRunTimoutAction() const { return _keyRunTimeoutAction; } + + + void setActionKeyPosition(const osgPresentation::KeyPosition& keyPos) { _actionKeyPos = keyPos; } + const osgPresentation::KeyPosition& getActionKeyPosition() const { return _actionKeyPos; } + + void setActionBroadcastKeyPosition(const osgPresentation::KeyPosition& keyPos) { _actionBroadcastKeyPos = keyPos; } + const osgPresentation::KeyPosition& getActionBroadcastKeyPosition() const { return _actionBroadcastKeyPos; } + + void setActionJumpData(const JumpData& jumpData) { _actionJumpData = jumpData; } + const JumpData& getActionJumpData() const { return _actionJumpData; } virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; @@ -73,10 +91,18 @@ class OSGPRESENTATION_EXPORT Timeout : public osg::Transform int _previousFrameNumber; double _timeOfLastEvent; + bool _displayTimout; + double _idleDurationBeforeTimeoutDisplay; double _idleDurationBeforeTimeoutAction; - JumpData _jumpData; + int _keyStartsTimoutDisplay; + int _keyDismissTimoutDisplay; + int _keyRunTimeoutAction; + + osgPresentation::KeyPosition _actionKeyPos; + osgPresentation::KeyPosition _actionBroadcastKeyPos; + JumpData _actionJumpData; }; } diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index 39916415b..a5385bc46 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -1467,17 +1467,84 @@ void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& con } else if (cur->name == "timeout_jump") { - OSG_NOTICE<<"Parsed Jump "<setJumpData(jumpData); + timeout->setActionJumpData(jumpData); } } + else if (cur->name == "timeout_event") + { + osgPresentation::KeyPosition keyPosition; + if (getKeyPositionInner( cur, keyPosition)) + { + OSG_NOTICE<<"timeout event ["<setActionKeyPosition(keyPosition); + } + } + else if (cur->name == "timeout_broadcast_event") + { + osgPresentation::KeyPosition keyPosition; + if (getKeyPositionInner( cur, keyPosition)) + { + OSG_NOTICE<<"timeout broadcast event ["<setActionBroadcastKeyPosition(keyPosition); + } + } + else if (cur->name == "idle_duration_before_timeout") + { + std::istringstream iss(cur->getTrimmedContents()); + double duration; + iss>>duration; + if (!iss.fail()) + { + OSG_NOTICE<<"timeout->setIdleDurationBeforeTimeoutDisplay("<setIdleDurationBeforeTimeoutDisplay(duration); + } + } + else if (cur->name == "idle_duration_before_action") + { + std::istringstream iss(cur->getTrimmedContents()); + double duration; + iss>>duration; + if (!iss.fail()) + { + OSG_NOTICE<<"timeout->setIdleDurationBeforeTimeoutAction("<setIdleDurationBeforeTimeoutAction(duration); + } + } + else if (cur->name == "key_starts_timeout_display") + { + osgPresentation::KeyPosition keyPosition; + if (getKeyPositionInner( cur, keyPosition) && keyPosition._key!=0) + { + OSG_NOTICE<<"timeout->setKeyStartsTimoutDisplay("<setKeyStartsTimoutDisplay(keyPosition._key); + } + } + else if (cur->name == "key_dismiss_timeout_display") + { + osgPresentation::KeyPosition keyPosition; + if (getKeyPositionInner( cur, keyPosition) && keyPosition._key!=0) + { + OSG_NOTICE<<"timeout->setKeyDismissTimoutDisplay("<setKeyDismissTimoutDisplay(keyPosition._key); + } + } + else if (cur->name == "key_run_action") + { + osgPresentation::KeyPosition keyPosition; + if (getKeyPositionInner( cur, keyPosition) && keyPosition._key!=0) + { + OSG_NOTICE<<"timeout->setKeyRunTimoutAction("<setKeyRunTimoutAction(keyPosition._key); + } + } + } + constructor.popCurrentLayer(); // return the } diff --git a/src/osgPresentation/Timeout.cpp b/src/osgPresentation/Timeout.cpp index 0a13df31b..2c39e4914 100644 --- a/src/osgPresentation/Timeout.cpp +++ b/src/osgPresentation/Timeout.cpp @@ -63,8 +63,12 @@ bool HUDSettings::getInverseModelViewMatrix(osg::Matrix& matrix, osg::NodeVisito Timeout::Timeout(HUDSettings* hudSettings): _previousFrameNumber(-1), _timeOfLastEvent(0.0), - _idleDurationBeforeTimeoutDisplay(5.0), - _idleDurationBeforeTimeoutAction(6.0) + _displayTimout(false), + _idleDurationBeforeTimeoutDisplay(4.0), + _idleDurationBeforeTimeoutAction(8.0), + _keyStartsTimoutDisplay(0), + _keyDismissTimoutDisplay(0), + _keyRunTimeoutAction(0) { _hudSettings = hudSettings; setCullingActive(false); @@ -101,7 +105,7 @@ void Timeout::traverse(osg::NodeVisitor& nv) if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) { double timeSinceLastEvent = nv.getFrameStamp() ? nv.getFrameStamp()->getReferenceTime()-_timeOfLastEvent : 0.0; - bool needToDisplay = (timeSinceLastEvent>_idleDurationBeforeTimeoutDisplay); + bool needToDisplay = _displayTimout || (timeSinceLastEvent>_idleDurationBeforeTimeoutDisplay); osgUtil::CullVisitor* cv = dynamic_cast(&nv); if (needToDisplay && cv) @@ -145,26 +149,48 @@ void Timeout::traverse(osg::NodeVisitor& nv) _previousFrameNumber = nv.getFrameStamp()->getFrameNumber(); bool needToRecordEventTime = false; - + bool needToAction = false; + if (deltaFrameNumber>1) { needToRecordEventTime = true; } - else - { - osgGA::EventVisitor* ev = dynamic_cast(&nv); - if (ev) + + osgGA::EventVisitor* ev = dynamic_cast(&nv); + osgViewer::Viewer* viewer = ev ? dynamic_cast(ev->getActionAdapter()) : 0; + if (ev) + { + osgGA::EventQueue::Events& events = ev->getEvents(); + for(osgGA::EventQueue::Events::iterator itr = events.begin(); + itr != events.end(); + ++itr) { - osgGA::EventQueue::Events& events = ev->getEvents(); - for(osgGA::EventQueue::Events::iterator itr = events.begin(); - itr != events.end(); - ++itr) + osgGA::GUIEventAdapter* event = itr->get(); + + bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP; + + if (keyEvent && event->getKey()==_keyStartsTimoutDisplay) { - osgGA::GUIEventAdapter* event = itr->get(); - if (event->getEventType()!=osgGA::GUIEventAdapter::FRAME) - { - needToRecordEventTime = true; - } + OSG_NOTICE<<"_keyStartsTimoutDisplay pressed"<getKey()==_keyDismissTimoutDisplay) + { + OSG_NOTICE<<"_keyDismissTimoutDisplay pressed"<getKey()==_keyRunTimeoutAction) + { + OSG_NOTICE<<"_keyRunTimeoutAction pressed"<getEventType()!=osgGA::GUIEventAdapter::FRAME) + { + needToRecordEventTime = true; } } } @@ -172,24 +198,59 @@ void Timeout::traverse(osg::NodeVisitor& nv) if (needToRecordEventTime) { _timeOfLastEvent = nv.getFrameStamp()->getReferenceTime(); + _displayTimout = false; } Transform::traverse(nv); double timeSinceLastEvent = nv.getFrameStamp() ? nv.getFrameStamp()->getReferenceTime()-_timeOfLastEvent : 0.0; - bool needToAction = (timeSinceLastEvent>_idleDurationBeforeTimeoutAction); + if (timeSinceLastEvent>_idleDurationBeforeTimeoutAction) needToAction = true; if (needToAction) { - OSG_NOTICE<<"Do action"<getReferenceTime(); - if (_jumpData.requiresJump()) + + if (_actionJumpData.requiresJump()) { - OSG_NOTICE<<"Doing jump"<dispatchEvent(_actionKeyPos); + } + + if (viewer && (_actionBroadcastKeyPos._key!=0 || _actionBroadcastKeyPos._x!=FLT_MAX || _actionBroadcastKeyPos._y!=FLT_MAX)) + { + OSG_NOTICE<<"Doing timeout broadcast key event"<<_actionBroadcastKeyPos._key< event = new osgGA::GUIEventAdapter; + + if (_actionBroadcastKeyPos._key!=0) event->setEventType(osgGA::GUIEventAdapter::KEYDOWN); + else event->setEventType(osgGA::GUIEventAdapter::MOVE); + + if (_actionBroadcastKeyPos._key!=0) event->setKey(_actionBroadcastKeyPos._key); + if (_actionBroadcastKeyPos._x!=FLT_MAX) event->setX(_actionBroadcastKeyPos._x); + if (_actionBroadcastKeyPos._y!=FLT_MAX) event->setY(_actionBroadcastKeyPos._y); + + event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); + + // dispatch cloned event to devices + osgViewer::View::Devices& devices = viewer->getDevices(); + for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i) + { + if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS) + { + (*i)->sendEvent(*event); + } + } + } + } }