Widget 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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. #ifndef OSGGA_WIDGET
  14. #define OSGGA_WIDGET
  15. #include <osg/Group>
  16. #include <osg/BoundingBox>
  17. #include <osgGA/Event>
  18. #include <osgGA/EventVisitor>
  19. namespace osgGA
  20. {
  21. class OSGGA_EXPORT Widget : public osg::Group
  22. {
  23. public:
  24. Widget();
  25. Widget(const Widget& tfw, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  26. META_Node(osgGA, Widget);
  27. virtual void traverse(osg::NodeVisitor& nv);
  28. virtual void traverseImplementation(osg::NodeVisitor& nv);
  29. virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
  30. virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
  31. virtual bool computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const;
  32. virtual void createGraphics();
  33. virtual void createGraphicsImplementation();
  34. virtual void setExtents(const osg::BoundingBoxf& bb);
  35. const osg::BoundingBoxf& getExtents() const { return _extents; }
  36. enum FocusBehaviour
  37. {
  38. CLICK_TO_FOCUS,
  39. FOCUS_FOLLOWS_POINTER,
  40. EVENT_DRIVEN_FOCUS_DISABLED
  41. };
  42. void setFocusBehaviour(FocusBehaviour behaviour) { _focusBehaviour = behaviour; }
  43. FocusBehaviour getFocusBehaviour() const { return _focusBehaviour; }
  44. /** update the focus according to events.*/
  45. virtual void updateFocus(osg::NodeVisitor& nv);
  46. /** set whether the widget has focus or not.*/
  47. virtual void setHasEventFocus(bool focus);
  48. /** get whether the widget has focus or not.*/
  49. virtual bool getHasEventFocus() const;
  50. virtual osg::BoundingSphere computeBound() const;
  51. /** update any focus related graphics+state to the focused state.*/
  52. virtual void enter();
  53. virtual void enterImplementation();
  54. /** update any focus related graphics+state to the unfocused state.*/
  55. virtual void leave();
  56. virtual void leaveImplementation();
  57. protected:
  58. virtual ~Widget() {}
  59. FocusBehaviour _focusBehaviour;
  60. bool _hasEventFocus;
  61. bool _graphicsInitialized;
  62. osg::BoundingBoxf _extents;
  63. };
  64. }
  65. #endif