GUIEventHandler 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef OSGGA_GUIEVENTHANDLER
  14. #define OSGGA_GUIEVENTHANDLER 1
  15. #include <vector>
  16. #include <osg/Drawable>
  17. #include <osg/ApplicationUsage>
  18. #include <osgGA/EventHandler>
  19. #include <osgGA/GUIEventAdapter>
  20. #include <osgGA/GUIActionAdapter>
  21. // #define COMPILE_COMPOSITE_EVENTHANDLER
  22. namespace osgGA{
  23. /**
  24. GUIEventHandler provides a basic interface for any class which wants to handle
  25. a GUI Events.
  26. The GUIEvent is supplied by a GUIEventAdapter. Feedback resulting from the
  27. handle method is supplied by a GUIActionAdapter, which allows the GUIEventHandler
  28. to ask the GUI to take some action in response to an incoming event.
  29. For example, consider a Trackball Viewer class which takes mouse events and
  30. manipulates a scene camera in response. The Trackball Viewer is a GUIEventHandler,
  31. and receives the events via the handle method. If the user 'throws' the model,
  32. the Trackball Viewer class can detect this via the incoming events, and
  33. request that the GUI set up a timer callback to continually redraw the view.
  34. This request is made via the GUIActionAdapter class.
  35. */
  36. class OSGGA_EXPORT GUIEventHandler : public EventHandler
  37. {
  38. public:
  39. GUIEventHandler() {}
  40. GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
  41. osg::Object(eh, copyop),
  42. osg::Callback(eh, copyop),
  43. EventHandler(eh, copyop) {}
  44. META_Object(osgGA,GUIEventHandler);
  45. /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
  46. virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
  47. /** Handle events, return true if handled, false otherwise. */
  48. virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); }
  49. /** Deprecated, Handle events, return true if handled, false otherwise. */
  50. virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; }
  51. protected:
  52. virtual ~GUIEventHandler();
  53. };
  54. }
  55. #endif