GUIActionAdapter 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_GUIACTIONADAPTER
  14. #define OSGGA_GUIACTIONADAPTER 1
  15. #include <osgGA/Export>
  16. #include <osg/View>
  17. #include <osgUtil/LineSegmentIntersector>
  18. namespace osgGA{
  19. /**
  20. Abstract base class defining the interface by which GUIEventHandlers may request
  21. actions of the GUI system in use. These requests for actions should then be honored
  22. by the GUI toolkit of the user's application.
  23. To provide more detail, when a GUIEventHandler (e.g. a TrackballManipulator)
  24. handles an incoming event, such as a mouse event, it may wish to make
  25. a request of the GUI. E.g. if a model is 'thrown', the trackball manipulator
  26. may wish to start a timer, and be repeatedly called, to continuously refresh the
  27. camera's position and orientation. However, it has no way of doing this, as it
  28. knows nothing of the window system in which it's operating. Instead, the
  29. GUIEventHandler issues it's request via a GUIActionAdapter, and the viewer
  30. in use should honour the request, using the GUI system in play.
  31. There is more than one way of using the GUIActionAdapter. E.g. it may be inherited
  32. into a Viewer class, as is done with osgGLUT::Viewer. Alternatively, a simple
  33. subclass of GUIActionAdapter (e.g. osgQt::QtActionAdapter) may be passed to
  34. the GUIEventHandler::handle() function; once the function has returned, the viewer
  35. will then unpack the results and work out what to do to respond to the
  36. requests.
  37. Also there are several ways to run your app and handle the updating of
  38. the window. osgGLUT::Viewer always has a idle callback registered which does a
  39. redraw all the time. osgGLUT::Viewer can safely ignore both requestRedraw() and
  40. requestContinousUpdate() as these are happening all the time anyway.
  41. Other apps will probably want to respond to the requestRedraw() and
  42. requestContinousUpdate(bool) and again there is more than one way to handle it.
  43. You can override requestRedraw() and implement to call your own window
  44. redraw straight away. Or you can implement so that a flag is set and
  45. then you then respond the flag being set in your own leisure.
  46. */
  47. class GUIEventAdapter;
  48. class GUIActionAdapter
  49. {
  50. public:
  51. virtual ~GUIActionAdapter() {}
  52. /** Provide a mechanism for getting the osg::View associated with this GUIActionAdapter.
  53. * One would use this to case view to osgViewer::View(er) if supported by the subclass.*/
  54. virtual osg::View* asView() { return 0; }
  55. /**
  56. requestRedraw() requests a single redraw.
  57. */
  58. virtual void requestRedraw() = 0;
  59. /**
  60. requestContinuousUpdate(bool) is for en/disabling a throw or idle
  61. callback to be requested by a GUIEventHandler (typically a CameraManipulator,
  62. though other GUIEventHandler's may also provide functionality).
  63. GUI toolkits can respond to this immediately by registering an idle/timed
  64. callback, or can delay setting the callback and update at their own leisure.
  65. */
  66. virtual void requestContinuousUpdate(bool needed=true) = 0;
  67. /**
  68. requestWarpPointer(int,int) is requesting a repositioning of the mouse pointer
  69. to a specified x,y location on the window. This is used by some camera manipulators
  70. to initialise the mouse pointer when mouse position relative to a controls
  71. neutral mouse position is required, i.e when mimicking an aircraft joystick.
  72. */
  73. virtual void requestWarpPointer(float x,float y) = 0;
  74. /** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
  75. virtual bool computeIntersections(const osgGA::GUIEventAdapter& /*ea*/, osgUtil::LineSegmentIntersector::Intersections& /*intersections*/,osg::Node::NodeMask /*traversalMask*/ = 0xffffffff) { return false; }
  76. /** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */
  77. virtual bool computeIntersections(const osgGA::GUIEventAdapter& /*ea*/, const osg::NodePath& /*nodePath*/, osgUtil::LineSegmentIntersector::Intersections& /*intersections*/,osg::Node::NodeMask /*traversalMask*/ = 0xffffffff) { return false; }
  78. };
  79. }
  80. #endif