1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
15#ifndef OSGMANIPULATOR_SCALE2DDRAGGER
16#define OSGMANIPULATOR_SCALE2DDRAGGER 1
18#include <osgManipulator/Dragger>
19#include <osgManipulator/Projector>
21namespace osgManipulator {
24 * Dragger for performing 2D scaling.
26class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger
32 SCALE_WITH_ORIGIN_AS_PIVOT = 0,
33 SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT
36 Scale2DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT);
38 META_OSGMANIPULATOR_Object(osgManipulator,Scale2DDragger)
41 * Handle pick events on dragger and generate TranslateInLine commands.
43 virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
45 /** Setup default geometry for dragger. */
46 void setupDefaultGeometry();
48 /** Set/Get min scale for dragger. */
49 inline void setMinScale(const osg::Vec2d& min) { _minScale = min; }
50 inline const osg::Vec2d& getMinScale() const { return _minScale; }
52 /** Set/Get color for dragger. */
53 inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
54 inline const osg::Vec4& getColor() const { return _color; }
57 * Set/Get pick color for dragger. Pick color is color of the dragger
58 * when picked. It gives a visual feedback to show that the dragger has
61 inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
62 inline const osg::Vec4& getPickColor() const { return _pickColor; }
64 /** Set/Get the handle nodes for dragger. */
65 inline void setTopLeftHandleNode (osg::Node& node) { _topLeftHandleNode = &node; }
66 inline osg::Node* getTopLeftHandleNode() { return _topLeftHandleNode.get(); }
67 inline const osg::Node* getTopLeftHandleNode() const { return _topLeftHandleNode.get(); }
68 inline void setBottomLeftHandleNode (osg::Node& node) { _bottomLeftHandleNode = &node; }
69 inline osg::Node* getBottomLeftHandleNode() { return _bottomLeftHandleNode.get(); }
70 inline const osg::Node* getBottomLeftHandleNode() const { return _bottomLeftHandleNode.get(); }
71 inline void setTopRightHandleNode(osg::Node& node) { _topRightHandleNode = &node; }
72 inline osg::Node* getTopRightHandleNode() { return _topRightHandleNode.get(); }
73 inline const osg::Node* getTopRightHandleNode() const { return _topRightHandleNode.get(); }
74 inline void setBottomRightHandleNode(osg::Node& node) { _bottomRightHandleNode = &node; }
75 inline osg::Node* getBottomRightHandleNode() { return _bottomRightHandleNode.get(); }
76 inline const osg::Node* getBottomRightHandleNode() const { return _bottomRightHandleNode.get(); }
78 /** Set/Get the handle nodes position for dragger. */
79 inline void setTopLeftHandlePosition(const osg::Vec2d& pos) { _topLeftHandlePosition = pos; }
80 const osg::Vec2d& getTopLeftHandlePosition() const { return _topLeftHandlePosition; }
81 inline void setBottomLeftHandlePosition(const osg::Vec2d& pos) { _bottomLeftHandlePosition = pos; }
82 const osg::Vec2d& getBottomLeftHandlePosition() const { return _bottomLeftHandlePosition; }
83 inline void setTopRightHandlePosition(const osg::Vec2d& pos) { _topRightHandlePosition = pos; }
84 const osg::Vec2d& getTopRightHandlePosition() const { return _topRightHandlePosition; }
85 inline void setBottomRightHandlePosition(const osg::Vec2d& pos){ _bottomRightHandlePosition = pos; }
86 const osg::Vec2d& getBottomRightHandlePosition() const { return _bottomRightHandlePosition; }
90 virtual ~Scale2DDragger();
92 osg::ref_ptr< PlaneProjector > _projector;
93 osg::Vec3d _startProjectedPoint;
94 osg::Vec2d _scaleCenter;
95 osg::Vec2d _referencePoint;
98 osg::ref_ptr< osg::Node > _topLeftHandleNode;
99 osg::ref_ptr< osg::Node > _bottomLeftHandleNode;
100 osg::ref_ptr< osg::Node > _topRightHandleNode;
101 osg::ref_ptr< osg::Node > _bottomRightHandleNode;
103 osg::Vec2d _topLeftHandlePosition;
104 osg::Vec2d _bottomLeftHandlePosition;
105 osg::Vec2d _topRightHandlePosition;
106 osg::Vec2d _bottomRightHandlePosition;
109 osg::Vec4 _pickColor;
111 ScaleMode _scaleMode;