Skip to content
This repository
Browse code

Introduce new osgGA::Event and osgGA::EventHandler base classes that …

…the old GUIEventAdapter and GUIEventHandler now subclass from.

The new osgGA::Event is written to support more generic events than the original GUIEventAdapter which are written for keyboard and mouse events.
  • Loading branch information...
commit b683c691e8342603a32bc71a8a89a581dffbf095 1 parent 193ee6c
Robert OSFIELD authored

Showing 37 changed files with 513 additions and 399 deletions. Show diff stats Hide diff stats

  1. +11 10 applications/present3D/deprecated/Cluster.cpp
  2. +4 9 applications/present3D/deprecated/PointsEventHandler.cpp
  3. +12 14 applications/present3D/deprecated/PointsEventHandler.h
  4. +6 12 applications/present3D/deprecated/ShowEventHandler.cpp
  5. +6 8 applications/present3D/deprecated/ShowEventHandler.h
  6. +15 24 examples/osganimationtimeline/osganimationtimeline.cpp
  7. +93 92 examples/osgcluster/osgcluster.cpp
  8. +4 1 include/osgGA/CameraManipulator
  9. +8 8 include/osgGA/Device
  10. +52 0 include/osgGA/Event
  11. +63 0 include/osgGA/EventHandler
  12. +4 4 include/osgGA/EventQueue
  13. +2 7 include/osgGA/EventVisitor
  14. +8 11 include/osgGA/GUIEventAdapter
  15. +16 25 include/osgGA/GUIEventHandler
  16. +0 2  include/osgPresentation/deprecated/KeyEventHandler
  17. +0 2  include/osgPresentation/deprecated/PickEventHandler
  18. +0 5 include/osgPresentation/deprecated/SlideEventHandler
  19. +17 17 include/osgViewer/View
  20. +0 2  src/osgDB/PropertyInterface.cpp
  21. +4 0 src/osgGA/CMakeLists.txt
  22. +1 1  src/osgGA/Device.cpp
  23. +25 0 src/osgGA/Event.cpp
  24. +52 0 src/osgGA/EventHandler.cpp
  25. +4 4 src/osgGA/EventQueue.cpp
  26. +3 3 src/osgGA/EventVisitor.cpp
  27. +1 3 src/osgGA/GUIEventAdapter.cpp
  28. +12 24 src/osgGA/GUIEventHandler.cpp
  29. +2 2 src/osgManipulator/Dragger.cpp
  30. +3 1 src/osgPresentation/Cursor.cpp
  31. +0 6 src/osgPresentation/deprecated/KeyEventHandler.cpp
  32. +0 6 src/osgPresentation/deprecated/PickEventHandler.cpp
  33. +0 19 src/osgPresentation/deprecated/SlideEventHandler.cpp
  34. +2 1  src/osgPresentation/deprecated/Timeout.cpp
  35. +18 14 src/osgViewer/CompositeViewer.cpp
  36. +52 52 src/osgViewer/View.cpp
  37. +13 10 src/osgViewer/Viewer.cpp
21 applications/present3D/deprecated/Cluster.cpp
... ... @@ -1,12 +1,12 @@
1   -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
  1 +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 2 *
3   - * This software is open source and may be redistributed and/or modified under
  3 + * This software is open source and may be redistributed and/or modified under
4 4 * the terms of the GNU General Public License (GPL) version 2.0.
5 5 * The full license is in LICENSE.txt file included with this distribution,.
6   - *
  6 + *
7 7 * This software is distributed in the hope that it will be useful,
8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 * include LICENSE.txt for more details.
11 11 */
12 12
@@ -39,9 +39,9 @@
39 39 #elif defined(__sgi)
40 40 #include <unistd.h>
41 41 #include <net/soioctl.h>
42   -#elif defined(__CYGWIN__)
  42 +#elif defined(__CYGWIN__)
43 43 #include <unistd.h>
44   -#elif defined(__sun)
  44 +#elif defined(__sun)
45 45 #include <unistd.h>
46 46 #include <sys/sockio.h>
47 47 #elif defined (__APPLE__)
@@ -202,7 +202,8 @@ void DataConverter::write(CameraPacket& cameraPacket)
202 202 itr != cameraPacket._events.end();
203 203 ++itr)
204 204 {
205   - write(*(*itr));
  205 + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
  206 + if (event) write(*(event));
206 207 }
207 208 }
208 209
@@ -249,7 +250,7 @@ void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer)
249 250
250 251 //////////////////////////////////////////////////////////////////////////////
251 252 //
252   -// Reciever
  253 +// Reciever
253 254 //
254 255 Receiver::Receiver( void )
255 256 {
@@ -338,7 +339,7 @@ void Receiver::sync( void )
338 339
339 340 #if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || \
340 341 defined(__DragonFly__)
341   - socklen_t
  342 + socklen_t
342 343 #else
343 344 int
344 345 #endif
@@ -381,7 +382,7 @@ void Receiver::sync( void )
381 382
382 383 //////////////////////////////////////////////////////////////////////////////
383 384 //
384   -// Broadcaster
  385 +// Broadcaster
385 386 //
386 387 Broadcaster::Broadcaster( void )
387 388 {
13 applications/present3D/deprecated/PointsEventHandler.cpp
... ... @@ -1,12 +1,12 @@
1   -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
  1 +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 2 *
3   - * This software is open source and may be redistributed and/or modified under
  3 + * This software is open source and may be redistributed and/or modified under
4 4 * the terms of the GNU General Public License (GPL) version 2.0.
5 5 * The full license is in LICENSE.txt file included with this distribution,.
6   - *
  6 + *
7 7 * This software is distributed in the hope that it will be useful,
8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 * include LICENSE.txt for more details.
11 11 */
12 12
@@ -54,11 +54,6 @@ bool PointsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
54 54 return false;
55 55 }
56 56
57   -void PointsEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
58   -{
59   - v.visit(*this);
60   -}
61   -
62 57 void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const
63 58 {
64 59 usage.addKeyboardMouseBinding("+","Increase point size");
26 applications/present3D/deprecated/PointsEventHandler.h
... ... @@ -1,12 +1,12 @@
1   -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
  1 +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 2 *
3   - * This software is open source and may be redistributed and/or modified under
  3 + * This software is open source and may be redistributed and/or modified under
4 4 * the terms of the GNU General Public License (GPL) version 2.0.
5 5 * The full license is in LICENSE.txt file included with this distribution,.
6   - *
  6 + *
7 7 * This software is distributed in the hope that it will be useful,
8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 * include LICENSE.txt for more details.
11 11 */
12 12
@@ -22,25 +22,23 @@ class PointsEventHandler : public osgGA::GUIEventHandler
22 22 {
23 23 public:
24 24 PointsEventHandler();
25   -
  25 +
26 26 virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
27   -
28   - virtual void accept(osgGA::GUIEventHandlerVisitor& v);
29   -
  27 +
30 28 void getUsage(osg::ApplicationUsage& usage) const;
31   -
  29 +
32 30 void setStateSet(osg::StateSet* stateset) { _stateset=stateset; }
33   -
  31 +
34 32 osg::StateSet* getStateSet() { return _stateset.get(); }
35   -
  33 +
36 34 const osg::StateSet* getStateSet() const { return _stateset.get(); }
37   -
  35 +
38 36 void setPointSize(float psize);
39 37
40 38 float getPointSize() const;
41   -
  39 +
42 40 void changePointSize(float delta);
43   -
  41 +
44 42 void changePointAttenuation(float scale);
45 43
46 44 osg::ref_ptr<osg::StateSet> _stateset;
18 applications/present3D/deprecated/ShowEventHandler.cpp
... ... @@ -1,12 +1,12 @@
1   -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
  1 +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 2 *
3   - * This software is open source and may be redistributed and/or modified under
  3 + * This software is open source and may be redistributed and/or modified under
4 4 * the terms of the GNU General Public License (GPL) version 2.0.
5 5 * The full license is in LICENSE.txt file included with this distribution,.
6   - *
  6 + *
7 7 * This software is distributed in the hope that it will be useful,
8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 * include LICENSE.txt for more details.
11 11 */
12 12
@@ -28,13 +28,13 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
28 28 case(osgGA::GUIEventAdapter::KEYUP):
29 29 {
30 30 osg::notify(osg::INFO)<<"ShowEventHandler KEYUP "<<(int)ea.getKey()<<std::endl;
31   - if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 &&
  31 + if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 &&
32 32 ea.getKey()<=osgGA::GUIEventAdapter::KEY_F8)
33 33 {
34 34 unsigned int child = ea.getKey()-osgGA::GUIEventAdapter::KEY_F1;
35 35 osg::notify(osg::INFO)<<" Select "<<child<<std::endl;
36 36 osg::Switch* showSwitch = dynamic_cast<osg::Switch*>(object);
37   - if (showSwitch)
  37 + if (showSwitch)
38 38 {
39 39 if (child<showSwitch->getNumChildren())
40 40 {
@@ -52,12 +52,6 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
52 52 return false;
53 53 }
54 54
55   -
56   -void ShowEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
57   -{
58   - v.visit(*this);
59   -}
60   -
61 55 void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
62 56 {
63 57 }
14 applications/present3D/deprecated/ShowEventHandler.h
... ... @@ -1,12 +1,12 @@
1   -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
  1 +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 2 *
3   - * This software is open source and may be redistributed and/or modified under
  3 + * This software is open source and may be redistributed and/or modified under
4 4 * the terms of the GNU General Public License (GPL) version 2.0.
5 5 * The full license is in LICENSE.txt file included with this distribution,.
6   - *
  6 + *
7 7 * This software is distributed in the hope that it will be useful,
8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 * include LICENSE.txt for more details.
11 11 */
12 12
@@ -28,11 +28,9 @@ class ShowEventHandler : public osgGA::GUIEventHandler
28 28 ShowEventHandler();
29 29
30 30 virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv);
31   -
32   - virtual void accept(osgGA::GUIEventHandlerVisitor& v);
33   -
  31 +
34 32 virtual void getUsage(osg::ApplicationUsage& usage) const;
35   -
  33 +
36 34 };
37 35
38 36 }
39 examples/osganimationtimeline/osganimationtimeline.cpp
... ... @@ -1,14 +1,14 @@
1   -/* -*-c++-*-
  1 +/* -*-c++-*-
2 2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3 3 *
4   - * This library is open source and may be redistributed and/or modified under
5   - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  4 + * This library is open source and may be redistributed and/or modified under
  5 + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 6 * (at your option) any later version. The full license is in LICENSE file
7 7 * included with this distribution, and on the openscenegraph.org website.
8   - *
  8 + *
9 9 * This library is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * OpenSceneGraph Public License for more details.
13 13 */
14 14
@@ -84,7 +84,7 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
84 84 _scratchNose->setLoop(1); // one time
85 85
86 86 // add the main loop at priority 0 at time 0.
87   -
  87 +
88 88 osgAnimation::Timeline* tml = _manager->getTimeline();
89 89 tml->play();
90 90 tml->addActionAt(0.0, _mainLoop.get(), 0);
@@ -139,21 +139,12 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
139 139 }
140 140 _releaseKey = false;
141 141 }
  142 + traverse(node, nv);
142 143 }
143 144 else
144 145 {
145   - osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
146   - if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
147   - {
148   - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
149   - itr != ev->getEvents().end();
150   - ++itr)
151   - {
152   - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv);
153   - }
154   - }
155   - }
156   - traverse(node, nv);
  146 + osgGA::GUIEventHandler::operator()(node, nv);
  147 + }
157 148 }
158 149
159 150 };
@@ -168,7 +159,7 @@ int main (int argc, char* argv[])
168 159 osgViewer::Viewer viewer(psr);
169 160
170 161 std::string file = "nathan.osg";
171   - if(argc >= 2)
  162 + if(argc >= 2)
172 163 file = psr[1];
173 164
174 165 // replace the manager
@@ -178,7 +169,7 @@ int main (int argc, char* argv[])
178 169 return 1;
179 170 }
180 171 osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback());
181   - if(!animationManager)
  172 + if(!animationManager)
182 173 {
183 174 osg::notify(osg::FATAL) << "Did not find AnimationManagerBase updateCallback needed to animate elements" << std::endl;
184 175 return 1;
@@ -186,22 +177,22 @@ int main (int argc, char* argv[])
186 177
187 178 osg::ref_ptr<osgAnimation::TimelineAnimationManager> tl = new osgAnimation::TimelineAnimationManager(*animationManager);
188 179 root->setUpdateCallback(tl.get());
189   -
  180 +
190 181 ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get());
191 182 root->setEventCallback(callback);
192 183 root->getUpdateCallback()->addNestedCallback(callback);
193   -
  184 +
194 185
195 186
196 187 // add the state manipulator
197 188 viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
198   -
  189 +
199 190 // add the thread model handler
200 191 viewer.addEventHandler(new osgViewer::ThreadingHandler);
201 192
202 193 // add the window size toggle handler
203 194 viewer.addEventHandler(new osgViewer::WindowSizeHandler);
204   -
  195 +
205 196 // add the stats handler
206 197 viewer.addEventHandler(new osgViewer::StatsHandler);
207 198
185 examples/osgcluster/osgcluster.cpp
@@ -48,13 +48,13 @@ const unsigned int MAX_NUM_EVENTS = 10;
48 48 const unsigned int SWAP_BYTES_COMPARE = 0x12345678;
49 49 class CameraPacket {
50 50 public:
51   -
52   -
53   - CameraPacket():_masterKilled(false)
  51 +
  52 +
  53 + CameraPacket():_masterKilled(false)
54 54 {
55 55 _byte_order = SWAP_BYTES_COMPARE;
56 56 }
57   -
  57 +
58 58 void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp)
59 59 {
60 60 _matrix = matrix;
@@ -63,20 +63,20 @@ class CameraPacket {
63 63 _frameStamp = *frameStamp;
64 64 }
65 65 }
66   -
  66 +
67 67 void getModelView(osg::Matrix& matrix,float angle_offset=0.0f)
68 68 {
69   -
  69 +
70 70 matrix = _matrix * osg::Matrix::rotate(osg::DegreesToRadians(angle_offset),0.0f,1.0f,0.0f);
71 71 }
72   -
  72 +
73 73 void readEventQueue(osgViewer::Viewer& viewer);
74   -
  74 +
75 75 void writeEventQueue(osgViewer::Viewer& viewer);
76 76
77 77 void setMasterKilled(const bool flag) { _masterKilled = flag; }
78 78 const bool getMasterKilled() const { return _masterKilled; }
79   -
  79 +
80 80 unsigned int _byte_order;
81 81 bool _masterKilled;
82 82 osg::Matrix _matrix;
@@ -84,11 +84,11 @@ class CameraPacket {
84 84 // note don't use a ref_ptr as used elsewhere for FrameStamp
85 85 // since we don't want to copy the pointer - but the memory.
86 86 // FrameStamp doesn't have a private destructor to allow
87   - // us to do this, even though its a reference counted object.
  87 + // us to do this, even though its a reference counted object.
88 88 osg::FrameStamp _frameStamp;
89   -
  89 +
90 90 osgGA::EventQueue::Events _events;
91   -
  91 +
92 92 };
93 93
94 94 class DataConverter
@@ -112,7 +112,7 @@ class DataConverter
112 112 bool _swapBytes;
113 113
114 114 char* _currentPtr;
115   -
  115 +
116 116 void reset()
117 117 {
118 118 _currentPtr = _startPtr;
@@ -122,22 +122,22 @@ class DataConverter
122 122 {
123 123 if (_currentPtr+1>=_endPtr) return;
124 124
125   - *(_currentPtr++) = *(ptr);
  125 + *(_currentPtr++) = *(ptr);
126 126 }
127 127
128 128 inline void read1(char* ptr)
129 129 {
130 130 if (_currentPtr+1>=_endPtr) return;
131 131
132   - *(ptr) = *(_currentPtr++);
  132 + *(ptr) = *(_currentPtr++);
133 133 }
134 134
135 135 inline void write2(char* ptr)
136 136 {
137 137 if (_currentPtr+2>=_endPtr) return;
138 138
139   - *(_currentPtr++) = *(ptr++);
140   - *(_currentPtr++) = *(ptr);
  139 + *(_currentPtr++) = *(ptr++);
  140 + *(_currentPtr++) = *(ptr);
141 141 }
142 142
143 143 inline void read2(char* ptr)
@@ -146,13 +146,13 @@ class DataConverter
146 146
147 147 if (_swapBytes)
148 148 {
149   - *(ptr+1) = *(_currentPtr++);
150   - *(ptr) = *(_currentPtr++);
  149 + *(ptr+1) = *(_currentPtr++);
  150 + *(ptr) = *(_currentPtr++);
151 151 }
152 152 else
153 153 {
154   - *(ptr++) = *(_currentPtr++);
155   - *(ptr) = *(_currentPtr++);
  154 + *(ptr++) = *(_currentPtr++);
  155 + *(ptr) = *(_currentPtr++);
156 156 }
157 157 }
158 158
@@ -160,10 +160,10 @@ class DataConverter
160 160 {
161 161 if (_currentPtr+4>=_endPtr) return;
162 162
163   - *(_currentPtr++) = *(ptr++);
164   - *(_currentPtr++) = *(ptr++);
165   - *(_currentPtr++) = *(ptr++);
166   - *(_currentPtr++) = *(ptr);
  163 + *(_currentPtr++) = *(ptr++);
  164 + *(_currentPtr++) = *(ptr++);
  165 + *(_currentPtr++) = *(ptr++);
  166 + *(_currentPtr++) = *(ptr);
167 167 }
168 168
169 169 inline void read4(char* ptr)
@@ -172,17 +172,17 @@ class DataConverter
172 172
173 173 if (_swapBytes)
174 174 {
175   - *(ptr+3) = *(_currentPtr++);
176   - *(ptr+2) = *(_currentPtr++);
177   - *(ptr+1) = *(_currentPtr++);
178   - *(ptr) = *(_currentPtr++);
  175 + *(ptr+3) = *(_currentPtr++);
  176 + *(ptr+2) = *(_currentPtr++);
  177 + *(ptr+1) = *(_currentPtr++);
  178 + *(ptr) = *(_currentPtr++);
179 179 }
180 180 else
181 181 {
182   - *(ptr++) = *(_currentPtr++);
183   - *(ptr++) = *(_currentPtr++);
184   - *(ptr++) = *(_currentPtr++);
185   - *(ptr) = *(_currentPtr++);
  182 + *(ptr++) = *(_currentPtr++);
  183 + *(ptr++) = *(_currentPtr++);
  184 + *(ptr++) = *(_currentPtr++);
  185 + *(ptr) = *(_currentPtr++);
186 186 }
187 187 }
188 188
@@ -190,15 +190,15 @@ class DataConverter
190 190 {
191 191 if (_currentPtr+8>=_endPtr) return;
192 192
193   - *(_currentPtr++) = *(ptr++);
194   - *(_currentPtr++) = *(ptr++);
195   - *(_currentPtr++) = *(ptr++);
196   - *(_currentPtr++) = *(ptr++);
  193 + *(_currentPtr++) = *(ptr++);
  194 + *(_currentPtr++) = *(ptr++);
  195 + *(_currentPtr++) = *(ptr++);
  196 + *(_currentPtr++) = *(ptr++);
197 197
198   - *(_currentPtr++) = *(ptr++);
199   - *(_currentPtr++) = *(ptr++);
200   - *(_currentPtr++) = *(ptr++);
201   - *(_currentPtr++) = *(ptr);
  198 + *(_currentPtr++) = *(ptr++);
  199 + *(_currentPtr++) = *(ptr++);
  200 + *(_currentPtr++) = *(ptr++);
  201 + *(_currentPtr++) = *(ptr);
202 202 }
203 203
204 204 inline void read8(char* ptr)
@@ -208,27 +208,27 @@ class DataConverter
208 208
209 209 if (_swapBytes)
210 210 {
211   - *(ptr+7) = *(_currentPtr++);
212   - *(ptr+6) = *(_currentPtr++);
213   - *(ptr+5) = *(_currentPtr++);
214   - *(ptr+4) = *(_currentPtr++);
215   -
216   - *(ptr+3) = *(_currentPtr++);
217   - *(ptr+2) = *(_currentPtr++);
218   - *(ptr+1) = *(_currentPtr++);
219   - *(ptr) = *(_currentPtr++);
  211 + *(ptr+7) = *(_currentPtr++);
  212 + *(ptr+6) = *(_currentPtr++);
  213 + *(ptr+5) = *(_currentPtr++);
  214 + *(ptr+4) = *(_currentPtr++);
  215 +
  216 + *(ptr+3) = *(_currentPtr++);
  217 + *(ptr+2) = *(_currentPtr++);
  218 + *(ptr+1) = *(_currentPtr++);
  219 + *(ptr) = *(_currentPtr++);
220 220 }
221 221 else
222 222 {
223   - *(ptr++) = *(_currentPtr++);
224   - *(ptr++) = *(_currentPtr++);
225   - *(ptr++) = *(_currentPtr++);
226   - *(ptr++) = *(_currentPtr++);
227   -
228   - *(ptr++) = *(_currentPtr++);
229   - *(ptr++) = *(_currentPtr++);
230   - *(ptr++) = *(_currentPtr++);
231   - *(ptr) = *(_currentPtr++);
  223 + *(ptr++) = *(_currentPtr++);
  224 + *(ptr++) = *(_currentPtr++);
  225 + *(ptr++) = *(_currentPtr++);
  226 + *(ptr++) = *(_currentPtr++);
  227 +
  228 + *(ptr++) = *(_currentPtr++);
  229 + *(ptr++) = *(_currentPtr++);
  230 + *(ptr++) = *(_currentPtr++);
  231 + *(ptr) = *(_currentPtr++);
232 232 }
233 233 }
234 234
@@ -361,22 +361,23 @@ class DataConverter
361 361 event.setModKeyMask(readUInt());
362 362 event.setTime(readDouble());
363 363 }
364   -
  364 +
365 365 void write(CameraPacket& cameraPacket)
366 366 {
367 367 writeUInt(cameraPacket._byte_order);
368   -
  368 +
369 369 writeUInt(cameraPacket._masterKilled);
370   -
  370 +
371 371 write(cameraPacket._matrix);
372 372 write(cameraPacket._frameStamp);
373   -
  373 +
374 374 writeUInt(cameraPacket._events.size());
375 375 for(osgGA::EventQueue::Events::iterator itr = cameraPacket._events.begin();
376 376 itr != cameraPacket._events.end();
377 377 ++itr)
378 378 {
379   - write(*(*itr));
  379 + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
  380 + if (event) write(*event);
380 381 }
381 382 }
382 383
@@ -387,12 +388,12 @@ class DataConverter
387 388 {
388 389 _swapBytes = !_swapBytes;
389 390 }
390   -
  391 +
391 392 cameraPacket._masterKilled = readUInt()!=0;
392   -
  393 +
393 394 read(cameraPacket._matrix);
394 395 read(cameraPacket._frameStamp);
395   -
  396 +
396 397 cameraPacket._events.clear();
397 398 unsigned int numEvents = readUInt();
398 399 for(unsigned int i=0;i<numEvents;++i)
@@ -409,7 +410,7 @@ void CameraPacket::readEventQueue(osgViewer::Viewer& viewer)
409 410 _events.clear();
410 411
411 412 osgViewer::ViewerBase::Contexts contexts;
412   - viewer.getContexts(contexts);
  413 + viewer.getContexts(contexts);
413 414
414 415 for(osgViewer::ViewerBase::Contexts::iterator citr =contexts.begin(); citr != contexts.end(); ++citr)
415 416 {
@@ -423,7 +424,7 @@ void CameraPacket::readEventQueue(osgViewer::Viewer& viewer)
423 424 }
424 425 _events.insert(_events.end(), gw_events.begin(), gw_events.end());
425 426 }
426   -
  427 +
427 428 viewer.getEventQueue()->copyEvents(_events);
428 429
429 430 osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl;
@@ -449,7 +450,7 @@ int main( int argc, char **argv )
449 450 {
450 451 // use an ArgumentParser object to manage the program arguments.
451 452 osg::ArgumentParser arguments(&argc,argv);
452   -
  453 +
453 454 // set up the usage document, in case we need to print out how to use this program.
454 455 arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to approach implementation of clustering.");
455 456 arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
@@ -459,7 +460,7 @@ int main( int argc, char **argv )
459 460 arguments.getApplicationUsage()->addCommandLineOption("-n <int>","Socket number to transmit packets");
460 461 arguments.getApplicationUsage()->addCommandLineOption("-f <float>","Field of view of camera");
461 462 arguments.getApplicationUsage()->addCommandLineOption("-o <float>","Offset angle of camera");
462   -
  463 +
463 464 // construct the viewer.
464 465 osgViewer::Viewer viewer;
465 466
@@ -468,12 +469,12 @@ int main( int argc, char **argv )
468 469 ViewerMode viewerMode = STAND_ALONE;
469 470 while (arguments.read("-m")) viewerMode = MASTER;
470 471 while (arguments.read("-s")) viewerMode = SLAVE;
471   -
  472 +
472 473 int socketNumber=8100;
473 474 while (arguments.read("-n",socketNumber)) ;
474 475
475 476 float camera_fov=-1.0f;
476   - while (arguments.read("-f",camera_fov))
  477 + while (arguments.read("-f",camera_fov))
477 478 {
478 479 }
479 480
@@ -497,7 +498,7 @@ int main( int argc, char **argv )
497 498 arguments.writeErrorMessages(std::cout);
498 499 return 1;
499 500 }
500   -
  501 +
501 502 if (arguments.argc()<=1)
502 503 {
503 504 arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
@@ -514,13 +515,13 @@ int main( int argc, char **argv )
514 515 {
515 516 double fovy, aspectRatio, zNear, zFar;
516 517 viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
517   -
  518 +
518 519 double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0;
519 520 std::cout << "setting lens perspective : original "<<original_fov<<" "<<fovy<<std::endl;
520   -
  521 +
521 522 fovy = atan(tan(osg::DegreesToRadians(camera_fov)*0.5)/aspectRatio)*2.0;
522 523 viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
523   -
  524 +
524 525 viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
525 526 original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0;
526 527 std::cout << "setting lens perspective : new "<<original_fov<<" "<<fovy<<std::endl;
@@ -549,13 +550,13 @@ int main( int argc, char **argv )
549 550 rc.setPort(static_cast<short int>(socketNumber));
550 551
551 552 bool masterKilled = false;
552   -
  553 +
553 554 DataConverter scratchPad(1024);
554 555
555 556 while( !viewer.done() && !masterKilled )
556 557 {
557 558 osg::Timer_t startTick = osg::Timer::instance()->tick();
558   -
  559 +
559 560 viewer.advance();
560 561
561 562 // special handling for working as a cluster.
@@ -563,12 +564,12 @@ int main( int argc, char **argv )
563 564 {
564 565 case(MASTER):
565 566 {
566   -
  567 +
567 568 // take camera zero as the guide.
568 569 osg::Matrix modelview(viewer.getCamera()->getViewMatrix());
569   -
  570 +
570 571 cp->setPacket(modelview,viewer.getFrameStamp());
571   -
  572 +
572 573 cp->readEventQueue(viewer);
573 574
574 575 scratchPad.reset();
@@ -578,11 +579,11 @@ int main( int argc, char **argv )
578 579 scratchPad.read(*cp);
579 580
580 581 bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
581   -
  582 +
582 583 std::cout << "bc.sync()"<<scratchPad._numBytes<<std::endl;
583 584
584 585 bc.sync();
585   -
  586 +
586 587 }
587 588 break;
588 589 case(SLAVE):
@@ -591,13 +592,13 @@ int main( int argc, char **argv )
591 592 rc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
592 593
593 594 rc.sync();
594   -
  595 +
595 596 scratchPad.reset();
596 597 scratchPad.read(*cp);
597   -
  598 +
598 599 cp->writeEventQueue(viewer);
599 600
600   - if (cp->getMasterKilled())
  601 + if (cp->getMasterKilled())
601 602 {
602 603 std::cout << "Received master killed."<<std::endl;
603 604 // break out of while (!done) loop since we've now want to shut down.
@@ -609,9 +610,9 @@ int main( int argc, char **argv )
609 610 // no need to anything here, just a normal interactive viewer.
610 611 break;
611 612 }
612   -
  613 +
613 614 osg::Timer_t endTick = osg::Timer::instance()->tick();
614   -
  615 +
615 616 osg::notify(osg::INFO)<<"Time to do cluster sync "<<osg::Timer::instance()->delta_m(startTick,endTick)<<std::endl;
616 617
617 618 // update the scene by traversing it with the the update visitor which will
@@ -623,14 +624,14 @@ int main( int argc, char **argv )
623 624 {
624 625 osg::Matrix modelview;
625 626 cp->getModelView(modelview,camera_offset);
626   -
  627 +
627 628 viewer.getCamera()->setViewMatrix(modelview);
628 629 }
629 630
630 631 // fire off the cull and draw traversals of the scene.
631 632 if(!masterKilled)
632 633 viewer.renderingTraversals();
633   -
  634 +
634 635 }
635 636
636 637 // if we are master clean up by telling all slaves that we're going down.
@@ -638,7 +639,7 @@ int main( int argc, char **argv )
638 639 {
639 640 // need to broadcast my death.
640 641 cp->setPacket(osg::Matrix::identity(),viewer.getFrameStamp());
641   - cp->setMasterKilled(true);
  642 + cp->setMasterKilled(true);
642 643
643 644 scratchPad.reset();
644 645 scratchPad.write(*cp);
5 include/osgGA/CameraManipulator
@@ -87,7 +87,7 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
87 87 /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
88 88 virtual osg::Matrixd getInverseMatrix() const = 0;
89 89
90   - /** update the camera for the current frame, typically called by the viewer classes.
  90 + /** update the camera for the current frame, typically called by the viewer classes.
91 91 Default implementation simply set the camera view matrix. */
92 92 virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
93 93
@@ -163,6 +163,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
163 163 */
164 164 virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
165 165
  166 + /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
  167 + virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
  168 +
166 169 /** Handle events, return true if handled, false otherwise. */
167 170 virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
168 171
16 include/osgGA/Device
@@ -29,16 +29,16 @@ class OSGGA_EXPORT Device : public osg::Object
29 29 RECEIVE_EVENTS = 1,
30 30 SEND_EVENTS = 2
31 31 } Capabilities;
32   -
  32 +
33 33 Device();
34 34 Device(const Device& es, const osg::CopyOp& copyop);
35 35
36 36 META_Object(osgGA,Device);
37   -
  37 +
38 38 int getCapabilities() const { return _capabilities; }
39   -
  39 +
40 40 virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; }
41   - virtual void sendEvent(const GUIEventAdapter& ea);
  41 + virtual void sendEvent(const Event& ea);
42 42 virtual void sendEvents(const EventQueue::Events& events);
43 43
44 44 void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
@@ -47,17 +47,17 @@ class OSGGA_EXPORT Device : public osg::Object
47 47
48 48 protected:
49 49 void setCapabilities(int capabilities) { _capabilities = capabilities; }
50   -
  50 +
51 51 virtual ~Device();
52 52
53 53 /** Prevent unwanted copy operator.*/
54 54 Device& operator = (const Device&) { return *this; }
55 55
56 56 osg::ref_ptr<osgGA::EventQueue> _eventQueue;
57   -
58   - private:
  57 +
  58 + private:
59 59 int _capabilities;
60   -
  60 +
61 61 };
62 62
63 63 }
52 include/osgGA/Event
... ... @@ -0,0 +1,52 @@
  1 +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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_EVENT
  15 +#define OSGGA_EVENT 1
  16 +
  17 +#include <osgGA/Export>
  18 +#include <osg/Object>
  19 +
  20 +namespace osgGA {
  21 +
  22 +// forward declare
  23 +class GUIEventAdapter;
  24 +
  25 +/** Base Event class.*/
  26 +class OSGGA_EXPORT Event : public osg::Object
  27 +{
  28 +public:
  29 + Event();
  30 +
  31 + Event(const Event& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  32 +
  33 + META_Object(osgGA, Event);
  34 +
  35 + virtual GUIEventAdapter* asGUIEventAdapter() { return 0; }
  36 + virtual const GUIEventAdapter* asGUIEventAdapter() const { return 0; }
  37 +
  38 + /** set time in seconds of event. */
  39 + void setTime(double time) { _time = time; }
  40 +
  41 + /** get time in seconds of event. */
  42 + double getTime() const { return _time; }
  43 +
  44 +protected:
  45 + virtual ~Event() {}
  46 +
  47 + double _time;
  48 +};
  49 +
  50 +}
  51 +
  52 +#endif
63 include/osgGA/EventHandler
... ... @@ -0,0 +1,63 @@
  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/NodeCallback>
  20 +#include <osg/Drawable>
  21 +#include <osg/ApplicationUsage>
  22 +
  23 +#include <osgGA/Export>
  24 +#include <osgGA/GUIEventAdapter>
  25 +#include <osgGA/GUIActionAdapter>
  26 +
  27 +
  28 +namespace osgGA{
  29 +
  30 +/**
  31 +EventHandler 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)
  32 +*/
  33 +
  34 +class OSGGA_EXPORT EventHandler : public osg::NodeCallback, public osg::Drawable::EventCallback
  35 +{
  36 +public:
  37 +
  38 + EventHandler() {}
  39 + EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
  40 + osg::NodeCallback(eh, copyop),
  41 + osg::Drawable::EventCallback(eh, copyop) {}
  42 +
  43 + META_Object(osgGA, EventHandler);
  44 +
  45 + /** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
  46 + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
  47 +
  48 + /** Event traversal drawable callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
  49 + virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable);
  50 +
  51 + /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
  52 + virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
  53 +
  54 + /** Get the user interface usage of this event handler, i.e. keyboard and mouse bindings.*/
  55 + virtual void getUsage(osg::ApplicationUsage&) const {}
  56 +
  57 +protected:
  58 +
  59 +};
  60 +
  61 +}
  62 +
  63 +#endif
8 include/osgGA/EventQueue
@@ -33,14 +33,14 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
33 33
34 34 EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS);
35 35
36   - typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events;
  36 + typedef std::list< osg::ref_ptr<Event> > Events;
37 37
38 38 bool empty() const
39 39 {
40 40 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
41 41 return _eventQueue.empty();
42 42 }
43   -
  43 +
44 44 /** Set events.*/
45 45 void setEvents(Events& events);
46 46
@@ -57,7 +57,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
57 57 void appendEvents(Events& events);
58 58
59 59 /** Add an event to the end of the event queue.*/
60   - void addEvent(GUIEventAdapter* event);
  60 + void addEvent(Event* event);
61 61
62 62
63 63 /** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they
@@ -70,7 +70,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
70 70
71 71 /** Set the graphics context associated with this event queue.*/
72 72 void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
73   -
  73 +
74 74 osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
75 75
76 76 const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }
9 include/osgGA/EventVisitor
@@ -51,16 +51,12 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
51 51
52 52 const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; }
53 53
54   -
55   - typedef std::list< osg::ref_ptr<GUIEventAdapter> > EventList;
56   -
57   - void addEvent(GUIEventAdapter* event);
58   - void removeEvent(GUIEventAdapter* event);
  54 + void addEvent(Event* event);
  55 + void removeEvent(Event* event);
59 56
60 57 void setEventHandled(bool handled) { _handled = handled; }
61 58 bool getEventHandled() const { return _handled; }
62 59
63   -
64 60 void setEvents(const EventQueue::Events& events) { _events = events; }
65 61 EventQueue::Events& getEvents() { return _events; }
66 62 const EventQueue::Events& getEvents() const { return _events; }
@@ -137,7 +133,6 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
137 133
138 134 bool _handled;
139 135 EventQueue::Events _events;
140   -
141 136 };
142 137
143 138 }
19 include/osgGA/GUIEventAdapter
@@ -11,13 +11,14 @@
11 11 * OpenSceneGraph Public License for more details.
12 12 */
13 13
14   -#ifndef OSGGA_EVENT
15   -#define OSGGA_EVENT 1
  14 +#ifndef OSGGA_GUIEVENTADAPTER
  15 +#define OSGGA_GUIEVENTADAPTER 1
16 16
17 17 #include <osg/Object>
18 18 #include <osg/Matrix>
19 19 #include <osg/GraphicsContext>
20   -#include <osgGA/Export>
  20 +
  21 +#include <osgGA/Event>
21 22
22 23 namespace osgGA{
23 24
@@ -77,7 +78,7 @@ struct PointerData : public osg::Referenced
77 78
78 79 /** Event class for storing Keyboard, mouse and window events.
79 80 */
80   -class OSGGA_EXPORT GUIEventAdapter : public osg::Object
  81 +class OSGGA_EXPORT GUIEventAdapter : public Event
81 82 {
82 83 public:
83 84
@@ -448,6 +449,9 @@ public:
448 449
449 450 META_Object(osgGA, GUIEventAdapter);
450 451
  452 + virtual GUIEventAdapter* asGUIEventAdapter() { return this; }
  453 + virtual const GUIEventAdapter* asGUIEventAdapter() const { return this; }
  454 +
451 455
452 456 /** Get the accumulated event state singleton.
453 457 * Typically all EventQueue will share this single GUIEventAdapter object for tracking
@@ -467,12 +471,6 @@ public:
467 471 /** get the event type. */
468 472 virtual EventType getEventType() const { return _eventType; }
469 473
470   - /** set time in seconds of event. */
471   - void setTime(double time) { _time = time; }
472   -
473   - /** get time in seconds of event. */
474   - double getTime() const { return _time; }
475   -
476 474 /** deprecated function for getting time of event. */
477 475 double time() const { return _time; }
478 476
@@ -709,7 +707,6 @@ public:
709 707
710 708 mutable bool _handled;
711 709 EventType _eventType;
712   - double _time;
713 710
714 711 osg::observer_ptr<osg::GraphicsContext> _context;
715 712 int _windowX;
41 include/osgGA/GUIEventHandler
@@ -20,7 +20,7 @@
20 20 #include <osg/Drawable>
21 21 #include <osg/ApplicationUsage>
22 22
23   -#include <osgGA/Export>
  23 +#include <osgGA/EventHandler>
24 24 #include <osgGA/GUIEventAdapter>
25 25 #include <osgGA/GUIActionAdapter>
26 26
@@ -47,27 +47,30 @@ This request is made via the GUIActionAdapter class.
47 47
48 48 */
49 49
50