Changeset 12911

Show
Ignore:
Timestamp:
01/24/12 15:27:17 (3 years ago)
Author:
robert
Message:

Refactored the click_to_run implementation to avoid bug associated with running the first click_to_run entry in a layer when
subsequent click to run's are called.

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgPresentation/SlideShowConstructor

    r12853 r12911  
    388388    void layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); 
    389389 
     390    void addToCurrentLayer(osg::Node* subgraph); 
     391     
    390392    void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData); 
    391393     
     
    512514    osg::ref_ptr<FilePathData>      _filePathData; 
    513515     
     516    osg::ref_ptr<osg::Group>                _layerToApplyEventCallbackTo; 
     517    osg::ref_ptr<osgGA::GUIEventHandler>    _currentEventCallbackToApply; 
     518 
     519 
    514520    std::string findFileAndRecordPath(const std::string& filename); 
    515521     
  • OpenSceneGraph/trunk/src/osgPresentation/SlideShowConstructor.cpp

    r12853 r12911  
    191191 
    192192    _slideBackgroundAsHUD = false; 
     193 
     194    _layerToApplyEventCallbackTo = 0; 
     195    _currentEventCallbackToApply = 0; 
    193196} 
    194197 
     
    437440                HUDTransform* hudTransform = new HUDTransform(_hudSettings.get()); 
    438441                hudTransform->addChild(background); 
    439                 _currentLayer->addChild(hudTransform); 
     442                addToCurrentLayer(hudTransform); 
    440443            } 
    441444            else 
    442445            { 
    443                 _currentLayer->addChild(background); 
     446                addToCurrentLayer(background); 
    444447            } 
    445448        } 
     
    467470            geode->addDrawable(text); 
    468471 
    469             _currentLayer->addChild(decorateSubgraphForPosition(geode, _titlePositionData)); 
     472            addToCurrentLayer(decorateSubgraphForPosition(geode, _titlePositionData)); 
    470473        } 
    471474         
     
    476479        for(unsigned int i=0;i<_previousLayer->getNumChildren();++i) 
    477480        { 
    478             _currentLayer->addChild(_previousLayer->getChild(i)); 
     481            addToCurrentLayer(_previousLayer->getChild(i)); 
    479482        } 
    480483    } 
     
    518521} 
    519522 
     523void SlideShowConstructor::addToCurrentLayer(osg::Node* subgraph) 
     524{ 
     525    if (!subgraph) return; 
     526     
     527    if (!_currentLayer) addLayer(); 
     528 
     529    if (_currentEventCallbackToApply.valid()) 
     530    { 
     531        if (subgraph->getEventCallback()==0) 
     532        { 
     533            if (_layerToApplyEventCallbackTo==0 || _currentLayer==_layerToApplyEventCallbackTo) 
     534            { 
     535                OSG_INFO<<"Assigning event callback."<<std::endl; 
     536                subgraph->setEventCallback(_currentEventCallbackToApply.get()); 
     537            } 
     538            else 
     539            { 
     540                OSG_INFO<<"Ignoring event callback from previous layer."<<std::endl; 
     541            } 
     542        } 
     543        else 
     544        { 
     545            OSG_NOTICE<<"Warning: subgraph already has event callback assigned, cannot add second event callback."<<std::endl; 
     546        } 
     547        _currentEventCallbackToApply = 0; 
     548    } 
     549    _currentLayer->addChild(subgraph); 
     550} 
     551 
    520552void SlideShowConstructor::layerClickToDoOperation(Operation operation, bool relativeJump, int slideNum, int layerNum) 
    521553{ 
    522     if (!_currentLayer) addLayer(); 
    523      
    524     if (_currentLayer.valid()) 
    525     { 
    526         if (_previousLayer==_currentLayer) 
    527         { 
    528             if (_currentLayer->getNumChildren()>0) 
    529             { 
    530                 OSG_INFO<<"creating new group within layer"<<std::endl; 
    531                 osg::Group* group = new osg::Group; 
    532                 _currentLayer->addChild(group); 
    533                 _currentLayer = group; 
    534             } 
    535         } 
    536         else 
    537         { 
    538             OSG_INFO<<"creating secondary group within layer"<<std::endl; 
    539             osg::Group* group = new osg::Group; 
    540             _previousLayer->addChild(group); 
    541             _currentLayer = group; 
    542         }                 
    543         _currentLayer->setEventCallback(new PickEventHandler(operation, relativeJump, slideNum, layerNum)); 
    544     } 
    545      
     554    _layerToApplyEventCallbackTo = _currentLayer; 
     555    _currentEventCallbackToApply = new PickEventHandler(operation, relativeJump, slideNum, layerNum); 
    546556} 
    547557 
    548558 
    549559void SlideShowConstructor::layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump, int slideNum, int layerNum) 
    550 { 
    551     if (!_currentLayer) addLayer(); 
    552      
    553     if (_currentLayer.valid()) 
    554     { 
    555         if (_previousLayer==_currentLayer) 
    556         { 
    557             if (_currentLayer->getNumChildren()>0) 
    558             { 
    559                 OSG_INFO<<"creating new group within layer"<<std::endl; 
    560                 osg::Group* group = new osg::Group; 
    561                 _currentLayer->addChild(group); 
    562                 _currentLayer = group; 
    563             } 
    564         } 
    565         else 
    566         { 
    567             OSG_INFO<<"creating secondary group within layer"<<std::endl; 
    568             osg::Group* group = new osg::Group; 
    569             _previousLayer->addChild(group); 
    570             _currentLayer = group; 
    571         }                 
    572         _currentLayer->setEventCallback(new PickEventHandler(command, operation, relativeJump, slideNum, layerNum)); 
    573     } 
    574      
     560{     
     561    _layerToApplyEventCallbackTo = _currentLayer; 
     562    _currentEventCallbackToApply = new PickEventHandler(command, operation, relativeJump, slideNum, layerNum); 
    575563} 
    576564 
     
    578566void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum) 
    579567{ 
    580     if (!_currentLayer) addLayer(); 
    581      
    582     if (_currentLayer.valid()) 
    583     { 
    584         if (_previousLayer==_currentLayer) 
    585         { 
    586             if (_currentLayer->getNumChildren()>0) 
    587             { 
    588                 OSG_INFO<<"creating new group within layer"<<std::endl; 
    589                 osg::Group* group = new osg::Group; 
    590                 _currentLayer->addChild(group); 
    591                 _currentLayer = group; 
    592             } 
    593         } 
    594         else 
    595         { 
    596             OSG_INFO<<"creating secondary group within layer"<<std::endl; 
    597             osg::Group* group = new osg::Group; 
    598             _previousLayer->addChild(group); 
    599             _currentLayer = group; 
    600         }                 
    601         _currentLayer->setEventCallback(new PickEventHandler(keyPos, relativeJump, slideNum, layerNum)); 
    602     } 
    603      
     568    _layerToApplyEventCallbackTo = _currentLayer; 
     569    _currentEventCallbackToApply = new PickEventHandler(keyPos, relativeJump, slideNum, layerNum); 
    604570} 
    605571 
     
    639605void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData) 
    640606{ 
    641     if (!_currentLayer) addLayer(); 
    642  
    643607    osg::Geode* geode = new osg::Geode; 
    644608 
     
    678642    geode->addDrawable(text); 
    679643     
    680     _currentLayer->addChild( decorateSubgraphForPosition(geode, positionData) ); 
     644    addToCurrentLayer( decorateSubgraphForPosition(geode, positionData) ); 
    681645 
    682646    bool needToApplyPosition = (_textPositionData.position == positionData.position); 
     
    689653void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData) 
    690654{ 
    691     if (!_currentLayer) addLayer(); 
    692  
    693655    osg::Geode* geode = new osg::Geode; 
    694656 
     
    727689    geode->addDrawable(text); 
    728690     
    729     _currentLayer->addChild( decorateSubgraphForPosition(geode, positionData) ); 
     691    addToCurrentLayer( decorateSubgraphForPosition(geode, positionData) ); 
    730692 
    731693    bool needToApplyPosition = (_textPositionData.position == positionData.position); 
     
    878840void SlideShowConstructor::addImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData) 
    879841{ 
    880     if (!_currentLayer) addLayer(); 
    881  
    882842    osg::ref_ptr<osgDB::Options> options = _options; 
    883843    if (!imageData.options.empty()) 
     
    1017977    } 
    1018978 
    1019     _currentLayer->addChild(subgraph); 
     979    addToCurrentLayer(subgraph); 
    1020980} 
    1021981 
    1022982void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight, const ImageData& imageDataRight,const PositionData& positionData) 
    1023983{ 
    1024     if (!_currentLayer) addLayer(); 
    1025  
    1026984    osg::ref_ptr<osgDB::Options> optionsLeft = _options; 
    1027985    if (!imageDataLeft.options.empty()) 
     
    12271185    } 
    12281186 
    1229     _currentLayer->addChild(subgraph); 
     1187    addToCurrentLayer(subgraph); 
    12301188} 
    12311189 
     
    13461304osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData) 
    13471305{ 
    1348     if (!_currentLayer) addLayer(); 
    1349  
    13501306    osg::ref_ptr<osgDB::Options> options = _options; 
    13511307    if (!imageData.options.empty()) 
     
    14691425    } 
    14701426 
    1471     _currentLayer->addChild(subgraph); 
     1427    addToCurrentLayer(subgraph); 
    14721428 
    14731429    osgWidget::PdfImage* pdfImage = dynamic_cast<osgWidget::PdfImage*>(image); 
     
    17241680    findImageStreamsAndAddCallbacks(subgraph); 
    17251681 
    1726     _currentLayer->addChild(subgraph); 
     1682    addToCurrentLayer(subgraph); 
    17271683} 
    17281684