openscenegraph
Scale2DDragger
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
14
15#ifndef OSGMANIPULATOR_SCALE2DDRAGGER
16#define OSGMANIPULATOR_SCALE2DDRAGGER 1
17
18#include <osgManipulator/Dragger>
19#include <osgManipulator/Projector>
20
21namespace osgManipulator {
22
23/**
24 * Dragger for performing 2D scaling.
25 */
26class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger
27{
28 public:
29
30 enum ScaleMode
31 {
32 SCALE_WITH_ORIGIN_AS_PIVOT = 0,
33 SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT
34 };
35
36 Scale2DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT);
37
38 META_OSGMANIPULATOR_Object(osgManipulator,Scale2DDragger)
39
40 /**
41 * Handle pick events on dragger and generate TranslateInLine commands.
42 */
43 virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
44
45 /** Setup default geometry for dragger. */
46 void setupDefaultGeometry();
47
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; }
51
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; }
55
56 /**
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
59 * been picked.
60 */
61 inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
62 inline const osg::Vec4& getPickColor() const { return _pickColor; }
63
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(); }
77
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; }
87
88 protected:
89
90 virtual ~Scale2DDragger();
91
92 osg::ref_ptr< PlaneProjector > _projector;
93 osg::Vec3d _startProjectedPoint;
94 osg::Vec2d _scaleCenter;
95 osg::Vec2d _referencePoint;
96 osg::Vec2d _minScale;
97
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;
102
103 osg::Vec2d _topLeftHandlePosition;
104 osg::Vec2d _bottomLeftHandlePosition;
105 osg::Vec2d _topRightHandlePosition;
106 osg::Vec2d _bottomRightHandlePosition;
107
108 osg::Vec4 _color;
109 osg::Vec4 _pickColor;
110
111 ScaleMode _scaleMode;
112};
113
114
115}
116
117#endif