diff --git a/examples/slideshow3D/ReaderWriterXML.cpp b/examples/slideshow3D/ReaderWriterXML.cpp index 9dbe73179..105d78e36 100644 --- a/examples/slideshow3D/ReaderWriterXML.cpp +++ b/examples/slideshow3D/ReaderWriterXML.cpp @@ -189,6 +189,12 @@ void ReaderWriterSS3D::parseLayer(SlideShowConstructor& constructor, xmlDocPtr d { parseModel(constructor, doc,cur); } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (key) constructor.setLayerDuration(atof((const char*)key)); + xmlFree(key); + } cur = cur->next; } } @@ -221,6 +227,12 @@ void ReaderWriterSS3D::parseSlide (SlideShowConstructor& constructor, xmlDocPtr { parseLayer (constructor, doc, cur); } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (key) constructor.setSlideDuration(atof((const char*)key)); + xmlFree(key); + } cur = cur->next; } return; @@ -290,6 +302,12 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSS3D::readNode(const std::string& fi if (key) constructor.setTextColor(mapStringToColor((const char*)key)); xmlFree(key); } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (key) constructor.setPresentationDuration(atof((const char*)key)); + xmlFree(key); + } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"slide"))) { parseSlide (constructor, doc, cur); diff --git a/examples/slideshow3D/SlideEventHandler.cpp b/examples/slideshow3D/SlideEventHandler.cpp index 868b7c86e..bf2a7abdb 100644 --- a/examples/slideshow3D/SlideEventHandler.cpp +++ b/examples/slideshow3D/SlideEventHandler.cpp @@ -1,4 +1,5 @@ #include "SlideEventHandler.h" +#include "SlideShowConstructor.h" class FindNamedSwitchVisitor : public osg::NodeVisitor { @@ -49,6 +50,14 @@ void SlideEventHandler::set(osg::Node* model) { std::cout<<"Presentation '"<getName()<<"'"<(_presentationSwitch->getUserData()); + if (durationData) + { + std::cout<<"Presentation time set to "<duration<duration; + } + selectSlide(0); } else @@ -76,6 +85,24 @@ void SlideEventHandler::set(osg::Node* model) } } +double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const +{ + const SlideShowConstructor::Duration* durationData = dynamic_cast(_slideSwitch->getChild(_activeLayer)->getUserData()); + if (durationData) + { + return durationData->duration; + } + + durationData = dynamic_cast(_slideSwitch->getUserData()); + if (durationData) + { + return durationData->duration; + } + + return _timePerSlide; +} + + bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) @@ -91,7 +118,7 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction _firstTraversal = false; _previousTime = time; } - else if (time-_previousTime>_timePerSlide) + else if (time-_previousTime>getCurrentTimeDelayBetweenSlides()) { _previousTime = time; diff --git a/examples/slideshow3D/SlideEventHandler.h b/examples/slideshow3D/SlideEventHandler.h index fe0d30ae8..306c3ce29 100644 --- a/examples/slideshow3D/SlideEventHandler.h +++ b/examples/slideshow3D/SlideEventHandler.h @@ -58,6 +58,8 @@ public: void setTimeDelayBetweenSlides(double dt) { _timePerSlide = dt; } double getTimeDelayBetweenSlides() const { return _timePerSlide; } + double getCurrentTimeDelayBetweenSlides() const; + protected: ~SlideEventHandler() {} diff --git a/examples/slideshow3D/SlideShowConstructor.cpp b/examples/slideshow3D/SlideShowConstructor.cpp index 1f49b015a..9dc324dce 100644 --- a/examples/slideshow3D/SlideShowConstructor.cpp +++ b/examples/slideshow3D/SlideShowConstructor.cpp @@ -22,6 +22,14 @@ SlideShowConstructor::SlideShowConstructor() _backgroundColor.set(0.0f,0.0f,0.0f,1.0f); _textColor.set(1.0f,1.0f,1.0f,1.0f); _textFont = "fonts/arial.ttf"; + + _titlePositionRatios = osg::Vec3(0.5f,0.0f,0.92f); + _titleAlignment = osgText::Text::CENTER_BASE_LINE; + + _titlePositionRatios = osg::Vec3(0.1f,0.0f,0.92f); + _titleAlignment = osgText::Text::LEFT_BASE_LINE; + + _presentationDuration = 0.0; } @@ -50,7 +58,7 @@ void SlideShowConstructor::createPresentation() { _titleHeight = _slideHeight*0.06f; _titleWidth = _slideWidth*0.8f; - _titleOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.5f,0.0f,_slideHeight*0.98f-_titleHeight); + _titleOrigin = _slideOrigin + osg::Vec3(_titlePositionRatios.x()*_slideWidth,_titlePositionRatios.y()*1.0f,_titlePositionRatios.z()*_slideHeight); _textHeight = _slideHeight*0.04f; _textWidth = _slideWidth*0.8f; @@ -76,6 +84,11 @@ void SlideShowConstructor::createPresentation() hp->eye = slideCenter+osg::Vec3(0.0f,-distanceToHeightRatio*_slideHeight,0.0f); hp->center = slideCenter; hp->up.set(0.0f,0.0f,1.0f); + + if (_presentationDuration!=0.0) + { + _presentationSwitch->setUserData(new Duration(_presentationDuration)); + } _root->setUserData(hp); @@ -98,6 +111,14 @@ void SlideShowConstructor::setPresentationName(const std::string& name) if (_presentationSwitch.valid()) _presentationSwitch->setName(std::string("Presentation_")+_presentationName); } +void SlideShowConstructor::setPresentationDuration(double duration) +{ + _presentationDuration = duration; + if (_presentationDuration!=0.0 && _presentationSwitch.valid()) + { + _presentationSwitch->setUserData(new Duration(_presentationDuration)); + } +} void SlideShowConstructor::addSlide() { @@ -117,6 +138,17 @@ void SlideShowConstructor::addSlide() _currentLayer = 0; } + +void SlideShowConstructor::setSlideDuration(double duration) +{ + if (!_slide) addSlide(); + + if (_slide.valid()) + { + _slide->setUserData(new Duration(duration)); + } +} + void SlideShowConstructor::addLayer() { if (!_slide) addSlide(); @@ -162,7 +194,7 @@ void SlideShowConstructor::addLayer() text->setCharacterSize(_titleHeight); text->setMaximumWidth(_titleWidth); text->setAxisAlignment(osgText::Text::XZ_PLANE); - text->setAlignment(osgText::Text::CENTER_BASE_LINE); + text->setAlignment(_titleAlignment); text->setPosition(_titleOrigin); text->setText(_slideTitle); @@ -184,6 +216,17 @@ void SlideShowConstructor::addLayer() } +void SlideShowConstructor::setLayerDuration(double duration) +{ + if (!_currentLayer) addLayer(); + + if (_currentLayer.valid()) + { + _currentLayer->setUserData(new Duration(duration)); + } +} + + void SlideShowConstructor::addBullet(const std::string& bullet) { if (!_currentLayer) addLayer(); diff --git a/examples/slideshow3D/SlideShowConstructor.h b/examples/slideshow3D/SlideShowConstructor.h index f457fe786..27955219e 100644 --- a/examples/slideshow3D/SlideShowConstructor.h +++ b/examples/slideshow3D/SlideShowConstructor.h @@ -6,6 +6,7 @@ #include #include #include +#include class SlideShowConstructor { @@ -15,11 +16,24 @@ public: struct HomePosition : public osg::Referenced { + HomePosition() {} + + HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up): + eye(in_eye), + center(in_center), + up(in_up) {} + osg::Vec3 eye; osg::Vec3 center; osg::Vec3 up; }; + struct Duration : public osg::Referenced + { + Duration(double in_duration):duration(in_duration) {} + + double duration; + }; void createPresentation(); @@ -33,14 +47,22 @@ public: void setPresentationAspectRatio(const std::string& str); + void setPresentationDuration(double duration); + + void addSlide(); void setSlideTitle(const std::string& name) { _slideTitle = name; } void setSlideBackground(const std::string& name) { _slideBackgroundImageFileName = name; } + void setSlideDuration(double duration); + + void addLayer(); + void setLayerDuration(double duration); + void addBullet(const std::string& bullet); void addParagraph(const std::string& paragraph); @@ -75,9 +97,12 @@ protected: float _textHeight; float _textWidth; std::string _presentationName; + double _presentationDuration; - + osg::Vec3 _titlePositionRatios; + osgText::Text::AlignmentType _titleAlignment; osg::Vec3 _titleOrigin; + osg::Vec3 _textOrigin; osg::Vec3 _imageOrigin; osg::Vec3 _modelLeft;