1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
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.
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.
14// Code by: Jeremy Moles (cubicool) 2007-2008
16#ifndef OSGWIDGET_VIEWER_EVENT_HANDLERS
17#define OSGWIDGET_VIEWER_EVENT_HANDLERS
19#include <osgGA/GUIEventAdapter>
20#include <osgGA/GUIEventHandler>
21#include <osgWidget/WindowManager>
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.
29// This handles the pressing/moving of mouse buttons, etc.
30class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
34 MouseHandler(WindowManager*);
37 const osgGA::GUIEventAdapter&,
38 osgGA::GUIActionAdapter&,
44 typedef bool (MouseHandler::*MouseAction)(float, float, int);
45 typedef bool (WindowManager::*MouseEvent)(float, float);
49 osg::observer_ptr<WindowManager> _wm;
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);
58 MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const;
59 bool _doMouseEvent (float, float, MouseEvent);
62// This handles the forwarding of keypress events.
63class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler
67 KeyboardHandler(WindowManager*);
70 const osgGA::GUIEventAdapter&,
71 osgGA::GUIActionAdapter&,
77 osg::observer_ptr<WindowManager> _wm;
81// This class offers a default kind of handling for resizing.
82class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler
86 ResizeHandler(WindowManager*, osg::Camera* = 0);
89 const osgGA::GUIEventAdapter&,
90 osgGA::GUIActionAdapter&,
97 osg::observer_ptr<WindowManager> _wm;
98 osg::observer_ptr<osg::Camera> _camera;
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
107 CameraSwitchHandler(WindowManager*, osg::Camera*);
110 const osgGA::GUIEventAdapter&,
111 osgGA::GUIActionAdapter&,
118 osg::observer_ptr<WindowManager> _wm;
119 osg::observer_ptr<osg::Camera> _camera;
120 osg::ref_ptr<osg::Node> _oldNode;