Completed <timeout> support, to use it with p3d use it along the lines:
<slide>
<layer>
<paragraph>Test</paragraph>
<timeout>
<idle_duration_before_timeout>3.0</idle_duration_before_timeout>
<idle_duration_before_action>5.0</idle_duration_before_action>
<key_starts_timeout_display>A</key_starts_timeout_display>
<key_dismiss_timeout_display>S</key_dismiss_timeout_display>
<key_run_action>D</key_run_action>
<timeout_jump slide="0" layer="1"></timeout_jump>
<timeout_event>w</timeout_event>
<timeout_broadcast_event>t</timeout_broadcast_event>
<image width="0.5">Images/lz.rgb</image>
</timeout>
</layer>
<layer>
<model>cow.osg</model>
</layer>
</slide>
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1467,17 +1467,84 @@ void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& con
|
||||
}
|
||||
else if (cur->name == "timeout_jump")
|
||||
{
|
||||
OSG_NOTICE<<"Parsed Jump "<<std::endl;
|
||||
|
||||
osgPresentation::JumpData jumpData;
|
||||
if (getJumpProperties(cur, jumpData))
|
||||
{
|
||||
OSG_NOTICE<<"Timeout Jump "<<jumpData.relativeJump<<","<< jumpData.slideNum<<", "<<jumpData.layerNum<<std::endl;
|
||||
timeout->setJumpData(jumpData);
|
||||
timeout->setActionJumpData(jumpData);
|
||||
}
|
||||
}
|
||||
else if (cur->name == "timeout_event")
|
||||
{
|
||||
osgPresentation::KeyPosition keyPosition;
|
||||
if (getKeyPositionInner( cur, keyPosition))
|
||||
{
|
||||
OSG_NOTICE<<"timeout event ["<<keyPosition._key<<"]"<<std::endl;
|
||||
timeout->setActionKeyPosition(keyPosition);
|
||||
}
|
||||
}
|
||||
else if (cur->name == "timeout_broadcast_event")
|
||||
{
|
||||
osgPresentation::KeyPosition keyPosition;
|
||||
if (getKeyPositionInner( cur, keyPosition))
|
||||
{
|
||||
OSG_NOTICE<<"timeout broadcast event ["<<keyPosition._key<<"]"<<std::endl;
|
||||
timeout->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("<<duration<<")"<<std::endl;
|
||||
timeout->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("<<duration<<")"<<std::endl;
|
||||
timeout->setIdleDurationBeforeTimeoutAction(duration);
|
||||
}
|
||||
}
|
||||
else if (cur->name == "key_starts_timeout_display")
|
||||
{
|
||||
osgPresentation::KeyPosition keyPosition;
|
||||
if (getKeyPositionInner( cur, keyPosition) && keyPosition._key!=0)
|
||||
{
|
||||
OSG_NOTICE<<"timeout->setKeyStartsTimoutDisplay("<<keyPosition._key<<")"<<std::endl;
|
||||
timeout->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("<<keyPosition._key<<")"<<std::endl;
|
||||
timeout->setKeyDismissTimoutDisplay(keyPosition._key);
|
||||
}
|
||||
}
|
||||
else if (cur->name == "key_run_action")
|
||||
{
|
||||
osgPresentation::KeyPosition keyPosition;
|
||||
if (getKeyPositionInner( cur, keyPosition) && keyPosition._key!=0)
|
||||
{
|
||||
OSG_NOTICE<<"timeout->setKeyRunTimoutAction("<<keyPosition._key<<")"<<std::endl;
|
||||
timeout->setKeyRunTimoutAction(keyPosition._key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
constructor.popCurrentLayer(); // return the
|
||||
}
|
||||
|
||||
|
||||
@@ -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<osgUtil::CullVisitor*>(&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<osgGA::EventVisitor*>(&nv);
|
||||
if (ev)
|
||||
|
||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
||||
osgViewer::Viewer* viewer = ev ? dynamic_cast<osgViewer::Viewer*>(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"<<std::endl;
|
||||
_displayTimout = true;
|
||||
}
|
||||
else if (keyEvent && event->getKey()==_keyDismissTimoutDisplay)
|
||||
{
|
||||
OSG_NOTICE<<"_keyDismissTimoutDisplay pressed"<<std::endl;
|
||||
_displayTimout = false;
|
||||
needToRecordEventTime = true;
|
||||
}
|
||||
else if (keyEvent && event->getKey()==_keyRunTimeoutAction)
|
||||
{
|
||||
OSG_NOTICE<<"_keyRunTimeoutAction pressed"<<std::endl;
|
||||
_displayTimout = false;
|
||||
needToRecordEventTime = true;
|
||||
|
||||
needToAction = true;
|
||||
}
|
||||
else if (event->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"<<std::endl;
|
||||
OSG_NOTICE<<"Do timeout action"<<std::endl;
|
||||
_previousFrameNumber = -1;
|
||||
_timeOfLastEvent = nv.getFrameStamp()->getReferenceTime();
|
||||
|
||||
if (_jumpData.requiresJump())
|
||||
|
||||
if (_actionJumpData.requiresJump())
|
||||
{
|
||||
OSG_NOTICE<<"Doing jump"<<std::endl;
|
||||
_jumpData.jump(SlideEventHandler::instance());
|
||||
OSG_NOTICE<<"Doing timeout jump"<<std::endl;
|
||||
_actionJumpData.jump(SlideEventHandler::instance());
|
||||
}
|
||||
|
||||
if (_actionKeyPos._key!=0 || _actionKeyPos._x!=FLT_MAX || _actionKeyPos._y!=FLT_MAX)
|
||||
{
|
||||
OSG_NOTICE<<"Doing timeout key event"<<_actionKeyPos._key<<std::endl;
|
||||
if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_actionKeyPos);
|
||||
}
|
||||
|
||||
if (viewer && (_actionBroadcastKeyPos._key!=0 || _actionBroadcastKeyPos._x!=FLT_MAX || _actionBroadcastKeyPos._y!=FLT_MAX))
|
||||
{
|
||||
OSG_NOTICE<<"Doing timeout broadcast key event"<<_actionBroadcastKeyPos._key<<std::endl;
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user