Added support for naming slides and layers with slide_name and layer_name properties respectively.
Added support for creating events based on key presses using a <key_to_run> and <key_to_jump> tags.
This commit is contained in:
@@ -12,6 +12,7 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/AnimationMaterial
|
||||
${HEADER_PATH}/CompileSlideCallback
|
||||
${HEADER_PATH}/PickEventHandler
|
||||
${HEADER_PATH}/KeyEventHandler
|
||||
${HEADER_PATH}/SlideEventHandler
|
||||
${HEADER_PATH}/SlideShowConstructor
|
||||
)
|
||||
@@ -21,6 +22,7 @@ SET(TARGET_SRC
|
||||
AnimationMaterial.cpp
|
||||
CompileSlideCallback.cpp
|
||||
PickEventHandler.cpp
|
||||
KeyEventHandler.cpp
|
||||
SlideEventHandler.cpp
|
||||
SlideShowConstructor.cpp
|
||||
${OPENSCENEGRAPH_VERSIONINFO_RC}
|
||||
|
||||
@@ -21,29 +21,23 @@
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum):
|
||||
PickEventHandler::PickEventHandler(osgPresentation::Operation operation, const JumpData& jumpData):
|
||||
_operation(operation),
|
||||
_relativeJump(relativeJump),
|
||||
_slideNum(slideNum),
|
||||
_layerNum(layerNum)
|
||||
_jumpData(jumpData)
|
||||
{
|
||||
}
|
||||
|
||||
PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum):
|
||||
PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation, const JumpData& jumpData):
|
||||
_command(str),
|
||||
_operation(operation),
|
||||
_relativeJump(relativeJump),
|
||||
_slideNum(slideNum),
|
||||
_layerNum(layerNum)
|
||||
_jumpData(jumpData)
|
||||
{
|
||||
}
|
||||
|
||||
PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum):
|
||||
PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos, const JumpData& jumpData):
|
||||
_keyPos(keyPos),
|
||||
_operation(osgPresentation::EVENT),
|
||||
_relativeJump(relativeJump),
|
||||
_slideNum(slideNum),
|
||||
_layerNum(layerNum)
|
||||
_jumpData(jumpData)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -101,21 +95,6 @@ void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
||||
{
|
||||
}
|
||||
|
||||
void PickEventHandler::setRelativeJump(int slideNum, int layerNum)
|
||||
{
|
||||
_relativeJump = true;
|
||||
_slideNum = slideNum;
|
||||
_layerNum = layerNum;
|
||||
}
|
||||
|
||||
void PickEventHandler::setAbsoluteJump(int slideNum, int layerNum)
|
||||
{
|
||||
_relativeJump = false;
|
||||
_slideNum = slideNum;
|
||||
_layerNum = layerNum;
|
||||
}
|
||||
|
||||
|
||||
void PickEventHandler::doOperation()
|
||||
{
|
||||
switch(_operation)
|
||||
@@ -198,29 +177,9 @@ void PickEventHandler::doOperation()
|
||||
}
|
||||
}
|
||||
|
||||
if (requiresJump())
|
||||
if (_jumpData.requiresJump())
|
||||
{
|
||||
OSG_NOTICE<<"Requires jump "<<_relativeJump<<", "<<_slideNum<<", "<<_layerNum<<std::endl;
|
||||
|
||||
if (_relativeJump)
|
||||
{
|
||||
int previousSlide = SlideEventHandler::instance()->getActiveSlide();
|
||||
int previousLayer = SlideEventHandler::instance()->getActiveLayer();
|
||||
int newSlide = previousSlide + _slideNum;
|
||||
int newLayer = previousLayer + _layerNum;
|
||||
if (newLayer<0)
|
||||
{
|
||||
newLayer = 0;
|
||||
}
|
||||
|
||||
OSG_NOTICE<<" jump to "<<newSlide<<", "<<newLayer<<std::endl;
|
||||
|
||||
SlideEventHandler::instance()->selectSlide(newSlide, newLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
SlideEventHandler::instance()->selectSlide(_slideNum,_layerNum);
|
||||
}
|
||||
_jumpData.jump(SlideEventHandler::instance());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
|
||||
#include <osgPresentation/AnimationMaterial>
|
||||
@@ -35,6 +37,75 @@ static osg::observer_ptr<SlideEventHandler> s_seh;
|
||||
|
||||
SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); }
|
||||
|
||||
bool JumpData::jump(SlideEventHandler* seh) const
|
||||
{
|
||||
OSG_INFO<<"Requires jump "<<relativeJump<<", "<<slideNum<<", "<<layerNum<<", "<<slideName<<", "<<layerName<<std::endl;
|
||||
|
||||
int slideNumToUse = slideNum;
|
||||
int layerNumToUse = layerNum;
|
||||
|
||||
if (!slideName.empty())
|
||||
{
|
||||
osg::Switch* presentation = seh->getPresentationSwitch();
|
||||
|
||||
for(unsigned int i=0; i<presentation->getNumChildren(); ++i)
|
||||
{
|
||||
osg::Node* node = seh->getSlide(i);
|
||||
std::string name;
|
||||
if (node->getUserValue("name",name) && slideName==name)
|
||||
{
|
||||
slideNumToUse = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (relativeJump)
|
||||
{
|
||||
slideNumToUse = seh->getActiveSlide() + slideNum;
|
||||
}
|
||||
|
||||
|
||||
if (!layerName.empty())
|
||||
{
|
||||
osg::Switch* slide = seh->getSlide(slideNumToUse);
|
||||
if (slide)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i=0; i<slide->getNumChildren(); ++i)
|
||||
{
|
||||
osg::Node* node = slide->getChild(i);
|
||||
std::string name;
|
||||
if (node->getUserValue("name",name))
|
||||
{
|
||||
if (layerName==name)
|
||||
{
|
||||
layerNumToUse = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i==slide->getNumChildren())
|
||||
{
|
||||
OSG_INFO<<"Could not find layer with "<<layerName<<std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_INFO<<"No appropriate Slide found."<<std::endl;
|
||||
}
|
||||
}
|
||||
else if (relativeJump)
|
||||
{
|
||||
layerNumToUse = seh->getActiveLayer() + layerNum;
|
||||
}
|
||||
|
||||
if (slideNumToUse<0) slideNumToUse = 0;
|
||||
if (layerNumToUse<0) layerNumToUse = 0;
|
||||
|
||||
OSG_INFO<<" jump to "<<slideNumToUse<<", "<<layerNumToUse<<std::endl;
|
||||
return seh->selectSlide(slideNumToUse,layerNumToUse);
|
||||
}
|
||||
|
||||
void LayerAttributes::callEnterCallbacks(osg::Node* node)
|
||||
{
|
||||
OSG_INFO<<"LayerAttributes::callEnterCallbacks("<<node<<")"<<std::endl;
|
||||
@@ -441,7 +512,15 @@ void ActiveOperators::collect(osg::Node* incommingNode, osg::NodeVisitor::Traver
|
||||
_current.clear();
|
||||
|
||||
FindOperatorsVisitor fov(_current, tm);
|
||||
incommingNode->accept(fov);
|
||||
|
||||
if (incommingNode)
|
||||
{
|
||||
incommingNode->accept(fov);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"ActiveOperators::collect() incommingNode="<<incommingNode<<std::endl;
|
||||
}
|
||||
|
||||
OSG_INFO<<"ActiveOperators::collect("<<incommingNode<<")"<<std::endl;
|
||||
OSG_INFO<<" _previous.size()="<<_previous.size()<<std::endl;
|
||||
@@ -1098,6 +1177,21 @@ unsigned int SlideEventHandler::getNumSlides()
|
||||
else return 0;
|
||||
}
|
||||
|
||||
osg::Switch* SlideEventHandler::getSlide(int slideNum)
|
||||
{
|
||||
if (slideNum<0 || slideNum>static_cast<int>(_presentationSwitch->getNumChildren())) return 0;
|
||||
|
||||
FindNamedSwitchVisitor findSlide("Slide");
|
||||
_presentationSwitch->getChild(slideNum)->accept(findSlide);
|
||||
return findSlide._switch;
|
||||
}
|
||||
|
||||
osg::Node* SlideEventHandler::getLayer(int slideNum, int layerNum)
|
||||
{
|
||||
osg::Switch* slide = getSlide(slideNum);
|
||||
return (slide && (layerNum>=0 && layerNum<static_cast<int>(slide->getNumChildren()))) ? slide->getChild(layerNum) : 0;
|
||||
}
|
||||
|
||||
|
||||
bool SlideEventHandler::selectSlide(int slideNum,int layerNum)
|
||||
{
|
||||
@@ -1245,25 +1339,9 @@ bool SlideEventHandler::nextSlide()
|
||||
{
|
||||
OSG_INFO<<"nextSlide()"<<std::endl;
|
||||
LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast<LayerAttributes*>(_slideSwitch->getUserData()) : 0;
|
||||
if (la && la->requiresJump())
|
||||
if (la && la->getJumpData().requiresJump())
|
||||
{
|
||||
if (la->getRelativeJump())
|
||||
{
|
||||
int previousSlide = getActiveSlide();
|
||||
int previousLayer = getActiveLayer();
|
||||
int newSlide = previousSlide + la->getSlideNum();
|
||||
int newLayer = previousLayer + la->getLayerNum();
|
||||
if (newLayer<0)
|
||||
{
|
||||
newLayer = 0;
|
||||
}
|
||||
|
||||
return selectSlide(newSlide, newLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
return selectSlide(la->getSlideNum(),la->getLayerNum());
|
||||
}
|
||||
return la->getJumpData().jump(this);
|
||||
}
|
||||
|
||||
if (selectSlide(_activeSlide+1)) return true;
|
||||
@@ -1294,25 +1372,9 @@ bool SlideEventHandler::nextLayer()
|
||||
{
|
||||
la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer));
|
||||
|
||||
if (la->requiresJump())
|
||||
if (la->getJumpData().requiresJump())
|
||||
{
|
||||
if (la->getRelativeJump())
|
||||
{
|
||||
int previousSlide = getActiveSlide();
|
||||
int previousLayer = getActiveLayer();
|
||||
int newSlide = previousSlide + la->getSlideNum();
|
||||
int newLayer = previousLayer + la->getLayerNum();
|
||||
if (newLayer<0)
|
||||
{
|
||||
newLayer = 0;
|
||||
}
|
||||
|
||||
return selectSlide(newSlide, newLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
return selectSlide(la->getSlideNum(),la->getLayerNum());
|
||||
}
|
||||
return la->getJumpData().jump(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
#include <osgPresentation/AnimationMaterial>
|
||||
#include <osgPresentation/PickEventHandler>
|
||||
#include <osgPresentation/KeyEventHandler>
|
||||
|
||||
#include <osgManipulator/TabBoxDragger>
|
||||
#include <osgManipulator/TabBoxTrackballDragger>
|
||||
@@ -199,7 +200,7 @@ SlideShowConstructor::SlideShowConstructor(osgDB::Options* options):
|
||||
_slideBackgroundAsHUD = false;
|
||||
|
||||
_layerToApplyEventCallbackTo = 0;
|
||||
_currentEventCallbackToApply = 0;
|
||||
_currentEventCallbacksToApply.clear();
|
||||
}
|
||||
|
||||
void SlideShowConstructor::setPresentationAspectRatio(float aspectRatio)
|
||||
@@ -393,6 +394,7 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
|
||||
if (!_slide) addSlide();
|
||||
|
||||
_currentLayer = new osg::Group;
|
||||
_currentLayer->setName("Layer");
|
||||
|
||||
// OSG_NOTICE<<"addLayer"<<std::endl;
|
||||
|
||||
@@ -542,14 +544,22 @@ void SlideShowConstructor::addToCurrentLayer(osg::Node* subgraph)
|
||||
|
||||
if (!_currentLayer) addLayer();
|
||||
|
||||
if (_currentEventCallbackToApply.valid())
|
||||
OSG_NOTICE<<"_currentEventCallbacksToApply.size()="<<_currentEventCallbacksToApply.size()<<std::endl;
|
||||
if (!_currentEventCallbacksToApply.empty())
|
||||
{
|
||||
OSG_NOTICE<<" subgraph->getEventCallback()=="<<subgraph->getEventCallback()<<std::endl;
|
||||
if (subgraph->getEventCallback()==0)
|
||||
{
|
||||
if (_layerToApplyEventCallbackTo==0 || _currentLayer==_layerToApplyEventCallbackTo)
|
||||
{
|
||||
OSG_INFO<<"Assigning event callback."<<std::endl;
|
||||
subgraph->setEventCallback(_currentEventCallbackToApply.get());
|
||||
OSG_NOTICE<<"Assigning event callbacks."<<std::endl;
|
||||
|
||||
for(EventHandlerList::iterator itr = _currentEventCallbacksToApply.begin();
|
||||
itr != _currentEventCallbacksToApply.end();
|
||||
++itr)
|
||||
{
|
||||
subgraph->addEventCallback(itr->get());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -560,29 +570,65 @@ void SlideShowConstructor::addToCurrentLayer(osg::Node* subgraph)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: subgraph already has event callback assigned, cannot add second event callback."<<std::endl;
|
||||
}
|
||||
_currentEventCallbackToApply = 0;
|
||||
_currentEventCallbacksToApply.clear();
|
||||
}
|
||||
_currentLayer->addChild(subgraph);
|
||||
}
|
||||
|
||||
void SlideShowConstructor::layerClickToDoOperation(Operation operation, bool relativeJump, int slideNum, int layerNum)
|
||||
void SlideShowConstructor::addEventHandler(PresentationContext presentationContext, osg::ref_ptr<osgGA::GUIEventHandler> handler)
|
||||
{
|
||||
_layerToApplyEventCallbackTo = _currentLayer;
|
||||
_currentEventCallbackToApply = new PickEventHandler(operation, relativeJump, slideNum, layerNum);
|
||||
switch(presentationContext)
|
||||
{
|
||||
case(CURRENT_PRESENTATION):
|
||||
OSG_NOTICE<<"Need to add event handler to presentation."<<std::endl;
|
||||
break;
|
||||
case(CURRENT_SLIDE):
|
||||
OSG_NOTICE<<"Need to add event handler to slide."<<std::endl;
|
||||
break;
|
||||
case(CURRENT_LAYER):
|
||||
OSG_INFO<<"Add event handler to layer."<<std::endl;
|
||||
_layerToApplyEventCallbackTo = _currentLayer;
|
||||
_currentEventCallbacksToApply.push_back(handler);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SlideShowConstructor::keyToDoOperation(PresentationContext presentationContext, int key, Operation operation, const JumpData& jumpData)
|
||||
{
|
||||
OSG_INFO<<"keyToDoOperation(key="<<key<<", operation="<<operation<<")"<<std::endl;
|
||||
addEventHandler(presentationContext, new KeyEventHandler(key, operation, jumpData));
|
||||
}
|
||||
|
||||
|
||||
void SlideShowConstructor::layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump, int slideNum, int layerNum)
|
||||
void SlideShowConstructor::keyToDoOperation(PresentationContext presentationContext, int key, const std::string& command, Operation operation, const JumpData& jumpData)
|
||||
{
|
||||
_layerToApplyEventCallbackTo = _currentLayer;
|
||||
_currentEventCallbackToApply = new PickEventHandler(command, operation, relativeJump, slideNum, layerNum);
|
||||
OSG_INFO<<"keyToDoOperation(key="<<key<<",command="<<command<<")"<<std::endl;
|
||||
addEventHandler(presentationContext, new KeyEventHandler(key, command, operation, jumpData));
|
||||
}
|
||||
|
||||
|
||||
void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum)
|
||||
void SlideShowConstructor::keyEventOperation(PresentationContext presentationContext, int key, const KeyPosition& keyPos, const JumpData& jumpData)
|
||||
{
|
||||
_layerToApplyEventCallbackTo = _currentLayer;
|
||||
_currentEventCallbackToApply = new PickEventHandler(keyPos, relativeJump, slideNum, layerNum);
|
||||
OSG_INFO<<"keyEventOperation(key="<<key<<")"<<std::endl;
|
||||
addEventHandler(presentationContext, new KeyEventHandler(key, keyPos, jumpData));
|
||||
}
|
||||
|
||||
|
||||
void SlideShowConstructor::layerClickToDoOperation(Operation operation, const JumpData& jumpData)
|
||||
{
|
||||
addEventHandler(CURRENT_LAYER, new PickEventHandler(operation, jumpData));
|
||||
}
|
||||
|
||||
|
||||
void SlideShowConstructor::layerClickToDoOperation(const std::string& command, Operation operation, const JumpData& jumpData)
|
||||
{
|
||||
addEventHandler(CURRENT_LAYER, new PickEventHandler(command, operation, jumpData));
|
||||
}
|
||||
|
||||
|
||||
void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, const JumpData& jumpData)
|
||||
{
|
||||
addEventHandler(CURRENT_LAYER, new PickEventHandler(keyPos, jumpData));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user