root/OpenSceneGraph/trunk/include/osgGA/GUIEventHandler @ 13890

Revision 13890, 5.0 kB (checked in by robert, 10 days ago)

Added shaders to support experimental shader based displacement mapping technique osgTerrain::ShaderTerrain?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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_GUIEVENTHANDLER
15#define OSGGA_GUIEVENTHANDLER 1
16
17#include <vector>
18
19#include <osg/NodeCallback>
20#include <osg/Drawable>
21#include <osg/ApplicationUsage>
22
23#include <osgGA/EventHandler>
24#include <osgGA/GUIEventAdapter>
25#include <osgGA/GUIActionAdapter>
26
27
28// #define COMPILE_COMPOSITE_EVENTHANDLER
29
30namespace osgGA{
31
32/**
33
34GUIEventHandler provides a basic interface for any class which wants to handle
35a GUI Events.
36
37The GUIEvent is supplied by a GUIEventAdapter. Feedback resulting from the
38handle method is supplied by a GUIActionAdapter, which allows the GUIEventHandler
39to ask the GUI to take some action in response to an incoming event.
40
41For example, consider a Trackball Viewer class which takes mouse events and
42manipulates a scene camera in response. The Trackball Viewer is a GUIEventHandler,
43and receives the events via the handle method. If the user 'throws' the model,
44the Trackball Viewer class can detect this via the incoming events, and
45request that the GUI set up a timer callback to continually redraw the view.
46This request is made via the GUIActionAdapter class.
47
48*/
49
50class OSGGA_EXPORT GUIEventHandler : public EventHandler
51{
52public:
53
54#if 1
55        GUIEventHandler() {}
56        GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
57            EventHandler(eh, copyop) {}
58#else
59        GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
60        GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
61            EventHandler(eh, copyop)
62            _ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {}
63#endif
64
65        META_Object(osgGA,GUIEventHandler);
66
67        /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
68        virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
69
70        /** Handle events, return true if handled, false otherwise. */
71        virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); }
72
73#if 0
74        /** Convenience method that only passes on to the handle(,,,) method events that either haven't been
75          * handled yet, or have been handled but haven't be set to be ignored by the IgnoreHandledEventsMask.
76          * Note, this method is an inline method, and not appropriate for users to override, override the handle(,,,)
77          * method instead.*/
78        inline bool handleWithCheckAgainstIgnoreHandledEventsMask(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv)
79        {
80            if (!ea.getHandled() ||
81                (ea.getEventType() & _ignoreHandledEventsMask)==0)
82            {
83                bool handled = handle(ea,aa,object,nv);
84                if (handled) ea.setHandled(true);
85                return handled;
86            }
87            else
88            {
89                return false;
90            }
91        }
92#endif
93        /** Deprecated, Handle events, return true if handled, false otherwise. */
94        virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; }
95
96#if 0
97        /** Convenience method that only passes on to the handle(,) method events that either haven't been
98          * handled yet, or have been handled but haven't be set to be ignored by the IgnoreHandledEventsMask.
99          * Note, this method is an inline method, and not appropriate for users to override, override the handle(,)
100          * method instead.*/
101        inline bool handleWithCheckAgainstIgnoreHandledEventsMask(const GUIEventAdapter& ea,GUIActionAdapter& aa)
102        {
103            if (!ea.getHandled() ||
104                (ea.getEventType() & _ignoreHandledEventsMask)==0)
105            {
106                bool handled = handle(ea,aa);
107                if (handled) ea.setHandled(true);
108                return handled;
109            }
110            else
111            {
112                return false;
113            }
114        }
115
116        /** Set a mask of osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */
117        void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; }
118
119        /** Get the event mask of the osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */
120        unsigned int getIgnoreHandledEventsMask() const { return _ignoreHandledEventsMask; };
121
122protected:
123        unsigned int _ignoreHandledEventsMask;
124#endif
125};
126
127}
128
129#endif
Note: See TracBrowser for help on using the browser.