openscenegraph
EventHandler
Go to the documentation of this file.
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
14#ifndef OSGGA_EVENTHANDLER
15#define OSGGA_EVENTHANDLER 1
16
17#include <vector>
18
19#include <osg/Drawable>
20#include <osg/ApplicationUsage>
21
22#include <osgGA/Export>
23#include <osgGA/GUIEventAdapter>
24#include <osgGA/GUIActionAdapter>
25
26
27namespace osgGA{
28
29/**
30EventHandler is base class for adding handling of events, either as node event callback, drawable event callback or an event handler attached directly to the view(er)
31*/
32
33class OSGGA_EXPORT EventHandler : public osg::NodeCallback, public osg::DrawableEventCallback
34{
35public:
36
37 EventHandler() {}
38 EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
39 osg::Object(eh, copyop),
40 osg::Callback(eh, copyop),
41 osg::NodeCallback(eh, copyop),
42 osg::DrawableEventCallback(eh, copyop) {}
43
44 META_Object(osgGA, EventHandler);
45
46 virtual NodeCallback* asNodeCallback() { return osg::NodeCallback::asNodeCallback(); }
47 virtual const NodeCallback* asNodeCallback() const { return osg::NodeCallback::asNodeCallback(); }
48
49 virtual DrawableEventCallback* asDrawableEventCallback() { return osg::DrawableEventCallback::asDrawableEventCallback(); }
50 virtual const DrawableEventCallback* asDrawableEventCallback() const { return osg::DrawableEventCallback::asDrawableEventCallback(); }
51
52 virtual EventHandler* asEventHandler() { return this; }
53 virtual const EventHandler* asEventHandler() const { return this; }
54
55 virtual bool run(osg::Object* object, osg::Object* data)
56 {
57 osg::Node* node = object->asNode();
58 osg::NodeVisitor* nv = data->asNodeVisitor();
59 operator()(node, nv);
60 return true;
61 }
62
63 /** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
64 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
65
66 /** Event traversal drawable callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
67 virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable);
68
69 /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
70 virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
71
72 /** Get the user interface usage of this event handler, i.e. keyboard and mouse bindings.*/
73 virtual void getUsage(osg::ApplicationUsage&) const {}
74
75protected:
76
77};
78
79}
80
81#endif