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.
This commit is contained in:
Robert Osfield
2009-07-03 19:16:53 +00:00
parent cb1b874167
commit 6e6a7c960e
8 changed files with 287 additions and 164 deletions

View File

@@ -125,7 +125,11 @@ bool PointerInfo::projectWindowXYIntoObject(const osg::Vec2d& windowCoord, osg::
//
Dragger::Dragger() :
_handleEvents(false),
_draggerActive(false)
_draggerActive(false),
_activationModKeyMask(0),
_activationKeyEvent(0),
_activationPermittedByModKeyMask(false),
_activationPermittedByKeyEvent(false)
{
_parentDragger = this;
getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
@@ -135,7 +139,13 @@ Dragger::Dragger() :
}
Dragger::Dragger(const Dragger& rhs, const osg::CopyOp& copyop):
osg::MatrixTransform(rhs, copyop)
osg::MatrixTransform(rhs, copyop),
_handleEvents(rhs._handleEvents),
_draggerActive(false),
_activationModKeyMask(rhs._activationModKeyMask),
_activationKeyEvent(rhs._activationKeyEvent),
_activationPermittedByModKeyMask(false),
_activationPermittedByKeyEvent(false)
{
osg::notify(osg::NOTICE)<<"CompositeDragger::CompositeDragger(const CompositeDragger& rhs, const osg::CopyOp& copyop) not Implemented yet."<<std::endl;
}
@@ -250,65 +260,98 @@ bool Dragger::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&
bool handled = false;
switch (ea.getEventType())
bool activationPermitted = true;
if (_activationModKeyMask!=0 || _activationKeyEvent!=0)
{
case osgGA::GUIEventAdapter::PUSH:
_activationPermittedByModKeyMask = (_activationModKeyMask!=0) ?
((ea.getModKeyMask() & _activationModKeyMask)!=0) :
false;
if (_activationKeyEvent!=0)
{
osgUtil::LineSegmentIntersector::Intersections intersections;
_pointer.reset();
if (view->computeIntersections(ea.getX(),ea.getY(),intersections))
switch (ea.getEventType())
{
_pointer.setCamera(view->getCamera());
_pointer.setMousePosition(ea.getX(), ea.getY());
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
case osgGA::GUIEventAdapter::KEYDOWN:
{
_pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = true;
break;
}
for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin();
itr != _pointer._hitList.front().first.end();
++itr)
case osgGA::GUIEventAdapter::KEYUP:
{
osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
if (dragger)
if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = false;
break;
}
default:
break;
}
}
activationPermitted = _activationPermittedByModKeyMask || _activationPermittedByKeyEvent;
}
if (activationPermitted || _draggerActive)
{
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::PUSH:
{
osgUtil::LineSegmentIntersector::Intersections intersections;
_pointer.reset();
if (view->computeIntersections(ea.getX(),ea.getY(),intersections))
{
_pointer.setCamera(view->getCamera());
_pointer.setMousePosition(ea.getX(), ea.getY());
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
if (dragger==this)
_pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
}
for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin();
itr != _pointer._hitList.front().first.end();
++itr)
{
osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
if (dragger)
{
dragger->handle(_pointer, ea, aa);
dragger->setDraggerActive(true);
handled = true;
if (dragger==this)
{
dragger->handle(_pointer, ea, aa);
dragger->setDraggerActive(true);
handled = true;
}
}
}
}
}
}
case osgGA::GUIEventAdapter::DRAG:
case osgGA::GUIEventAdapter::RELEASE:
{
if (_draggerActive)
case osgGA::GUIEventAdapter::DRAG:
case osgGA::GUIEventAdapter::RELEASE:
{
_pointer._hitIter = _pointer._hitList.begin();
_pointer.setCamera(view->getCamera());
_pointer.setMousePosition(ea.getX(), ea.getY());
if (_draggerActive)
{
_pointer._hitIter = _pointer._hitList.begin();
_pointer.setCamera(view->getCamera());
_pointer.setMousePosition(ea.getX(), ea.getY());
handle(_pointer, ea, aa);
handle(_pointer, ea, aa);
handled = true;
handled = true;
}
break;
}
break;
default:
break;
}
default:
break;
}
if (_draggerActive && ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
{
setDraggerActive(false);
_pointer.reset();
if (_draggerActive && ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
{
setDraggerActive(false);
_pointer.reset();
}
}
return handled;

View File

@@ -45,7 +45,6 @@ SET(TARGET_H
IF(CMAKE_COMPILER_IS_GNUCXX)
# Remove -pedantic flag as it barfs on ffmoeg headers
STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDIF()

View File

@@ -459,7 +459,7 @@ void RayTracedTechnique::init()
osg::ref_ptr<TexGenLocatorCallback> locatorCallback = new TexGenLocatorCallback(texgen, masterLocator, layerLocator);
masterLocator->addCallback(locatorCallback.get());
layerLocator->addCallback(locatorCallback.get());
if (masterLocator != layerLocator) layerLocator->addCallback(locatorCallback.get());
stateset->setTextureAttributeAndModes(0, texgen, osg::StateAttribute::ON);

View File

@@ -215,14 +215,24 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Dragger)
__bool__getHandleEvents,
"",
"");
I_Method1(void, setDraggerActive, IN, bool, active,
I_Method1(void, setActivationModKeyMask, IN, unsigned int, mask,
Properties::NON_VIRTUAL,
__void__setDraggerActive__bool,
__void__setActivationModKeyMask__unsigned_int,
"",
"");
I_Method0(bool, getDraggerActive,
I_Method0(unsigned int, getActivationModKeyMask,
Properties::NON_VIRTUAL,
__bool__getDraggerActive,
__unsigned_int__getActivationModKeyMask,
"",
"");
I_Method1(void, setActivationKeyEvent, IN, int, key,
Properties::NON_VIRTUAL,
__void__setActivationKeyEvent__int,
"",
"");
I_Method0(int, getActivationKeyEvent,
Properties::NON_VIRTUAL,
__int__getActivationKeyEvent,
"",
"");
I_Method1(void, traverse, IN, osg::NodeVisitor &, x,
@@ -314,15 +324,30 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Dragger)
__void__dispatch__MotionCommand_R1,
"",
"");
I_ProtectedMethod1(void, setDraggerActive, IN, bool, active,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
__void__setDraggerActive__bool,
"",
"");
I_ProtectedMethod0(bool, getDraggerActive,
Properties::NON_VIRTUAL,
Properties::CONST,
__bool__getDraggerActive,
"",
"");
I_SimpleProperty(int, ActivationKeyEvent,
__int__getActivationKeyEvent,
__void__setActivationKeyEvent__int);
I_SimpleProperty(unsigned int, ActivationModKeyMask,
__unsigned_int__getActivationModKeyMask,
__void__setActivationModKeyMask__unsigned_int);
I_SimpleProperty(osgManipulator::CompositeDragger *, Composite,
__CompositeDragger_P1__getComposite,
0);
I_SimpleProperty(osgManipulator::Dragger::Constraints &, Constraints,
__Constraints_R1__getConstraints,
0);
I_SimpleProperty(bool, DraggerActive,
__bool__getDraggerActive,
__void__setDraggerActive__bool);
I_SimpleProperty(osgManipulator::Dragger::DraggerCallbacks &, DraggerCallbacks,
__DraggerCallbacks_R1__getDraggerCallbacks,
0);