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