Scale2DDragger 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef OSGMANIPULATOR_SCALE2DDRAGGER
  15. #define OSGMANIPULATOR_SCALE2DDRAGGER 1
  16. #include <osgManipulator/Dragger>
  17. #include <osgManipulator/Projector>
  18. namespace osgManipulator {
  19. /**
  20. * Dragger for performing 2D scaling.
  21. */
  22. class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger
  23. {
  24. public:
  25. enum ScaleMode
  26. {
  27. SCALE_WITH_ORIGIN_AS_PIVOT = 0,
  28. SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT
  29. };
  30. Scale2DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT);
  31. META_OSGMANIPULATOR_Object(osgManipulator,Scale2DDragger)
  32. /**
  33. * Handle pick events on dragger and generate TranslateInLine commands.
  34. */
  35. virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
  36. /** Setup default geometry for dragger. */
  37. void setupDefaultGeometry();
  38. /** Set/Get min scale for dragger. */
  39. inline void setMinScale(const osg::Vec2d& min) { _minScale = min; }
  40. inline const osg::Vec2d& getMinScale() const { return _minScale; }
  41. /** Set/Get color for dragger. */
  42. inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
  43. inline const osg::Vec4& getColor() const { return _color; }
  44. /**
  45. * Set/Get pick color for dragger. Pick color is color of the dragger
  46. * when picked. It gives a visual feedback to show that the dragger has
  47. * been picked.
  48. */
  49. inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
  50. inline const osg::Vec4& getPickColor() const { return _pickColor; }
  51. /** Set/Get the handle nodes for dragger. */
  52. inline void setTopLeftHandleNode (osg::Node& node) { _topLeftHandleNode = &node; }
  53. inline osg::Node* getTopLeftHandleNode() { return _topLeftHandleNode.get(); }
  54. inline const osg::Node* getTopLeftHandleNode() const { return _topLeftHandleNode.get(); }
  55. inline void setBottomLeftHandleNode (osg::Node& node) { _bottomLeftHandleNode = &node; }
  56. inline osg::Node* getBottomLeftHandleNode() { return _bottomLeftHandleNode.get(); }
  57. inline const osg::Node* getBottomLeftHandleNode() const { return _bottomLeftHandleNode.get(); }
  58. inline void setTopRightHandleNode(osg::Node& node) { _topRightHandleNode = &node; }
  59. inline osg::Node* getTopRightHandleNode() { return _topRightHandleNode.get(); }
  60. inline const osg::Node* getTopRightHandleNode() const { return _topRightHandleNode.get(); }
  61. inline void setBottomRightHandleNode(osg::Node& node) { _bottomRightHandleNode = &node; }
  62. inline osg::Node* getBottomRightHandleNode() { return _bottomRightHandleNode.get(); }
  63. inline const osg::Node* getBottomRightHandleNode() const { return _bottomRightHandleNode.get(); }
  64. /** Set/Get the handle nodes position for dragger. */
  65. inline void setTopLeftHandlePosition(const osg::Vec2d& pos) { _topLeftHandlePosition = pos; }
  66. const osg::Vec2d& getTopLeftHandlePosition() const { return _topLeftHandlePosition; }
  67. inline void setBottomLeftHandlePosition(const osg::Vec2d& pos) { _bottomLeftHandlePosition = pos; }
  68. const osg::Vec2d& getBottomLeftHandlePosition() const { return _bottomLeftHandlePosition; }
  69. inline void setTopRightHandlePosition(const osg::Vec2d& pos) { _topRightHandlePosition = pos; }
  70. const osg::Vec2d& getTopRightHandlePosition() const { return _topRightHandlePosition; }
  71. inline void setBottomRightHandlePosition(const osg::Vec2d& pos){ _bottomRightHandlePosition = pos; }
  72. const osg::Vec2d& getBottomRightHandlePosition() const { return _bottomRightHandlePosition; }
  73. protected:
  74. virtual ~Scale2DDragger();
  75. osg::ref_ptr< PlaneProjector > _projector;
  76. osg::Vec3d _startProjectedPoint;
  77. osg::Vec2d _scaleCenter;
  78. osg::Vec2d _referencePoint;
  79. osg::Vec2d _minScale;
  80. osg::ref_ptr< osg::Node > _topLeftHandleNode;
  81. osg::ref_ptr< osg::Node > _bottomLeftHandleNode;
  82. osg::ref_ptr< osg::Node > _topRightHandleNode;
  83. osg::ref_ptr< osg::Node > _bottomRightHandleNode;
  84. osg::Vec2d _topLeftHandlePosition;
  85. osg::Vec2d _bottomLeftHandlePosition;
  86. osg::Vec2d _topRightHandlePosition;
  87. osg::Vec2d _bottomRightHandlePosition;
  88. osg::Vec4 _color;
  89. osg::Vec4 _pickColor;
  90. ScaleMode _scaleMode;
  91. };
  92. }
  93. #endif