Added DraggerTransformCallback::HandleCommandMask to DraggerTransformCallback to allow applications to select which

commands they want the dragger callback to respond to why updating the transform.
This commit is contained in:
Robert Osfield 2012-02-01 13:55:38 +00:00
parent 7664d90504
commit 487ee0f8e7
2 changed files with 61 additions and 5 deletions

View File

@ -45,15 +45,34 @@ class OSGMANIPULATOR_EXPORT DraggerTransformCallback : public DraggerCallback
{ {
public: public:
DraggerTransformCallback(osg::MatrixTransform* transform); enum HandleCommandMask
{
HANDLE_TRANSLATE_IN_LINE = 1<<0,
HANDLE_TRANSLATE_IN_PLANE = 1<<1,
HANDLE_SCALED_1D = 1<<2,
HANDLE_SCALED_2D = 1<<3,
HANDLE_SCALED_UNIFORM = 1<<4,
HANDLE_ROTATE_3D = 1<<5,
HANDLE_ALL = 0x8ffffff
};
DraggerTransformCallback(osg::MatrixTransform* transform, int handleCommandMask = HANDLE_ALL);
virtual bool receive(const MotionCommand&); virtual bool receive(const MotionCommand&);
virtual bool receive(const TranslateInLineCommand& command);
virtual bool receive(const TranslateInPlaneCommand& command);
virtual bool receive(const Scale1DCommand& command);
virtual bool receive(const Scale2DCommand& command);
virtual bool receive(const ScaleUniformCommand& command);
virtual bool receive(const Rotate3DCommand& command);
osg::MatrixTransform* getTransform() { return _transform.get(); } osg::MatrixTransform* getTransform() { return _transform.get(); }
const osg::MatrixTransform* getTransform() const { return _transform.get(); } const osg::MatrixTransform* getTransform() const { return _transform.get(); }
protected: protected:
unsigned int _handleCommandMask;
osg::observer_ptr<osg::MatrixTransform> _transform; osg::observer_ptr<osg::MatrixTransform> _transform;
osg::Matrix _startMotionMatrix; osg::Matrix _startMotionMatrix;
@ -228,7 +247,7 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform
DraggerCallbacks& getDraggerCallbacks() { return _draggerCallbacks; } DraggerCallbacks& getDraggerCallbacks() { return _draggerCallbacks; }
const DraggerCallbacks& getDraggerCallbacks() const { return _draggerCallbacks; } const DraggerCallbacks& getDraggerCallbacks() const { return _draggerCallbacks; }
void addTransformUpdating(MatrixTransform* transform); void addTransformUpdating(MatrixTransform* transform, int handleCommandMask = DraggerTransformCallback::HANDLE_ALL);
void removeTransformUpdating(MatrixTransform* transform); void removeTransformUpdating(MatrixTransform* transform);
/** Setup default geometry for dragger. */ /** Setup default geometry for dragger. */

View File

@ -45,7 +45,8 @@ void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
// //
// DraggerTransformCallback // DraggerTransformCallback
// //
DraggerTransformCallback::DraggerTransformCallback(osg::MatrixTransform* transform): DraggerTransformCallback::DraggerTransformCallback(osg::MatrixTransform* transform,int handleCommandMask):
_handleCommandMask(handleCommandMask),
_transform(transform) _transform(transform)
{ {
} }
@ -93,6 +94,42 @@ bool DraggerTransformCallback::receive(const MotionCommand& command)
} }
} }
bool DraggerTransformCallback::receive(const TranslateInLineCommand& command)
{
if ((_handleCommandMask&HANDLE_TRANSLATE_IN_LINE)!=0) return receive(static_cast<const MotionCommand&>(command));
return false;
}
bool DraggerTransformCallback::receive(const TranslateInPlaneCommand& command)
{
if ((_handleCommandMask&HANDLE_TRANSLATE_IN_PLANE)!=0) return receive(static_cast<const MotionCommand&>(command));
return false;
}
bool DraggerTransformCallback::receive(const Scale1DCommand& command)
{
if ((_handleCommandMask&HANDLE_SCALED_1D)!=0) return receive(static_cast<const MotionCommand&>(command));
return false;
}
bool DraggerTransformCallback::receive(const Scale2DCommand& command)
{
if ((_handleCommandMask&HANDLE_SCALED_2D)!=0) return receive(static_cast<const MotionCommand&>(command));
return false;
}
bool DraggerTransformCallback::receive(const ScaleUniformCommand& command)
{
if ((_handleCommandMask&HANDLE_SCALED_UNIFORM)!=0) return receive(static_cast<const MotionCommand&>(command));
return false;
}
bool DraggerTransformCallback::receive(const Rotate3DCommand& command)
{
if ((_handleCommandMask&HANDLE_ROTATE_3D)!=0) return receive(static_cast<const MotionCommand&>(command));
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
@ -199,9 +236,9 @@ void Dragger::removeConstraint(Constraint* constraint)
} }
} }
void Dragger::addTransformUpdating(osg::MatrixTransform* transform) void Dragger::addTransformUpdating(osg::MatrixTransform* transform, int handleCommandMask)
{ {
addDraggerCallback(new DraggerTransformCallback(transform)); addDraggerCallback(new DraggerTransformCallback(transform, handleCommandMask));
} }
void Dragger::removeTransformUpdating(osg::MatrixTransform* transform) void Dragger::removeTransformUpdating(osg::MatrixTransform* transform)