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:
@@ -178,6 +178,7 @@ public:
|
||||
inline bool read(const std::string& str, osg::Vec4& value) const;
|
||||
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token) const;
|
||||
bool getKeyProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const;
|
||||
@@ -195,7 +196,7 @@ public:
|
||||
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const;
|
||||
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const;
|
||||
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const;
|
||||
bool getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const;
|
||||
bool getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const;
|
||||
|
||||
bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
|
||||
bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
|
||||
@@ -380,6 +381,40 @@ bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int&
|
||||
return read(itr->second,value);
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getKeyProperty(osgDB::XmlNode*cur, const char* token, int& value) const
|
||||
{
|
||||
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
|
||||
if (itr==cur->properties.end()) return false;
|
||||
|
||||
OSG_NOTICE<<"getKeyProperty()="<<itr->second<<std::endl;
|
||||
|
||||
if (itr->second.empty())
|
||||
{
|
||||
OSG_NOTICE<<" empty()"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itr->second.find("0x",0,2)!=std::string::npos)
|
||||
{
|
||||
std::istringstream iss(itr->second);
|
||||
iss>>std::hex>>value;
|
||||
return true;
|
||||
}
|
||||
else if (itr->second.size()>1 && (itr->second[0]>='0' && itr->second[0]<='9'))
|
||||
{
|
||||
std::istringstream iss(itr->second);
|
||||
iss>>value;
|
||||
OSG_NOTICE<<" numeric result = "<<value<<std::endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = itr->second[0];
|
||||
OSG_NOTICE<<" alphanumeric result = "<<value<<std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const
|
||||
{
|
||||
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
|
||||
@@ -922,19 +957,31 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
|
||||
return propertiesRead;
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const
|
||||
bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const
|
||||
{
|
||||
bool propertyRead = false;
|
||||
|
||||
if (getProperty(cur, "slide", slideNum))
|
||||
if (getProperty(cur, "slide_name", jumpData.slideName))
|
||||
{
|
||||
OSG_INFO<<"slide "<<slideNum<<std::endl;
|
||||
OSG_INFO<<"slide_name "<<jumpData.slideName<<std::endl;
|
||||
propertyRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "layer", layerNum))
|
||||
if (getProperty(cur, "slide", jumpData.slideNum))
|
||||
{
|
||||
OSG_INFO<<"layer "<<layerNum<<std::endl;
|
||||
OSG_INFO<<"slide "<<jumpData.slideNum<<std::endl;
|
||||
propertyRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "layer", jumpData.layerNum))
|
||||
{
|
||||
OSG_INFO<<"layer "<<jumpData.layerNum<<std::endl;
|
||||
propertyRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "layer_name", jumpData.layerName))
|
||||
{
|
||||
OSG_INFO<<"layer_name "<<jumpData.layerName<<std::endl;
|
||||
propertyRead = true;
|
||||
}
|
||||
|
||||
@@ -943,7 +990,7 @@ bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJum
|
||||
{
|
||||
OSG_INFO<<"jump "<<jumpType<<std::endl;
|
||||
propertyRead = true;
|
||||
relativeJump = (jumpType=="relative") || (jumpType=="Relative") || (jumpType=="RELATIVE") ;
|
||||
jumpData.relativeJump = (jumpType=="relative") || (jumpType=="Relative") || (jumpType=="RELATIVE") ;
|
||||
}
|
||||
|
||||
return propertyRead;
|
||||
@@ -1245,59 +1292,104 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
|
||||
{
|
||||
OSG_INFO<<"Parsed Jump "<<std::endl;
|
||||
|
||||
bool relativeJump = true;
|
||||
int slideNum = 0;
|
||||
int layerNum = 0;
|
||||
if (getJumpProperties(cur, relativeJump, slideNum, layerNum))
|
||||
osgPresentation::JumpData jumpData;
|
||||
if (getJumpProperties(cur, jumpData))
|
||||
{
|
||||
OSG_INFO<<"Layer Jump "<<relativeJump<<","<< slideNum<<", "<<layerNum<<std::endl;
|
||||
OSG_INFO<<"Layer Jump "<<jumpData.relativeJump<<","<< jumpData.slideNum<<", "<<jumpData.layerNum<<std::endl;
|
||||
|
||||
constructor.setLayerJump(relativeJump, slideNum, layerNum);
|
||||
constructor.setLayerJump(jumpData);
|
||||
}
|
||||
}
|
||||
else if (cur->name == "click_to_run")
|
||||
{
|
||||
bool relativeJump = true;
|
||||
int slideNum = 0;
|
||||
int layerNum = 0;
|
||||
getJumpProperties(cur, relativeJump, slideNum, layerNum);
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
OSG_INFO<<"click_to_run ["<<cur->contents<<"]"<<std::endl;
|
||||
constructor.layerClickToDoOperation(cur->contents,osgPresentation::RUN, relativeJump, slideNum, layerNum);
|
||||
constructor.layerClickToDoOperation(cur->contents,osgPresentation::RUN, jumpData);
|
||||
}
|
||||
else if (cur->name == "click_to_load")
|
||||
{
|
||||
bool relativeJump = true;
|
||||
int slideNum = 0;
|
||||
int layerNum = 0;
|
||||
getJumpProperties(cur, relativeJump, slideNum, layerNum);
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
OSG_INFO<<"click_to_load ["<<cur->contents<<"]"<<std::endl;
|
||||
constructor.layerClickToDoOperation(cur->contents,osgPresentation::LOAD, relativeJump, slideNum, layerNum);
|
||||
constructor.layerClickToDoOperation(cur->contents,osgPresentation::LOAD, jumpData);
|
||||
}
|
||||
|
||||
else if (cur->name == "click_to_event")
|
||||
{
|
||||
bool relativeJump = true;
|
||||
int slideNum = 0;
|
||||
int layerNum = 0;
|
||||
getJumpProperties(cur, relativeJump, slideNum, layerNum);
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
if (getKeyPositionInner( cur, keyPosition))
|
||||
{
|
||||
OSG_INFO<<"click_to_event ["<<keyPosition._key<<"]"<<std::endl;
|
||||
constructor.layerClickEventOperation(keyPosition, relativeJump, slideNum, layerNum);
|
||||
constructor.layerClickEventOperation(keyPosition, jumpData);
|
||||
}
|
||||
}
|
||||
|
||||
else if (cur->name == "click_to_jump")
|
||||
{
|
||||
bool relativeJump = true;
|
||||
int slideNum = 0;
|
||||
int layerNum = 0;
|
||||
getJumpProperties(cur, relativeJump, slideNum, layerNum);
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
constructor.layerClickEventOperation(osgPresentation::JUMP, relativeJump, slideNum, layerNum);
|
||||
constructor.layerClickEventOperation(osgPresentation::JUMP, jumpData);
|
||||
}
|
||||
|
||||
else if (cur->name == "key_to_run")
|
||||
{
|
||||
int key;
|
||||
if (getKeyProperty(cur, "key", key))
|
||||
{
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
OSG_NOTICE<<"key_to_run ["<<cur->contents<<"], key="<<key<<std::endl;
|
||||
constructor.keyToDoOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, cur->contents,osgPresentation::RUN, jumpData);
|
||||
}
|
||||
}
|
||||
else if (cur->name == "key_to_load")
|
||||
{
|
||||
int key;
|
||||
if (getKeyProperty(cur, "key", key))
|
||||
{
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
OSG_NOTICE<<"key_to_load ["<<cur->contents<<"]"<<std::endl;
|
||||
constructor.keyToDoOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, cur->contents,osgPresentation::LOAD, jumpData);
|
||||
}
|
||||
}
|
||||
|
||||
else if (cur->name == "key_to_event")
|
||||
{
|
||||
int key;
|
||||
if (getKeyProperty(cur, "key", key))
|
||||
{
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
if (getKeyPositionInner( cur, keyPosition))
|
||||
{
|
||||
OSG_NOTICE<<"key_to_event ["<<keyPosition._key<<"]"<<std::endl;
|
||||
constructor.keyEventOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, keyPosition, jumpData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (cur->name == "key_to_jump")
|
||||
{
|
||||
int key;
|
||||
if (getKeyProperty(cur, "key", key))
|
||||
{
|
||||
osgPresentation::JumpData jumpData;
|
||||
getJumpProperties(cur, jumpData);
|
||||
|
||||
OSG_NOTICE<<"key_to_jump"<<std::endl;
|
||||
|
||||
constructor.keyEventOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, osgPresentation::JUMP, jumpData);
|
||||
}
|
||||
}
|
||||
|
||||
else if (cur->name == "newline")
|
||||
@@ -1449,6 +1541,19 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
|
||||
constructor.translateTextCursor(osg::Vec3(-totalIndent,0.0f,0.0f));
|
||||
}
|
||||
|
||||
std::string name;
|
||||
if (getProperty(root, "layer_name", name))
|
||||
{
|
||||
if (constructor.getCurrentLayer())
|
||||
{
|
||||
constructor.getCurrentLayer()->setUserValue("name",name);
|
||||
OSG_NOTICE<<"Setting current layers name "<<name<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"getCurrentSlide() returns NULL, unable to set name "<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const
|
||||
@@ -1657,6 +1762,7 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
|
||||
{
|
||||
constructor.addLayer(true, true);
|
||||
parseLayer (constructor, cur);
|
||||
|
||||
}
|
||||
else if (cur->name == "layer")
|
||||
{
|
||||
@@ -1697,6 +1803,20 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
|
||||
}
|
||||
}
|
||||
|
||||
std::string name;
|
||||
if (getProperty(root, "slide_name", name))
|
||||
{
|
||||
if (constructor.getCurrentSlide())
|
||||
{
|
||||
constructor.getCurrentSlide()->setUserValue("name",name);
|
||||
OSG_NOTICE<<"Setting current slide name "<<name<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"getCurrentSlide() returns NULL, unable to set name "<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
constructor.setBackgroundColor(previous_bgcolor,false);
|
||||
constructor.setTextColor(previous_textcolor);
|
||||
|
||||
|
||||
@@ -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