/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ #include #include #include #include #include #include using namespace osgPresentation; PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): _operation(operation), _relativeJump(relativeJump), _slideNum(slideNum), _layerNum(layerNum) { } PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): _command(str), _operation(operation), _relativeJump(relativeJump), _slideNum(slideNum), _layerNum(layerNum) { } PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): _keyPos(keyPos), _operation(osgPresentation::EVENT), _relativeJump(relativeJump), _slideNum(slideNum), _layerNum(layerNum) { } bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::MOVE): case(osgGA::GUIEventAdapter::PUSH): case(osgGA::GUIEventAdapter::RELEASE): { osgViewer::Viewer* viewer = dynamic_cast(&aa); osgUtil::LineSegmentIntersector::Intersections intersections; if (viewer->computeIntersections(ea.getX(),ea.getY(), nv->getNodePath(), intersections)) { for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin(); hitr!=intersections.end(); ++hitr) { if (ea.getEventType()==osgGA::GUIEventAdapter::MOVE) { OSG_INFO<<"Tooltip..."<className()<dispatchEvent(_keyPos); break; } case(osgPresentation::JUMP): { OSG_NOTICE<<"Requires jump "<getActiveSlide(); int previousLayer = SlideEventHandler::instance()->getActiveLayer(); int newSlide = previousSlide + _slideNum; int newLayer = previousLayer + _layerNum; if (newLayer<0) { newLayer = 0; } OSG_NOTICE<<" jump to "<selectSlide(newSlide, newLayer); } else { SlideEventHandler::instance()->selectSlide(_slideNum,_layerNum); } } else { OSG_NOTICE<<"No jump required."<