From b683c691e8342603a32bc71a8a89a581dffbf095 Mon Sep 17 00:00:00 2001 From: Robert OSFIELD Date: Fri, 25 Oct 2013 14:54:15 +0000 Subject: [PATCH] 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. --- applications/present3D/deprecated/Cluster.cpp | 21 +- .../deprecated/PointsEventHandler.cpp | 13 +- .../present3D/deprecated/PointsEventHandler.h | 26 ++- .../present3D/deprecated/ShowEventHandler.cpp | 18 +- .../present3D/deprecated/ShowEventHandler.h | 14 +- .../osganimationtimeline.cpp | 39 ++-- examples/osgcluster/osgcluster.cpp | 185 +++++++++--------- include/osgGA/CameraManipulator | 5 +- include/osgGA/Device | 16 +- include/osgGA/Event | 52 +++++ include/osgGA/EventHandler | 63 ++++++ include/osgGA/EventQueue | 8 +- include/osgGA/EventVisitor | 9 +- include/osgGA/GUIEventAdapter | 19 +- include/osgGA/GUIEventHandler | 41 ++-- .../deprecated/KeyEventHandler | 2 - .../deprecated/PickEventHandler | 2 - .../deprecated/SlideEventHandler | 5 - include/osgViewer/View | 34 ++-- src/osgDB/PropertyInterface.cpp | 2 - src/osgGA/CMakeLists.txt | 4 + src/osgGA/Device.cpp | 2 +- src/osgGA/Event.cpp | 25 +++ src/osgGA/EventHandler.cpp | 52 +++++ src/osgGA/EventQueue.cpp | 8 +- src/osgGA/EventVisitor.cpp | 6 +- src/osgGA/GUIEventAdapter.cpp | 4 +- src/osgGA/GUIEventHandler.cpp | 36 ++-- src/osgManipulator/Dragger.cpp | 4 +- src/osgPresentation/Cursor.cpp | 4 +- .../deprecated/KeyEventHandler.cpp | 6 - .../deprecated/PickEventHandler.cpp | 6 - .../deprecated/SlideEventHandler.cpp | 19 -- src/osgPresentation/deprecated/Timeout.cpp | 3 +- src/osgViewer/CompositeViewer.cpp | 32 +-- src/osgViewer/View.cpp | 104 +++++----- src/osgViewer/Viewer.cpp | 23 ++- 37 files changed, 513 insertions(+), 399 deletions(-) create mode 100644 include/osgGA/Event create mode 100644 include/osgGA/EventHandler create mode 100644 src/osgGA/Event.cpp create mode 100644 src/osgGA/EventHandler.cpp diff --git a/applications/present3D/deprecated/Cluster.cpp b/applications/present3D/deprecated/Cluster.cpp index 361dfe862ba..62d2313e6e2 100644 --- a/applications/present3D/deprecated/Cluster.cpp +++ b/applications/present3D/deprecated/Cluster.cpp @@ -1,12 +1,12 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * - * This software is open source and may be redistributed and/or modified under + * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. - * + * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ @@ -39,9 +39,9 @@ #elif defined(__sgi) #include #include -#elif defined(__CYGWIN__) +#elif defined(__CYGWIN__) #include -#elif defined(__sun) +#elif defined(__sun) #include #include #elif defined (__APPLE__) @@ -202,7 +202,8 @@ void DataConverter::write(CameraPacket& cameraPacket) itr != cameraPacket._events.end(); ++itr) { - write(*(*itr)); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (event) write(*(event)); } } @@ -249,7 +250,7 @@ void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer) ////////////////////////////////////////////////////////////////////////////// // -// Reciever +// Reciever // Receiver::Receiver( void ) { @@ -338,7 +339,7 @@ void Receiver::sync( void ) #if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || \ defined(__DragonFly__) - socklen_t + socklen_t #else int #endif @@ -381,7 +382,7 @@ void Receiver::sync( void ) ////////////////////////////////////////////////////////////////////////////// // -// Broadcaster +// Broadcaster // Broadcaster::Broadcaster( void ) { diff --git a/applications/present3D/deprecated/PointsEventHandler.cpp b/applications/present3D/deprecated/PointsEventHandler.cpp index 2a6b99dc72d..78ff548c75e 100644 --- a/applications/present3D/deprecated/PointsEventHandler.cpp +++ b/applications/present3D/deprecated/PointsEventHandler.cpp @@ -1,12 +1,12 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * - * This software is open source and may be redistributed and/or modified under + * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. - * + * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ @@ -54,11 +54,6 @@ bool PointsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio return false; } -void PointsEventHandler::accept(osgGA::GUIEventHandlerVisitor& v) -{ - v.visit(*this); -} - void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const { usage.addKeyboardMouseBinding("+","Increase point size"); diff --git a/applications/present3D/deprecated/PointsEventHandler.h b/applications/present3D/deprecated/PointsEventHandler.h index ca8ec18eae0..2594ad73bea 100644 --- a/applications/present3D/deprecated/PointsEventHandler.h +++ b/applications/present3D/deprecated/PointsEventHandler.h @@ -1,12 +1,12 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * - * This software is open source and may be redistributed and/or modified under + * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. - * + * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ @@ -22,25 +22,23 @@ class PointsEventHandler : public osgGA::GUIEventHandler { public: PointsEventHandler(); - + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); - - virtual void accept(osgGA::GUIEventHandlerVisitor& v); - + void getUsage(osg::ApplicationUsage& usage) const; - + void setStateSet(osg::StateSet* stateset) { _stateset=stateset; } - + osg::StateSet* getStateSet() { return _stateset.get(); } - + const osg::StateSet* getStateSet() const { return _stateset.get(); } - + void setPointSize(float psize); float getPointSize() const; - + void changePointSize(float delta); - + void changePointAttenuation(float scale); osg::ref_ptr _stateset; diff --git a/applications/present3D/deprecated/ShowEventHandler.cpp b/applications/present3D/deprecated/ShowEventHandler.cpp index fe3141ee8e8..e7be3626935 100644 --- a/applications/present3D/deprecated/ShowEventHandler.cpp +++ b/applications/present3D/deprecated/ShowEventHandler.cpp @@ -1,12 +1,12 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * - * This software is open source and may be redistributed and/or modified under + * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. - * + * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ @@ -28,13 +28,13 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA case(osgGA::GUIEventAdapter::KEYUP): { osg::notify(osg::INFO)<<"ShowEventHandler KEYUP "<<(int)ea.getKey()<=osgGA::GUIEventAdapter::KEY_F1 && + if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 && ea.getKey()<=osgGA::GUIEventAdapter::KEY_F8) { unsigned int child = ea.getKey()-osgGA::GUIEventAdapter::KEY_F1; osg::notify(osg::INFO)<<" Select "<(object); - if (showSwitch) + if (showSwitch) { if (childgetNumChildren()) { @@ -52,12 +52,6 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA return false; } - -void ShowEventHandler::accept(osgGA::GUIEventHandlerVisitor& v) -{ - v.visit(*this); -} - void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const { } diff --git a/applications/present3D/deprecated/ShowEventHandler.h b/applications/present3D/deprecated/ShowEventHandler.h index c252fcd1bd9..e23984d696a 100644 --- a/applications/present3D/deprecated/ShowEventHandler.h +++ b/applications/present3D/deprecated/ShowEventHandler.h @@ -1,12 +1,12 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * - * This software is open source and may be redistributed and/or modified under + * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. - * + * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ @@ -28,11 +28,9 @@ class ShowEventHandler : public osgGA::GUIEventHandler ShowEventHandler(); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); - - virtual void accept(osgGA::GUIEventHandlerVisitor& v); - + virtual void getUsage(osg::ApplicationUsage& usage) const; - + }; } diff --git a/examples/osganimationtimeline/osganimationtimeline.cpp b/examples/osganimationtimeline/osganimationtimeline.cpp index 129b6ef240b..0324704b964 100644 --- a/examples/osganimationtimeline/osganimationtimeline.cpp +++ b/examples/osganimationtimeline/osganimationtimeline.cpp @@ -1,14 +1,14 @@ -/* -*-c++-*- +/* -*-c++-*- * Copyright (C) 2008 Cedric Pinson * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -84,7 +84,7 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler _scratchNose->setLoop(1); // one time // add the main loop at priority 0 at time 0. - + osgAnimation::Timeline* tml = _manager->getTimeline(); tml->play(); tml->addActionAt(0.0, _mainLoop.get(), 0); @@ -139,21 +139,12 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler } _releaseKey = false; } + traverse(node, nv); } else { - osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) - { - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); - itr != ev->getEvents().end(); - ++itr) - { - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); - } - } - } - traverse(node, nv); + osgGA::GUIEventHandler::operator()(node, nv); + } } }; @@ -168,7 +159,7 @@ int main (int argc, char* argv[]) osgViewer::Viewer viewer(psr); std::string file = "nathan.osg"; - if(argc >= 2) + if(argc >= 2) file = psr[1]; // replace the manager @@ -178,7 +169,7 @@ int main (int argc, char* argv[]) return 1; } osgAnimation::AnimationManagerBase* animationManager = dynamic_cast(root->getUpdateCallback()); - if(!animationManager) + if(!animationManager) { osg::notify(osg::FATAL) << "Did not find AnimationManagerBase updateCallback needed to animate elements" << std::endl; return 1; @@ -186,22 +177,22 @@ int main (int argc, char* argv[]) osg::ref_ptr tl = new osgAnimation::TimelineAnimationManager(*animationManager); root->setUpdateCallback(tl.get()); - + ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get()); root->setEventCallback(callback); root->getUpdateCallback()->addNestedCallback(callback); - + // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); - + // add the thread model handler viewer.addEventHandler(new osgViewer::ThreadingHandler); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); diff --git a/examples/osgcluster/osgcluster.cpp b/examples/osgcluster/osgcluster.cpp index bb91db01543..d841f21beda 100644 --- a/examples/osgcluster/osgcluster.cpp +++ b/examples/osgcluster/osgcluster.cpp @@ -48,13 +48,13 @@ const unsigned int MAX_NUM_EVENTS = 10; const unsigned int SWAP_BYTES_COMPARE = 0x12345678; class CameraPacket { public: - - - CameraPacket():_masterKilled(false) + + + CameraPacket():_masterKilled(false) { _byte_order = SWAP_BYTES_COMPARE; } - + void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp) { _matrix = matrix; @@ -63,20 +63,20 @@ class CameraPacket { _frameStamp = *frameStamp; } } - + void getModelView(osg::Matrix& matrix,float angle_offset=0.0f) { - + matrix = _matrix * osg::Matrix::rotate(osg::DegreesToRadians(angle_offset),0.0f,1.0f,0.0f); } - + void readEventQueue(osgViewer::Viewer& viewer); - + void writeEventQueue(osgViewer::Viewer& viewer); void setMasterKilled(const bool flag) { _masterKilled = flag; } const bool getMasterKilled() const { return _masterKilled; } - + unsigned int _byte_order; bool _masterKilled; osg::Matrix _matrix; @@ -84,11 +84,11 @@ class CameraPacket { // note don't use a ref_ptr as used elsewhere for FrameStamp // since we don't want to copy the pointer - but the memory. // FrameStamp doesn't have a private destructor to allow - // us to do this, even though its a reference counted object. + // us to do this, even though its a reference counted object. osg::FrameStamp _frameStamp; - + osgGA::EventQueue::Events _events; - + }; class DataConverter @@ -112,7 +112,7 @@ class DataConverter bool _swapBytes; char* _currentPtr; - + void reset() { _currentPtr = _startPtr; @@ -122,22 +122,22 @@ class DataConverter { if (_currentPtr+1>=_endPtr) return; - *(_currentPtr++) = *(ptr); + *(_currentPtr++) = *(ptr); } inline void read1(char* ptr) { if (_currentPtr+1>=_endPtr) return; - *(ptr) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } inline void write2(char* ptr) { if (_currentPtr+2>=_endPtr) return; - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr); } inline void read2(char* ptr) @@ -146,13 +146,13 @@ class DataConverter if (_swapBytes) { - *(ptr+1) = *(_currentPtr++); - *(ptr) = *(_currentPtr++); + *(ptr+1) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } else { - *(ptr++) = *(_currentPtr++); - *(ptr) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } } @@ -160,10 +160,10 @@ class DataConverter { if (_currentPtr+4>=_endPtr) return; - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr); } inline void read4(char* ptr) @@ -172,17 +172,17 @@ class DataConverter if (_swapBytes) { - *(ptr+3) = *(_currentPtr++); - *(ptr+2) = *(_currentPtr++); - *(ptr+1) = *(_currentPtr++); - *(ptr) = *(_currentPtr++); + *(ptr+3) = *(_currentPtr++); + *(ptr+2) = *(_currentPtr++); + *(ptr+1) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } else { - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - *(ptr) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } } @@ -190,15 +190,15 @@ class DataConverter { if (_currentPtr+8>=_endPtr) return; - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr++); - *(_currentPtr++) = *(ptr); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr++); + *(_currentPtr++) = *(ptr); } inline void read8(char* ptr) @@ -208,27 +208,27 @@ class DataConverter if (_swapBytes) { - *(ptr+7) = *(_currentPtr++); - *(ptr+6) = *(_currentPtr++); - *(ptr+5) = *(_currentPtr++); - *(ptr+4) = *(_currentPtr++); - - *(ptr+3) = *(_currentPtr++); - *(ptr+2) = *(_currentPtr++); - *(ptr+1) = *(_currentPtr++); - *(ptr) = *(_currentPtr++); + *(ptr+7) = *(_currentPtr++); + *(ptr+6) = *(_currentPtr++); + *(ptr+5) = *(_currentPtr++); + *(ptr+4) = *(_currentPtr++); + + *(ptr+3) = *(_currentPtr++); + *(ptr+2) = *(_currentPtr++); + *(ptr+1) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } else { - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - *(ptr++) = *(_currentPtr++); - *(ptr) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr++) = *(_currentPtr++); + *(ptr) = *(_currentPtr++); } } @@ -361,22 +361,23 @@ class DataConverter event.setModKeyMask(readUInt()); event.setTime(readDouble()); } - + void write(CameraPacket& cameraPacket) { writeUInt(cameraPacket._byte_order); - + writeUInt(cameraPacket._masterKilled); - + write(cameraPacket._matrix); write(cameraPacket._frameStamp); - + writeUInt(cameraPacket._events.size()); for(osgGA::EventQueue::Events::iterator itr = cameraPacket._events.begin(); itr != cameraPacket._events.end(); ++itr) { - write(*(*itr)); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (event) write(*event); } } @@ -387,12 +388,12 @@ class DataConverter { _swapBytes = !_swapBytes; } - + cameraPacket._masterKilled = readUInt()!=0; - + read(cameraPacket._matrix); read(cameraPacket._frameStamp); - + cameraPacket._events.clear(); unsigned int numEvents = readUInt(); for(unsigned int i=0;icopyEvents(_events); osg::notify(osg::INFO)<<"written events = "<<_events.size()<setDescription(arguments.getApplicationName()+" is the example which demonstrates how to approach implementation of clustering."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); @@ -459,7 +460,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("-n ","Socket number to transmit packets"); arguments.getApplicationUsage()->addCommandLineOption("-f ","Field of view of camera"); arguments.getApplicationUsage()->addCommandLineOption("-o ","Offset angle of camera"); - + // construct the viewer. osgViewer::Viewer viewer; @@ -468,12 +469,12 @@ int main( int argc, char **argv ) ViewerMode viewerMode = STAND_ALONE; while (arguments.read("-m")) viewerMode = MASTER; while (arguments.read("-s")) viewerMode = SLAVE; - + int socketNumber=8100; while (arguments.read("-n",socketNumber)) ; float camera_fov=-1.0f; - while (arguments.read("-f",camera_fov)) + while (arguments.read("-f",camera_fov)) { } @@ -497,7 +498,7 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - + if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); @@ -514,13 +515,13 @@ int main( int argc, char **argv ) { double fovy, aspectRatio, zNear, zFar; viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); - + double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; std::cout << "setting lens perspective : original "<setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); - + viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; std::cout << "setting lens perspective : new "<(socketNumber)); bool masterKilled = false; - + DataConverter scratchPad(1024); while( !viewer.done() && !masterKilled ) { osg::Timer_t startTick = osg::Timer::instance()->tick(); - + viewer.advance(); // special handling for working as a cluster. @@ -563,12 +564,12 @@ int main( int argc, char **argv ) { case(MASTER): { - + // take camera zero as the guide. osg::Matrix modelview(viewer.getCamera()->getViewMatrix()); - + cp->setPacket(modelview,viewer.getFrameStamp()); - + cp->readEventQueue(viewer); scratchPad.reset(); @@ -578,11 +579,11 @@ int main( int argc, char **argv ) scratchPad.read(*cp); bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes); - + std::cout << "bc.sync()"<writeEventQueue(viewer); - if (cp->getMasterKilled()) + if (cp->getMasterKilled()) { std::cout << "Received master killed."<tick(); - + osg::notify(osg::INFO)<<"Time to do cluster sync "<delta_m(startTick,endTick)<getModelView(modelview,camera_offset); - + viewer.getCamera()->setViewMatrix(modelview); } // fire off the cull and draw traversals of the scene. if(!masterKilled) viewer.renderingTraversals(); - + } // 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 ) { // need to broadcast my death. cp->setPacket(osg::Matrix::identity(),viewer.getFrameStamp()); - cp->setMasterKilled(true); + cp->setMasterKilled(true); scratchPad.reset(); scratchPad.write(*cp); diff --git a/include/osgGA/CameraManipulator b/include/osgGA/CameraManipulator index 761dbd09ef9..74092a83396 100644 --- a/include/osgGA/CameraManipulator +++ b/include/osgGA/CameraManipulator @@ -87,7 +87,7 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/ virtual osg::Matrixd getInverseMatrix() const = 0; - /** update the camera for the current frame, typically called by the viewer classes. + /** update the camera for the current frame, typically called by the viewer classes. Default implementation simply set the camera view matrix. */ virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); } @@ -163,6 +163,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler */ virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {} + /** Handle event. Override the handle(..) method in your event handlers to respond to events. */ + virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); } + /** Handle events, return true if handled, false otherwise. */ virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); diff --git a/include/osgGA/Device b/include/osgGA/Device index d7cfc4df72a..4f364ead64b 100644 --- a/include/osgGA/Device +++ b/include/osgGA/Device @@ -29,16 +29,16 @@ class OSGGA_EXPORT Device : public osg::Object RECEIVE_EVENTS = 1, SEND_EVENTS = 2 } Capabilities; - + Device(); Device(const Device& es, const osg::CopyOp& copyop); META_Object(osgGA,Device); - + int getCapabilities() const { return _capabilities; } - + virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; } - virtual void sendEvent(const GUIEventAdapter& ea); + virtual void sendEvent(const Event& ea); virtual void sendEvents(const EventQueue::Events& events); void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } @@ -47,17 +47,17 @@ class OSGGA_EXPORT Device : public osg::Object protected: void setCapabilities(int capabilities) { _capabilities = capabilities; } - + virtual ~Device(); /** Prevent unwanted copy operator.*/ Device& operator = (const Device&) { return *this; } osg::ref_ptr _eventQueue; - - private: + + private: int _capabilities; - + }; } diff --git a/include/osgGA/Event b/include/osgGA/Event new file mode 100644 index 00000000000..06ad8c2cd1d --- /dev/null +++ b/include/osgGA/Event @@ -0,0 +1,52 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGGA_EVENT +#define OSGGA_EVENT 1 + +#include +#include + +namespace osgGA { + +// forward declare +class GUIEventAdapter; + +/** Base Event class.*/ +class OSGGA_EXPORT Event : public osg::Object +{ +public: + Event(); + + Event(const Event& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgGA, Event); + + virtual GUIEventAdapter* asGUIEventAdapter() { return 0; } + virtual const GUIEventAdapter* asGUIEventAdapter() const { return 0; } + + /** set time in seconds of event. */ + void setTime(double time) { _time = time; } + + /** get time in seconds of event. */ + double getTime() const { return _time; } + +protected: + virtual ~Event() {} + + double _time; +}; + +} + +#endif diff --git a/include/osgGA/EventHandler b/include/osgGA/EventHandler new file mode 100644 index 00000000000..956b8876659 --- /dev/null +++ b/include/osgGA/EventHandler @@ -0,0 +1,63 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGGA_EVENTHANDLER +#define OSGGA_EVENTHANDLER 1 + +#include + +#include +#include +#include + +#include +#include +#include + + +namespace osgGA{ + +/** +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) +*/ + +class OSGGA_EXPORT EventHandler : public osg::NodeCallback, public osg::Drawable::EventCallback +{ +public: + + EventHandler() {} + EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + osg::NodeCallback(eh, copyop), + osg::Drawable::EventCallback(eh, copyop) {} + + META_Object(osgGA, EventHandler); + + /** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */ + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); + + /** Event traversal drawable callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */ + virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable); + + /** Handle event. Override the handle(..) method in your event handlers to respond to events. */ + virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv); + + /** Get the user interface usage of this event handler, i.e. keyboard and mouse bindings.*/ + virtual void getUsage(osg::ApplicationUsage&) const {} + +protected: + +}; + +} + +#endif diff --git a/include/osgGA/EventQueue b/include/osgGA/EventQueue index 4edeaeb134c..2906788fcc0 100644 --- a/include/osgGA/EventQueue +++ b/include/osgGA/EventQueue @@ -33,14 +33,14 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS); - typedef std::list< osg::ref_ptr > Events; + typedef std::list< osg::ref_ptr > Events; bool empty() const { OpenThreads::ScopedLock lock(_eventQueueMutex); return _eventQueue.empty(); } - + /** Set events.*/ void setEvents(Events& events); @@ -57,7 +57,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced void appendEvents(Events& events); /** Add an event to the end of the event queue.*/ - void addEvent(GUIEventAdapter* event); + void addEvent(Event* event); /** 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 /** Set the graphics context associated with this event queue.*/ void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); } - + osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); } const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); } diff --git a/include/osgGA/EventVisitor b/include/osgGA/EventVisitor index 83cfc7c56f0..e83008b2a33 100644 --- a/include/osgGA/EventVisitor +++ b/include/osgGA/EventVisitor @@ -51,16 +51,12 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; } - - typedef std::list< osg::ref_ptr > EventList; - - void addEvent(GUIEventAdapter* event); - void removeEvent(GUIEventAdapter* event); + void addEvent(Event* event); + void removeEvent(Event* event); void setEventHandled(bool handled) { _handled = handled; } bool getEventHandled() const { return _handled; } - void setEvents(const EventQueue::Events& events) { _events = events; } EventQueue::Events& getEvents() { return _events; } const EventQueue::Events& getEvents() const { return _events; } @@ -137,7 +133,6 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor bool _handled; EventQueue::Events _events; - }; } diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index 08620ee34cc..aa7689c880b 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -11,13 +11,14 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSGGA_EVENT -#define OSGGA_EVENT 1 +#ifndef OSGGA_GUIEVENTADAPTER +#define OSGGA_GUIEVENTADAPTER 1 #include #include #include -#include + +#include namespace osgGA{ @@ -77,7 +78,7 @@ struct PointerData : public osg::Referenced /** Event class for storing Keyboard, mouse and window events. */ -class OSGGA_EXPORT GUIEventAdapter : public osg::Object +class OSGGA_EXPORT GUIEventAdapter : public Event { public: @@ -448,6 +449,9 @@ public: META_Object(osgGA, GUIEventAdapter); + virtual GUIEventAdapter* asGUIEventAdapter() { return this; } + virtual const GUIEventAdapter* asGUIEventAdapter() const { return this; } + /** Get the accumulated event state singleton. * Typically all EventQueue will share this single GUIEventAdapter object for tracking @@ -467,12 +471,6 @@ public: /** get the event type. */ virtual EventType getEventType() const { return _eventType; } - /** set time in seconds of event. */ - void setTime(double time) { _time = time; } - - /** get time in seconds of event. */ - double getTime() const { return _time; } - /** deprecated function for getting time of event. */ double time() const { return _time; } @@ -709,7 +707,6 @@ public: mutable bool _handled; EventType _eventType; - double _time; osg::observer_ptr _context; int _windowX; diff --git a/include/osgGA/GUIEventHandler b/include/osgGA/GUIEventHandler index 38d589a2840..3d66db9e374 100644 --- a/include/osgGA/GUIEventHandler +++ b/include/osgGA/GUIEventHandler @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -47,27 +47,30 @@ This request is made via the GUIActionAdapter class. */ -class OSGGA_EXPORT GUIEventHandler : public osg::NodeCallback, public osg::Drawable::EventCallback +class OSGGA_EXPORT GUIEventHandler : public EventHandler { public: +#if 1 + GUIEventHandler() {} + GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + EventHandler(eh, copyop) {} +#else GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {} - GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop): - osg::NodeCallback(eh, copyop), - osg::Drawable::EventCallback(eh, copyop), + GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + EventHandler(eh, copyop) _ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {} +#endif META_Object(osgGA,GUIEventHandler); - /** Event traversal node callback method.*/ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - - /** Event traversal drawable callback method.*/ - virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable); + /** Handle event. Override the handle(..) method in your event handlers to respond to events. */ + virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv); /** Handle events, return true if handled, false otherwise. */ virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); } +#if 0 /** Convenience method that only passes on to the handle(,,,) method events that either haven't been * handled yet, or have been handled but haven't be set to be ignored by the IgnoreHandledEventsMask. * Note, this method is an inline method, and not appropriate for users to override, override the handle(,,,) @@ -86,10 +89,11 @@ public: return false; } } - +#endif /** Deprecated, Handle events, return true if handled, false otherwise. */ virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; } +#if 0 /** Convenience method that only passes on to the handle(,) method events that either haven't been * handled yet, or have been handled but haven't be set to be ignored by the IgnoreHandledEventsMask. * Note, this method is an inline method, and not appropriate for users to override, override the handle(,) @@ -109,9 +113,6 @@ public: } } - /** Get the keyboard and mouse usage of this manipulator.*/ - virtual void getUsage(osg::ApplicationUsage&) const {} - /** Set a mask of osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */ void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; } @@ -120,18 +121,8 @@ public: protected: unsigned int _ignoreHandledEventsMask; - -}; - -#ifdef USE_DEPRECATED_API - // keep for backwards compatibility - class GUIEventHandlerVisitor - { - public: - - void visit(GUIEventHandler&) {} - }; #endif +}; } diff --git a/include/osgPresentation/deprecated/KeyEventHandler b/include/osgPresentation/deprecated/KeyEventHandler index 0aa0cc26d84..dae5e247e13 100644 --- a/include/osgPresentation/deprecated/KeyEventHandler +++ b/include/osgPresentation/deprecated/KeyEventHandler @@ -48,8 +48,6 @@ class OSGPRESENTATION_EXPORT KeyEventHandler : public osgGA::GUIEventHandler virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); - virtual void accept(osgGA::GUIEventHandlerVisitor& v); - virtual void getUsage(osg::ApplicationUsage& usage) const; void doOperation(); diff --git a/include/osgPresentation/deprecated/PickEventHandler b/include/osgPresentation/deprecated/PickEventHandler index 329d7955c8d..6f6a31902e8 100644 --- a/include/osgPresentation/deprecated/PickEventHandler +++ b/include/osgPresentation/deprecated/PickEventHandler @@ -45,8 +45,6 @@ class OSGPRESENTATION_EXPORT PickEventHandler : public osgGA::GUIEventHandler virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); - virtual void accept(osgGA::GUIEventHandlerVisitor& v); - virtual void getUsage(osg::ApplicationUsage& usage) const; void doOperation(); diff --git a/include/osgPresentation/deprecated/SlideEventHandler b/include/osgPresentation/deprecated/SlideEventHandler index 09801aee103..41499bf1256 100644 --- a/include/osgPresentation/deprecated/SlideEventHandler +++ b/include/osgPresentation/deprecated/SlideEventHandler @@ -254,11 +254,6 @@ public: void set(osg::Node* model); - virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); } - - /** Event traversal node callback method.*/ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); virtual void getUsage(osg::ApplicationUsage& usage) const; diff --git a/include/osgViewer/View b/include/osgViewer/View index a2955ed34f2..d73f5a9ae91 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -43,10 +43,10 @@ class OSGVIEWER_EXPORT ViewConfig : public osg::Object ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {} META_Object(osgViewer,ViewConfig); - + /** configure method that is overridden by Config subclasses.*/ virtual void configure(osgViewer::View& /*view*/) const {} - + /** convinience method for getting the relavent display settings to use.*/ virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const; }; @@ -129,7 +129,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Get the const View's image pager.*/ const osgDB::ImagePager* getImagePager() const; - + /** Add a Device. * The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/ void addDevice(osgGA::Device* eventSource); @@ -167,13 +167,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter void home(); - typedef std::list< osg::ref_ptr > EventHandlers; + typedef std::list< osg::ref_ptr > EventHandlers; /** Add an EventHandler that adds handling of events to the View.*/ - void addEventHandler(osgGA::GUIEventHandler* eventHandler); + void addEventHandler(osgGA::EventHandler* eventHandler); /** Remove an EventHandler from View.*/ - void removeEventHandler(osgGA::GUIEventHandler* eventHandler); + void removeEventHandler(osgGA::EventHandler* eventHandler); /** Get the View's list of EventHandlers.*/ EventHandlers& getEventHandlers() { return _eventHandlers; } @@ -216,14 +216,14 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/ float getFusionDistanceValue() const { return _fusionDistanceValue; } - + /** Apply a viewer configuration to set up Cameras and Windowing. */ void apply(ViewConfig* config); - + ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); } const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); } - - + + /** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */ void setUpViewAcrossAllScreens(); @@ -242,7 +242,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** deprecated. use view.apply(new osgViewer::WoWVxDisplay(type (20 to 42), screenNum). */ void setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C); - + /** Convenience method for setting up depth partitioning on the specified camera.*/ bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0); @@ -254,7 +254,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Return true if this view contains a specified camera.*/ bool containsCamera(const osg::Camera* camera) const; - + /** deprecated. */ const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const; @@ -264,14 +264,14 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** deprecated. */ bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); - + /** Compute intersections of a ray, starting the current mouse position, through the specified camera. */ bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); /** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */ bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); - + /** Compute intersections of a ray through the specified camera. */ bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); @@ -284,7 +284,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter public: - + osg::Texture* createDistortionTexture(int width, int height); osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture); osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone); @@ -300,7 +300,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter osg::ref_ptr _ds; double _eyeScale; }; - + public: @@ -334,7 +334,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter float _fusionDistanceValue; osg::ref_ptr _lastAppliedViewConfig; - + }; } diff --git a/src/osgDB/PropertyInterface.cpp b/src/osgDB/PropertyInterface.cpp index a0342678ff0..5e426cad8e0 100644 --- a/src/osgDB/PropertyInterface.cpp +++ b/src/osgDB/PropertyInterface.cpp @@ -372,7 +372,6 @@ bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object, { if (areTypesCompatible(valueType, sourceType)) { - OSG_NOTICE<<"Calling get"<get(*object, valuePtr); } else @@ -396,7 +395,6 @@ bool PropertyInterface::copyPropertyObjectToObject(osg::Object* object, const st { if (areTypesCompatible(valueType, destinationType)) { - OSG_NOTICE<<"Calling set"<set(*object, const_cast(valuePtr)); } else diff --git a/src/osgGA/CMakeLists.txt b/src/osgGA/CMakeLists.txt index f4932111097..b3fe5baece4 100644 --- a/src/osgGA/CMakeLists.txt +++ b/src/osgGA/CMakeLists.txt @@ -11,6 +11,8 @@ SET(TARGET_H ${HEADER_PATH}/AnimationPathManipulator ${HEADER_PATH}/DriveManipulator ${HEADER_PATH}/Device + ${HEADER_PATH}/Event + ${HEADER_PATH}/EventHandler ${HEADER_PATH}/EventQueue ${HEADER_PATH}/EventVisitor ${HEADER_PATH}/Export @@ -38,6 +40,8 @@ SET(TARGET_SRC AnimationPathManipulator.cpp DriveManipulator.cpp Device.cpp + Event.cpp + EventHandler.cpp EventQueue.cpp EventVisitor.cpp FirstPersonManipulator.cpp diff --git a/src/osgGA/Device.cpp b/src/osgGA/Device.cpp index b4abc0bd9f5..552be331834 100644 --- a/src/osgGA/Device.cpp +++ b/src/osgGA/Device.cpp @@ -28,7 +28,7 @@ Device::Device(const Device& es, const osg::CopyOp& copyop): setEventQueue(new EventQueue); } -void Device::sendEvent(const GUIEventAdapter& /*event*/) +void Device::sendEvent(const Event& /*event*/) { OSG_WARN << "Device::sendEvent not implemented!" << std::endl; } diff --git a/src/osgGA/Event.cpp b/src/osgGA/Event.cpp new file mode 100644 index 00000000000..2e11326e16b --- /dev/null +++ b/src/osgGA/Event.cpp @@ -0,0 +1,25 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + +using namespace osgGA; + +Event::Event(): + _time(0.0) +{} + +Event::Event(const Event& rhs, const osg::CopyOp& copyop): + osg::Object(rhs, copyop), + _time(rhs._time) +{} diff --git a/src/osgGA/EventHandler.cpp b/src/osgGA/EventHandler.cpp new file mode 100644 index 00000000000..ecfc9710344 --- /dev/null +++ b/src/osgGA/EventHandler.cpp @@ -0,0 +1,52 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include + +using namespace osgGA; + +void EventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) +{ + osgGA::EventVisitor* ev = dynamic_cast(nv); + if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) + { + for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); + itr != ev->getEvents().end(); + ++itr) + { + handle(itr->get(), node, nv); + } + } + if (node->getNumChildrenRequiringEventTraversal()>0 || _nestedCallback.valid()) traverse(node,nv); +} + +void EventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable) +{ + osgGA::EventVisitor* ev = dynamic_cast(nv); + if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) + { + for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); + itr != ev->getEvents().end(); + ++itr) + { + handle(itr->get(), drawable, nv); + } + } +} + +bool EventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) +{ + OSG_NOTICE<<"Handle event "< lock(_eventQueueMutex); _eventQueue.push_back(event); @@ -425,7 +425,7 @@ GUIEventAdapter* EventQueue::touchBegan(unsigned int id, GUIEventAdapter::Touch event->addTouchPoint(id, phase, x, y, 0); if(_firstTouchEmulatesMouse) event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); - + addEvent(event); return event; @@ -464,7 +464,7 @@ GUIEventAdapter* EventQueue::touchEnded(unsigned int id, GUIEventAdapter::Touch event->addTouchPoint(id, phase, x, y, tap_count); if(_firstTouchEmulatesMouse) event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); - + addEvent(event); return event; @@ -495,7 +495,7 @@ void EventQueue::frame(double time) GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); event->setEventType(GUIEventAdapter::FRAME); event->setTime(time); - + // OSG_NOTICE<<"frame("<getX()="<getX()<<", event->getY()="<getY()<<", event->getXmin()="<getXmin()<<", event->getYmin()="<getYmin()<<", event->getXmax()="<getXmax()<<", event->getYmax()="<getYmax()<& GUIEventAdapter::getAccumulatedEventState() GUIEventAdapter::GUIEventAdapter(): _handled(false), _eventType(NONE), - _time(0.0), _windowX(0), _windowY(0), _windowWidth(1280), @@ -48,10 +47,9 @@ GUIEventAdapter::GUIEventAdapter(): {} GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop): - osg::Object(rhs,copyop), + osgGA::Event(rhs,copyop), _handled(rhs._handled), _eventType(rhs._eventType), - _time(rhs._time), _context(rhs._context), _windowX(rhs._windowX), _windowY(rhs._windowY), diff --git a/src/osgGA/GUIEventHandler.cpp b/src/osgGA/GUIEventHandler.cpp index 25cd231ba02..04a845aa1ce 100644 --- a/src/osgGA/GUIEventHandler.cpp +++ b/src/osgGA/GUIEventHandler.cpp @@ -16,33 +16,21 @@ using namespace osgGA; - -void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) -{ - osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) - { - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); - itr != ev->getEvents().end(); - ++itr) - { - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); - } - } - if (node->getNumChildrenRequiringEventTraversal()>0 || _nestedCallback.valid()) traverse(node,nv); -} - -void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable) +// adapt EventHandler usage to old style GUIEventHandler usage +bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) + osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter(); + if (ea && ev && ev->getActionAdapter()) { - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); - itr != ev->getEvents().end(); - ++itr) - { - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), drawable, nv); - } +#if 1 + bool handled = handle(*ea, *(ev->getActionAdapter()), object, nv); + if (handled) ea->setHandled(true); + return handled; +#else + return handleWithCheckAgainstIgnoreHandledEventsMask(*ea, *(ev->getActionAdapter()), object, nv); +#endif } + return false; } diff --git a/src/osgManipulator/Dragger.cpp b/src/osgManipulator/Dragger.cpp index a397159bab9..7ac2092353a 100644 --- a/src/osgManipulator/Dragger.cpp +++ b/src/osgManipulator/Dragger.cpp @@ -305,8 +305,8 @@ void Dragger::traverse(osg::NodeVisitor& nv) itr != ev->getEvents().end(); ++itr) { - osgGA::GUIEventAdapter* ea = itr->get(); - if (handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true); + osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter(); + if (ea && handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true); } } return; diff --git a/src/osgPresentation/Cursor.cpp b/src/osgPresentation/Cursor.cpp index f73545a6992..733f9438c6e 100644 --- a/src/osgPresentation/Cursor.cpp +++ b/src/osgPresentation/Cursor.cpp @@ -187,7 +187,9 @@ void Cursor::traverse(osg::NodeVisitor& nv) itr != events.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (!event) continue; + switch(event->getEventType()) { case(osgGA::GUIEventAdapter::PUSH): diff --git a/src/osgPresentation/deprecated/KeyEventHandler.cpp b/src/osgPresentation/deprecated/KeyEventHandler.cpp index 6118276e022..24cb90923c4 100644 --- a/src/osgPresentation/deprecated/KeyEventHandler.cpp +++ b/src/osgPresentation/deprecated/KeyEventHandler.cpp @@ -65,12 +65,6 @@ bool KeyEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAd return false; } - -void KeyEventHandler::accept(osgGA::GUIEventHandlerVisitor& v) -{ - v.visit(*this); -} - void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const { } diff --git a/src/osgPresentation/deprecated/PickEventHandler.cpp b/src/osgPresentation/deprecated/PickEventHandler.cpp index 749e6c29edf..3105ff53e16 100644 --- a/src/osgPresentation/deprecated/PickEventHandler.cpp +++ b/src/osgPresentation/deprecated/PickEventHandler.cpp @@ -131,12 +131,6 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA return false; } - -void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v) -{ - v.visit(*this); -} - void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const { } diff --git a/src/osgPresentation/deprecated/SlideEventHandler.cpp b/src/osgPresentation/deprecated/SlideEventHandler.cpp index 51161630742..c5dd145b600 100644 --- a/src/osgPresentation/deprecated/SlideEventHandler.cpp +++ b/src/osgPresentation/deprecated/SlideEventHandler.cpp @@ -967,25 +967,6 @@ double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const return _timePerSlide; } -void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) -{ - osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev) - { - if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv); - - if (ev->getActionAdapter() && !ev->getEvents().empty()) - { - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); - itr != ev->getEvents().end(); - ++itr) - { - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); - } - } - } -} - bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { diff --git a/src/osgPresentation/deprecated/Timeout.cpp b/src/osgPresentation/deprecated/Timeout.cpp index a0e11685393..c9d50220fc1 100644 --- a/src/osgPresentation/deprecated/Timeout.cpp +++ b/src/osgPresentation/deprecated/Timeout.cpp @@ -257,7 +257,8 @@ void Timeout::traverse(osg::NodeVisitor& nv) itr != events.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (!event) continue; bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP; diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index b43b625a6e2..1afdcf9ed51 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -916,7 +916,7 @@ void CompositeViewer::reprojectPointerData(osgGA::GUIEventAdapter& source_event, struct SortEvents { - bool operator() (const osg::ref_ptr& lhs,const osg::ref_ptr& rhs) const + bool operator() (const osg::ref_ptr& lhs,const osg::ref_ptr& rhs) const { return lhs->getTime() < rhs->getTime(); } @@ -961,7 +961,8 @@ void CompositeViewer::eventTraversal() itr != gw_events.end(); ++itr) { - (*itr)->setGraphicsContext(gw); + osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter(); + if (ea) ea->setGraphicsContext(gw); } all_events.insert(all_events.end(), gw_events.begin(), gw_events.end()); @@ -976,7 +977,8 @@ void CompositeViewer::eventTraversal() itr != all_events.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (!event) continue; switch(event->getEventType()) { @@ -1059,7 +1061,9 @@ void CompositeViewer::eventTraversal() itr != all_events.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (!event) continue; + switch(event->getEventType()) { case(osgGA::GUIEventAdapter::CLOSE_WINDOW): @@ -1118,7 +1122,8 @@ void CompositeViewer::eventTraversal() itr != veitr->second.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); + osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter(); + if (!event) continue; switch(event->getEventType()) { case(osgGA::GUIEventAdapter::KEYUP): @@ -1148,16 +1153,15 @@ void CompositeViewer::eventTraversal() ++veitr) { View* view = veitr->first; + _eventVisitor->setActionAdapter(view); if (view && view->getSceneData()) { - _eventVisitor->setActionAdapter(view); - for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); itr != veitr->second.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); + osgGA::Event* event = itr->get(); _eventVisitor->reset(); _eventVisitor->addEvent( event ); @@ -1205,18 +1209,18 @@ void CompositeViewer::eventTraversal() ++veitr) { View* view = veitr->first; + _eventVisitor->setActionAdapter(view); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); itr != veitr->second.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); - + osgGA::Event* event = itr->get(); for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin(); hitr != view->getEventHandlers().end(); ++hitr) { - (*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view, 0, _eventVisitor.get()); + (*hitr)->handle( event, view, _eventVisitor.get()); } } } @@ -1226,16 +1230,16 @@ void CompositeViewer::eventTraversal() ++veitr) { View* view = veitr->first; + _eventVisitor->setActionAdapter(view); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); itr != veitr->second.end(); ++itr) { - osgGA::GUIEventAdapter* event = itr->get(); - + osgGA::Event* event = itr->get(); if (view->getCameraManipulator()) { - view->getCameraManipulator()->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view); + view->getCameraManipulator()->handle( event, view, _eventVisitor.get()); } } } diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 752b09c2d6b..fe3607d3bf3 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -270,7 +270,7 @@ void View::init() void View::setStartTick(osg::Timer_t tick) { _startTick = tick; - + for(Devices::iterator eitr = _eventSources.begin(); eitr != _eventSources.end(); ++eitr) @@ -395,7 +395,7 @@ void View::home() } -void View::addEventHandler(osgGA::GUIEventHandler* eventHandler) +void View::addEventHandler(osgGA::EventHandler* eventHandler) { EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler); if (itr == _eventHandlers.end()) @@ -404,7 +404,7 @@ void View::addEventHandler(osgGA::GUIEventHandler* eventHandler) } } -void View::removeEventHandler(osgGA::GUIEventHandler* eventHandler) +void View::removeEventHandler(osgGA::EventHandler* eventHandler) { EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler); if (itr != _eventHandlers.end()) @@ -846,7 +846,7 @@ void View::requestContinuousUpdate(bool flag) void View::requestWarpPointer(float x,float y) { OSG_INFO<<"View::requestWarpPointer("<getCurrentEventState(); const osgViewer::GraphicsWindow* gw = dynamic_cast(eventState->getGraphicsContext()); bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; - + // OSG_NOTICE<<"getCameraContainingPosition("<getViewport(); - + // rescale mouse x,y first to 0 to 1 range double new_x = (x-eventState->getXmin())/(eventState->getXmax()-eventState->getXmin()); double new_y = (y-eventState->getYmin())/(eventState->getYmax()-eventState->getYmin()); - + // flip y if required if (view_invert_y) new_y = 1.0f-new_y; - + // rescale mouse x, y to window dimensions so we can check against master Camera's viewport new_x *= static_cast(_camera->getGraphicsContext()->getTraits()->width); new_y *= static_cast(_camera->getGraphicsContext()->getTraits()->height); - + if (new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) && new_x < (viewport->x()+viewport->width()-1.0+epsilon) && new_y <= (viewport->y()+viewport->height()-1.0+epsilon) ) { @@ -929,7 +929,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo // OSG_NOTICE<<"master camera viewport not matched."<getViewMatrix() * getCamera()->getProjectionMatrix(); // convert to non dimensional @@ -990,9 +990,9 @@ bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector { float local_x, local_y; const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); - + OSG_INFO<<"computeIntersections("<