OpenSceneGraph 3.6.5
EventVisitor
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_EVENTVISITOR
15#define OSGGA_EVENTVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Node>
19#include <osg/Geode>
20#include <osg/Billboard>
21#include <osg/LOD>
22#include <osg/Switch>
23#include <osg/LightSource>
24#include <osg/Transform>
25#include <osg/Projection>
26#include <osg/OccluderNode>
27#include <osg/ScriptEngine>
28
29#include <osgGA/GUIEventAdapter>
30#include <osgGA/GUIEventHandler>
32#include <osgGA/EventQueue>
33
34namespace osgGA {
35
42{
43 public:
44
46 virtual ~EventVisitor();
47
53
56 virtual const osgGA::EventVisitor* asEventVisitor() const { return this; }
57
58 void setActionAdapter(osgGA::GUIActionAdapter* actionAdapter) { _actionAdapter=actionAdapter; }
59
61
63
64 void addEvent(Event* event);
65 void removeEvent(Event* event);
66
67 void setEventHandled(bool handled) { _handled = handled; }
68 bool getEventHandled() const { return _handled; }
69
70 void setEvents(const EventQueue::Events& events) { _events = events; }
72 const EventQueue::Events& getEvents() const { return _events; }
73
74 public:
75
76 virtual void reset();
77
79 virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
80
81
82 virtual void apply(osg::Drawable& drawable)
83 {
84 osg::Callback* callback = drawable.getEventCallback();
85 if (callback)
86 {
87 osgGA::EventHandler* eh = callback->asEventHandler();
88 if (eh)
89 {
90 callback->run(&drawable,this);
91 }
92 else
93 {
94 osg::DrawableEventCallback* drawable_callback = callback->asDrawableEventCallback();
95 osg::NodeCallback* node_callback = callback->asNodeCallback();
96 osg::CallbackObject* callback_object = callback->asCallbackObject();
97
98 if (drawable_callback) drawable_callback->event(this,&drawable);
99 if (node_callback) (*node_callback)(&drawable, this);
100 if (callback_object) callback_object->run(&drawable, this);
101
102 if (!drawable_callback && !node_callback && !callback_object) callback->run(&drawable, this);
103 }
104 }
105
106 handle_callbacks(drawable.getStateSet());
107 }
108
109 // The following overrides are technically redundant as the default implementation would eventually trickle down to
110 // apply(osg::Node&); - however defining these explicitly should save a couple of virtual function calls
111 virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
114 virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
117 virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
118 virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
120
121
122 protected:
123
125 EventVisitor& operator = (const EventVisitor&) { return *this; }
126
127 inline void handle_callbacks(osg::StateSet* stateset)
128 {
129 if (stateset && stateset->requiresEventTraversal())
130 {
131 stateset->runEventCallbacks(this);
132 }
133 }
134
136 {
138
139 osg::Callback* callback = node.getEventCallback();
140 if (callback) callback->run(&node,this);
141 else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node);
142 }
143
144
146
148
151};
152
153}
154
155#endif
156
The 'GA' in osgGA stands for 'GUI Abstraction'; the osgGA namespace provides facilities to help devel...
Definition Callback:21
Billboard is a derived form of Geode that orients its osg::Drawable children to face the eye point.
Definition Billboard:27
Definition Callback:34
virtual CallbackObject * asCallbackObject()
Convert 'this' into a CallbackObject pointer if Object is a CallbackObject, otherwise return 0.
Definition Callback:49
virtual osgGA::EventHandler * asEventHandler()
Definition Callback:70
virtual DrawableEventCallback * asDrawableEventCallback()
Definition Callback:64
virtual bool run(osg::Object *object, osg::Object *data)
Invoke the callback, first parameter is the Object that the callback is attached to,...
Definition Callback:80
virtual NodeCallback * asNodeCallback()
Definition Callback:52
Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding...
Definition Callback:134
bool run(osg::Object *object, osg::Object *data)
override Callback::run() entry point to adapt to CallbackObject::run(..) method.
Deprecated.
Definition Callback:215
Definition Callback:320
virtual void event(osg::NodeVisitor *, osg::Drawable *)
do customized Event code.
Definition Callback:337
Pure virtual base class for drawable geometry.
Definition Drawable:89
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
General group node which maintains a list of children.
Definition Group:29
Leaf Node for defining a light in the scene.
Definition LightSource:25
LOD - Level Of Detail group node which allows switching between children depending on distance from e...
Definition LOD:36
Base class for all internal nodes in the scene graph.
Definition Node:72
unsigned int getNumChildrenRequiringEventTraversal() const
Get the number of Children of this node which require Event traversal, since they have an Event Callb...
Definition Node:284
osg::StateSet * getStateSet()
Return the node's StateSet.
Definition Node:382
Callback * getEventCallback()
Get event node callback, called during event traversal.
Definition Node:252
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
void traverse(Node &node)
Method for handling traversal of a nodes.
Definition NodeVisitor:274
OccluderNode is a Group node which provides hooks for adding ConvexPlanarOccluders to the scene.
Definition OccluderNode:27
Projection nodes set up the frustum/orthographic projection used when rendering the scene.
Definition Projection:25
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
void runEventCallbacks(osg::NodeVisitor *nv)
Run the event callbacks attached directly to this StateSet or to its children.
bool requiresEventTraversal() const
Return whether this StateSet has event callbacks associated with it, and therefore must be traversed.
Definition StateSet:496
Switch is a Group node that allows switching between children.
Definition Switch:27
A Transform is a group node for which all children are transformed by a 4x4 matrix.
Definition Transform:75
Base Event class.
Definition Event:27
EventHandler is base class for adding handling of events, either as node event callback,...
Definition EventHandler:34
std::list< osg::ref_ptr< Event > > Events
Definition EventQueue:36
Basic EventVisitor implementation for animating a scene.
Definition EventVisitor:42
bool getEventHandled() const
Definition EventVisitor:68
virtual void reset()
Method to call to reset visitor.
virtual ~EventVisitor()
virtual void apply(osg::Projection &node)
Definition EventVisitor:116
const EventQueue::Events & getEvents() const
Definition EventVisitor:72
osg::ref_ptr< GUIEventAdapter > _accumulateEventState
Definition EventVisitor:147
osgGA::GUIActionAdapter * getActionAdapter()
Definition EventVisitor:60
void setEventHandled(bool handled)
Definition EventVisitor:67
virtual void apply(osg::Transform &node)
Definition EventVisitor:115
bool _handled
Definition EventVisitor:149
void addEvent(Event *event)
virtual void apply(osg::LightSource &node)
Definition EventVisitor:113
EventQueue::Events _events
Definition EventVisitor:150
void removeEvent(Event *event)
virtual void apply(osg::OccluderNode &node)
Definition EventVisitor:119
const osgGA::GUIActionAdapter * getActionAdapter() const
Definition EventVisitor:62
virtual void apply(osg::Node &node)
During traversal each type of node calls its callbacks and its children traversed.
Definition EventVisitor:79
void setActionAdapter(osgGA::GUIActionAdapter *actionAdapter)
Definition EventVisitor:58
EventQueue::Events & getEvents()
Definition EventVisitor:71
void setEvents(const EventQueue::Events &events)
Definition EventVisitor:70
void handle_callbacks(osg::StateSet *stateset)
Definition EventVisitor:127
virtual void apply(osg::Switch &node)
Definition EventVisitor:117
osgGA::GUIActionAdapter * _actionAdapter
Definition EventVisitor:145
virtual void apply(osg::Billboard &node)
Definition EventVisitor:112
virtual void apply(osg::Drawable &drawable)
Definition EventVisitor:82
void handle_callbacks_and_traverse(osg::Node &node)
Definition EventVisitor:135
virtual void apply(osg::Geode &node)
Definition EventVisitor:111
META_NodeVisitor(osgGA, EventVisitor) virtual osgGA
Convert 'this' into a osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor,...
Definition EventVisitor:48
virtual void apply(osg::Group &node)
Definition EventVisitor:114
virtual void apply(osg::LOD &node)
Definition EventVisitor:118
virtual const osgGA::EventVisitor * asEventVisitor() const
convert 'const this' into a const osgGA::EventVisitor pointer if Object is a osgGA::EventVisitor,...
Definition EventVisitor:56
Definition GUIActionAdapter:62
#define OSGGA_EXPORT
Definition Export:40

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.