Show
Ignore:
Timestamp:
07/03/09 21:16:53 (3 years ago)
Author:
robert
Message:

Added Dragger::s/getActivationModKeyMask(..) and Dragger::s/getActivationKeyEvent(...) methods to make it possible to have draggers that only respond when you press a specified modified key or standard key.

Changed the optional dragger in osgvolume to require the shift key to be pressed for the dragger to become active.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgManipulator/Dragger.cpp

    r10443 r10454  
    126126Dragger::Dragger() : 
    127127    _handleEvents(false), 
    128     _draggerActive(false) 
     128    _draggerActive(false), 
     129    _activationModKeyMask(0), 
     130    _activationKeyEvent(0), 
     131    _activationPermittedByModKeyMask(false), 
     132    _activationPermittedByKeyEvent(false) 
    129133{ 
    130134    _parentDragger = this; 
     
    136140 
    137141Dragger::Dragger(const Dragger& rhs, const osg::CopyOp& copyop): 
    138     osg::MatrixTransform(rhs, copyop) 
     142    osg::MatrixTransform(rhs, copyop), 
     143    _handleEvents(rhs._handleEvents), 
     144    _draggerActive(false), 
     145    _activationModKeyMask(rhs._activationModKeyMask), 
     146    _activationKeyEvent(rhs._activationKeyEvent), 
     147    _activationPermittedByModKeyMask(false), 
     148    _activationPermittedByKeyEvent(false) 
    139149{ 
    140150    osg::notify(osg::NOTICE)<<"CompositeDragger::CompositeDragger(const CompositeDragger& rhs, const osg::CopyOp& copyop) not Implemented yet."<<std::endl; 
     
    251261    bool handled = false; 
    252262 
    253     switch (ea.getEventType()) 
    254     { 
    255         case osgGA::GUIEventAdapter::PUSH: 
    256         { 
    257             osgUtil::LineSegmentIntersector::Intersections intersections; 
    258  
    259             _pointer.reset(); 
    260  
    261             if (view->computeIntersections(ea.getX(),ea.getY(),intersections)) 
     263    bool activationPermitted = true; 
     264    if (_activationModKeyMask!=0 || _activationKeyEvent!=0) 
     265    { 
     266        _activationPermittedByModKeyMask = (_activationModKeyMask!=0) ? 
     267            ((ea.getModKeyMask() & _activationModKeyMask)!=0) : 
     268            false; 
     269 
     270        if (_activationKeyEvent!=0) 
     271        { 
     272            switch (ea.getEventType()) 
    262273            { 
    263                 _pointer.setCamera(view->getCamera()); 
    264                 _pointer.setMousePosition(ea.getX(), ea.getY()); 
    265  
    266                 for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); 
    267                     hitr != intersections.end(); 
    268                     ++hitr) 
     274                case osgGA::GUIEventAdapter::KEYDOWN: 
    269275                { 
    270                     _pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint()); 
     276                    if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = true; 
     277                    break; 
    271278                } 
    272                 for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin(); 
    273                         itr != _pointer._hitList.front().first.end(); 
    274                         ++itr) 
     279                case osgGA::GUIEventAdapter::KEYUP: 
    275280                { 
    276                     osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr); 
    277                     if (dragger) 
     281                    if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = false; 
     282                    break; 
     283                } 
     284                default: 
     285                    break; 
     286            } 
     287        } 
     288 
     289        activationPermitted =  _activationPermittedByModKeyMask || _activationPermittedByKeyEvent; 
     290 
     291    } 
     292 
     293    if (activationPermitted || _draggerActive) 
     294    { 
     295        switch (ea.getEventType()) 
     296        { 
     297            case osgGA::GUIEventAdapter::PUSH: 
     298            { 
     299                osgUtil::LineSegmentIntersector::Intersections intersections; 
     300 
     301                _pointer.reset(); 
     302 
     303                if (view->computeIntersections(ea.getX(),ea.getY(),intersections)) 
     304                { 
     305                    _pointer.setCamera(view->getCamera()); 
     306                    _pointer.setMousePosition(ea.getX(), ea.getY()); 
     307 
     308                    for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); 
     309                        hitr != intersections.end(); 
     310                        ++hitr) 
    278311                    { 
    279                         if (dragger==this) 
     312                        _pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint()); 
     313                    } 
     314                    for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin(); 
     315                            itr != _pointer._hitList.front().first.end(); 
     316                            ++itr) 
     317                    { 
     318                        osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr); 
     319                        if (dragger) 
    280320                        { 
    281                             dragger->handle(_pointer, ea, aa); 
    282                             dragger->setDraggerActive(true); 
    283                             handled = true; 
     321                            if (dragger==this) 
     322                            { 
     323                                dragger->handle(_pointer, ea, aa); 
     324                                dragger->setDraggerActive(true); 
     325                                handled = true; 
     326                            } 
    284327                        } 
    285328                    } 
    286329                } 
    287330            } 
    288         } 
    289         case osgGA::GUIEventAdapter::DRAG: 
    290         case osgGA::GUIEventAdapter::RELEASE: 
    291         { 
    292             if (_draggerActive) 
     331            case osgGA::GUIEventAdapter::DRAG: 
     332            case osgGA::GUIEventAdapter::RELEASE: 
    293333            { 
    294                 _pointer._hitIter = _pointer._hitList.begin(); 
    295                 _pointer.setCamera(view->getCamera()); 
    296                 _pointer.setMousePosition(ea.getX(), ea.getY()); 
    297  
    298                 handle(_pointer, ea, aa);                 
    299  
    300                 handled = true; 
     334                if (_draggerActive) 
     335                { 
     336                    _pointer._hitIter = _pointer._hitList.begin(); 
     337                    _pointer.setCamera(view->getCamera()); 
     338                    _pointer.setMousePosition(ea.getX(), ea.getY()); 
     339 
     340                    handle(_pointer, ea, aa); 
     341 
     342                    handled = true; 
     343                } 
     344                break; 
    301345            } 
    302             break; 
    303         } 
    304         default: 
    305             break; 
    306     } 
    307  
    308     if (_draggerActive && ea.getEventType() == osgGA::GUIEventAdapter::RELEASE) 
    309     { 
    310         setDraggerActive(false); 
    311         _pointer.reset(); 
     346            default: 
     347                break; 
     348        } 
     349 
     350        if (_draggerActive && ea.getEventType() == osgGA::GUIEventAdapter::RELEASE) 
     351        { 
     352            setDraggerActive(false); 
     353            _pointer.reset(); 
     354        } 
    312355    } 
    313356