Callbacks 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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 OSGUI_CALLBACKS
  14. #define OSGUI_CALLBACKS
  15. #include <osg/Callback>
  16. #include <osgGA/EventVisitor>
  17. #include <osgUI/Export>
  18. #include <osgUI/Widget>
  19. namespace osgUI
  20. {
  21. class OSGUI_EXPORT CloseCallback : public osg::CallbackObject
  22. {
  23. public:
  24. CloseCallback(const std::string& callbackName=std::string("close"), osgUI::Widget* closeWidget=0);
  25. CloseCallback(const CloseCallback& hc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  26. META_Object(osgUI, CloseCallback);
  27. void setCloseWidget(osgUI::Widget* widget) { _closeWidget = widget; }
  28. osgUI::Widget* getCloseWidget() { return _closeWidget.get(); }
  29. const osgUI::Widget* getCloseWidget() const { return _closeWidget.get(); }
  30. virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
  31. protected:
  32. virtual ~CloseCallback() {}
  33. osg::observer_ptr<osgUI::Widget> _closeWidget;
  34. };
  35. class OSGUI_EXPORT HandleCallback : public osg::CallbackObject
  36. {
  37. public:
  38. HandleCallback();
  39. HandleCallback(const HandleCallback& hc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  40. META_Object(osgUI, HandleCallback);
  41. virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
  42. virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event) const;
  43. protected:
  44. virtual ~HandleCallback() {}
  45. };
  46. class OSGUI_EXPORT DragCallback : public HandleCallback
  47. {
  48. public:
  49. DragCallback();
  50. DragCallback(const DragCallback& dc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  51. META_Object(osgUI, DragCallback);
  52. void setDragging(bool v) { _dragging = v; }
  53. bool getDragging() const { return _dragging; }
  54. void setPreviousPosition(const osg::Vec3d& position) { _previousPosition = position; }
  55. const osg::Vec3d& getPreviousPosition() const { return _previousPosition; }
  56. virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event) const;
  57. protected:
  58. virtual ~DragCallback() {}
  59. bool _dragging;
  60. osg::Vec3d _previousPosition;
  61. };
  62. }
  63. #endif