ViewerEventHandlers 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 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. // Code by: Jeremy Moles (cubicool) 2007-2008
  14. #ifndef OSGWIDGET_VIEWER_EVENT_HANDLERS
  15. #define OSGWIDGET_VIEWER_EVENT_HANDLERS
  16. #include <osgGA/GUIEventAdapter>
  17. #include <osgGA/GUIEventHandler>
  18. #include <osgWidget/WindowManager>
  19. // NOTE! These are all just examples of some default event handlers--they are not
  20. // required. You are more than welcome to provide your own even handlers that
  21. // communicate with a WindowManager using it's public API.
  22. namespace osgWidget {
  23. // This handles the pressing/moving of mouse buttons, etc.
  24. class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
  25. {
  26. public:
  27. MouseHandler(WindowManager*);
  28. virtual bool handle(
  29. const osgGA::GUIEventAdapter&,
  30. osgGA::GUIActionAdapter&,
  31. osg::Object*,
  32. osg::NodeVisitor*
  33. );
  34. typedef bool (MouseHandler::*MouseAction)(float, float, int);
  35. typedef bool (WindowManager::*MouseEvent)(float, float);
  36. protected:
  37. osg::observer_ptr<WindowManager> _wm;
  38. bool _handleMousePush (float, float, int);
  39. bool _handleMouseRelease (float, float, int);
  40. bool _handleMouseDoubleClick (float, float, int);
  41. bool _handleMouseDrag (float, float, int);
  42. bool _handleMouseMove (float, float, int);
  43. bool _handleMouseScroll (float, float, int);
  44. MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const;
  45. bool _doMouseEvent (float, float, MouseEvent);
  46. };
  47. // This handles the forwarding of keypress events.
  48. class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler
  49. {
  50. public:
  51. KeyboardHandler(WindowManager*);
  52. virtual bool handle(
  53. const osgGA::GUIEventAdapter&,
  54. osgGA::GUIActionAdapter&,
  55. osg::Object*,
  56. osg::NodeVisitor*
  57. );
  58. protected:
  59. osg::observer_ptr<WindowManager> _wm;
  60. };
  61. // This class offers a default kind of handling for resizing.
  62. class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler
  63. {
  64. public:
  65. ResizeHandler(WindowManager*, osg::Camera* = 0);
  66. virtual bool handle(
  67. const osgGA::GUIEventAdapter&,
  68. osgGA::GUIActionAdapter&,
  69. osg::Object*,
  70. osg::NodeVisitor*
  71. );
  72. protected:
  73. osg::observer_ptr<WindowManager> _wm;
  74. osg::observer_ptr<osg::Camera> _camera;
  75. };
  76. // This class provides a hotkey that lets you toggle back and forth between
  77. // a camera and setting the CameraManipulator's home point.
  78. class OSGWIDGET_EXPORT CameraSwitchHandler: public osgGA::GUIEventHandler
  79. {
  80. public:
  81. CameraSwitchHandler(WindowManager*, osg::Camera*);
  82. virtual bool handle(
  83. const osgGA::GUIEventAdapter&,
  84. osgGA::GUIActionAdapter&,
  85. osg::Object*,
  86. osg::NodeVisitor*
  87. );
  88. protected:
  89. osg::observer_ptr<WindowManager> _wm;
  90. osg::observer_ptr<osg::Camera> _camera;
  91. osg::ref_ptr<osg::Node> _oldNode;
  92. };
  93. }
  94. #endif