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.
This commit is contained in:
Robert Osfield 2013-10-25 14:54:15 +00:00
parent 2025c511f0
commit 4a660f6266
37 changed files with 511 additions and 397 deletions

View File

@ -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 terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,. * The full license is in LICENSE.txt file included with this distribution,.
* *
* This software is distributed in the hope that it will be useful, * This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * include LICENSE.txt for more details.
*/ */
@ -39,9 +39,9 @@
#elif defined(__sgi) #elif defined(__sgi)
#include <unistd.h> #include <unistd.h>
#include <net/soioctl.h> #include <net/soioctl.h>
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
#include <unistd.h> #include <unistd.h>
#elif defined(__sun) #elif defined(__sun)
#include <unistd.h> #include <unistd.h>
#include <sys/sockio.h> #include <sys/sockio.h>
#elif defined (__APPLE__) #elif defined (__APPLE__)
@ -202,7 +202,8 @@ void DataConverter::write(CameraPacket& cameraPacket)
itr != cameraPacket._events.end(); itr != cameraPacket._events.end();
++itr) ++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 ) Receiver::Receiver( void )
{ {
@ -338,7 +339,7 @@ void Receiver::sync( void )
#if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || \ #if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || \
defined(__DragonFly__) defined(__DragonFly__)
socklen_t socklen_t
#else #else
int int
#endif #endif
@ -381,7 +382,7 @@ void Receiver::sync( void )
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// Broadcaster // Broadcaster
// //
Broadcaster::Broadcaster( void ) Broadcaster::Broadcaster( void )
{ {

View File

@ -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 terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,. * The full license is in LICENSE.txt file included with this distribution,.
* *
* This software is distributed in the hope that it will be useful, * This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * include LICENSE.txt for more details.
*/ */
@ -54,11 +54,6 @@ bool PointsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
return false; return false;
} }
void PointsEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const
{ {
usage.addKeyboardMouseBinding("+","Increase point size"); usage.addKeyboardMouseBinding("+","Increase point size");

View File

@ -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 terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,. * The full license is in LICENSE.txt file included with this distribution,.
* *
* This software is distributed in the hope that it will be useful, * This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * include LICENSE.txt for more details.
*/ */
@ -22,25 +22,23 @@ class PointsEventHandler : public osgGA::GUIEventHandler
{ {
public: public:
PointsEventHandler(); PointsEventHandler();
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
void getUsage(osg::ApplicationUsage& usage) const; void getUsage(osg::ApplicationUsage& usage) const;
void setStateSet(osg::StateSet* stateset) { _stateset=stateset; } void setStateSet(osg::StateSet* stateset) { _stateset=stateset; }
osg::StateSet* getStateSet() { return _stateset.get(); } osg::StateSet* getStateSet() { return _stateset.get(); }
const osg::StateSet* getStateSet() const { return _stateset.get(); } const osg::StateSet* getStateSet() const { return _stateset.get(); }
void setPointSize(float psize); void setPointSize(float psize);
float getPointSize() const; float getPointSize() const;
void changePointSize(float delta); void changePointSize(float delta);
void changePointAttenuation(float scale); void changePointAttenuation(float scale);
osg::ref_ptr<osg::StateSet> _stateset; osg::ref_ptr<osg::StateSet> _stateset;

View File

@ -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 terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,. * The full license is in LICENSE.txt file included with this distribution,.
* *
* This software is distributed in the hope that it will be useful, * This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * include LICENSE.txt for more details.
*/ */
@ -28,13 +28,13 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
case(osgGA::GUIEventAdapter::KEYUP): case(osgGA::GUIEventAdapter::KEYUP):
{ {
osg::notify(osg::INFO)<<"ShowEventHandler KEYUP "<<(int)ea.getKey()<<std::endl; osg::notify(osg::INFO)<<"ShowEventHandler KEYUP "<<(int)ea.getKey()<<std::endl;
if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 && if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 &&
ea.getKey()<=osgGA::GUIEventAdapter::KEY_F8) ea.getKey()<=osgGA::GUIEventAdapter::KEY_F8)
{ {
unsigned int child = ea.getKey()-osgGA::GUIEventAdapter::KEY_F1; unsigned int child = ea.getKey()-osgGA::GUIEventAdapter::KEY_F1;
osg::notify(osg::INFO)<<" Select "<<child<<std::endl; osg::notify(osg::INFO)<<" Select "<<child<<std::endl;
osg::Switch* showSwitch = dynamic_cast<osg::Switch*>(object); osg::Switch* showSwitch = dynamic_cast<osg::Switch*>(object);
if (showSwitch) if (showSwitch)
{ {
if (child<showSwitch->getNumChildren()) if (child<showSwitch->getNumChildren())
{ {
@ -52,12 +52,6 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
return false; return false;
} }
void ShowEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }

View File

@ -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 terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,. * The full license is in LICENSE.txt file included with this distribution,.
* *
* This software is distributed in the hope that it will be useful, * This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * include LICENSE.txt for more details.
*/ */
@ -28,11 +28,9 @@ class ShowEventHandler : public osgGA::GUIEventHandler
ShowEventHandler(); ShowEventHandler();
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); 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; virtual void getUsage(osg::ApplicationUsage& usage) const;
}; };
} }

View File

@ -1,14 +1,14 @@
/* -*-c++-*- /* -*-c++-*-
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
* *
* This library is open source and may be redistributed and/or modified under * 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 * 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 * (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website. * included with this distribution, and on the openscenegraph.org website.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * OpenSceneGraph Public License for more details.
*/ */
@ -84,7 +84,7 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
_scratchNose->setLoop(1); // one time _scratchNose->setLoop(1); // one time
// add the main loop at priority 0 at time 0. // add the main loop at priority 0 at time 0.
osgAnimation::Timeline* tml = _manager->getTimeline(); osgAnimation::Timeline* tml = _manager->getTimeline();
tml->play(); tml->play();
tml->addActionAt(0.0, _mainLoop.get(), 0); tml->addActionAt(0.0, _mainLoop.get(), 0);
@ -139,21 +139,12 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
} }
_releaseKey = false; _releaseKey = false;
} }
traverse(node, nv);
} }
else else
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::GUIEventHandler::operator()(node, 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);
} }
}; };
@ -168,7 +159,7 @@ int main (int argc, char* argv[])
osgViewer::Viewer viewer(psr); osgViewer::Viewer viewer(psr);
std::string file = "nathan.osg"; std::string file = "nathan.osg";
if(argc >= 2) if(argc >= 2)
file = psr[1]; file = psr[1];
// replace the manager // replace the manager
@ -178,7 +169,7 @@ int main (int argc, char* argv[])
return 1; return 1;
} }
osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback()); osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback());
if(!animationManager) if(!animationManager)
{ {
osg::notify(osg::FATAL) << "Did not find AnimationManagerBase updateCallback needed to animate elements" << std::endl; osg::notify(osg::FATAL) << "Did not find AnimationManagerBase updateCallback needed to animate elements" << std::endl;
return 1; return 1;
@ -186,22 +177,22 @@ int main (int argc, char* argv[])
osg::ref_ptr<osgAnimation::TimelineAnimationManager> tl = new osgAnimation::TimelineAnimationManager(*animationManager); osg::ref_ptr<osgAnimation::TimelineAnimationManager> tl = new osgAnimation::TimelineAnimationManager(*animationManager);
root->setUpdateCallback(tl.get()); root->setUpdateCallback(tl.get());
ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get()); ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get());
root->setEventCallback(callback); root->setEventCallback(callback);
root->getUpdateCallback()->addNestedCallback(callback); root->getUpdateCallback()->addNestedCallback(callback);
// add the state manipulator // add the state manipulator
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
// add the thread model handler // add the thread model handler
viewer.addEventHandler(new osgViewer::ThreadingHandler); viewer.addEventHandler(new osgViewer::ThreadingHandler);
// add the window size toggle handler // add the window size toggle handler
viewer.addEventHandler(new osgViewer::WindowSizeHandler); viewer.addEventHandler(new osgViewer::WindowSizeHandler);
// add the stats handler // add the stats handler
viewer.addEventHandler(new osgViewer::StatsHandler); viewer.addEventHandler(new osgViewer::StatsHandler);

View File

@ -48,13 +48,13 @@ const unsigned int MAX_NUM_EVENTS = 10;
const unsigned int SWAP_BYTES_COMPARE = 0x12345678; const unsigned int SWAP_BYTES_COMPARE = 0x12345678;
class CameraPacket { class CameraPacket {
public: public:
CameraPacket():_masterKilled(false) CameraPacket():_masterKilled(false)
{ {
_byte_order = SWAP_BYTES_COMPARE; _byte_order = SWAP_BYTES_COMPARE;
} }
void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp) void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp)
{ {
_matrix = matrix; _matrix = matrix;
@ -63,20 +63,20 @@ class CameraPacket {
_frameStamp = *frameStamp; _frameStamp = *frameStamp;
} }
} }
void getModelView(osg::Matrix& matrix,float angle_offset=0.0f) 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); matrix = _matrix * osg::Matrix::rotate(osg::DegreesToRadians(angle_offset),0.0f,1.0f,0.0f);
} }
void readEventQueue(osgViewer::Viewer& viewer); void readEventQueue(osgViewer::Viewer& viewer);
void writeEventQueue(osgViewer::Viewer& viewer); void writeEventQueue(osgViewer::Viewer& viewer);
void setMasterKilled(const bool flag) { _masterKilled = flag; } void setMasterKilled(const bool flag) { _masterKilled = flag; }
const bool getMasterKilled() const { return _masterKilled; } const bool getMasterKilled() const { return _masterKilled; }
unsigned int _byte_order; unsigned int _byte_order;
bool _masterKilled; bool _masterKilled;
osg::Matrix _matrix; osg::Matrix _matrix;
@ -84,11 +84,11 @@ class CameraPacket {
// note don't use a ref_ptr as used elsewhere for FrameStamp // note don't use a ref_ptr as used elsewhere for FrameStamp
// since we don't want to copy the pointer - but the memory. // since we don't want to copy the pointer - but the memory.
// FrameStamp doesn't have a private destructor to allow // 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; osg::FrameStamp _frameStamp;
osgGA::EventQueue::Events _events; osgGA::EventQueue::Events _events;
}; };
class DataConverter class DataConverter
@ -112,7 +112,7 @@ class DataConverter
bool _swapBytes; bool _swapBytes;
char* _currentPtr; char* _currentPtr;
void reset() void reset()
{ {
_currentPtr = _startPtr; _currentPtr = _startPtr;
@ -122,22 +122,22 @@ class DataConverter
{ {
if (_currentPtr+1>=_endPtr) return; if (_currentPtr+1>=_endPtr) return;
*(_currentPtr++) = *(ptr); *(_currentPtr++) = *(ptr);
} }
inline void read1(char* ptr) inline void read1(char* ptr)
{ {
if (_currentPtr+1>=_endPtr) return; if (_currentPtr+1>=_endPtr) return;
*(ptr) = *(_currentPtr++); *(ptr) = *(_currentPtr++);
} }
inline void write2(char* ptr) inline void write2(char* ptr)
{ {
if (_currentPtr+2>=_endPtr) return; if (_currentPtr+2>=_endPtr) return;
*(_currentPtr++) = *(ptr++); *(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr); *(_currentPtr++) = *(ptr);
} }
inline void read2(char* ptr) inline void read2(char* ptr)
@ -146,13 +146,13 @@ class DataConverter
if (_swapBytes) if (_swapBytes)
{ {
*(ptr+1) = *(_currentPtr++); *(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++); *(ptr) = *(_currentPtr++);
} }
else else
{ {
*(ptr++) = *(_currentPtr++); *(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++); *(ptr) = *(_currentPtr++);
} }
} }
@ -160,10 +160,10 @@ class DataConverter
{ {
if (_currentPtr+4>=_endPtr) return; 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) inline void read4(char* ptr)
@ -172,17 +172,17 @@ class DataConverter
if (_swapBytes) if (_swapBytes)
{ {
*(ptr+3) = *(_currentPtr++); *(ptr+3) = *(_currentPtr++);
*(ptr+2) = *(_currentPtr++); *(ptr+2) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++); *(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++); *(ptr) = *(_currentPtr++);
} }
else 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; 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) inline void read8(char* ptr)
@ -208,27 +208,27 @@ class DataConverter
if (_swapBytes) if (_swapBytes)
{ {
*(ptr+7) = *(_currentPtr++); *(ptr+7) = *(_currentPtr++);
*(ptr+6) = *(_currentPtr++); *(ptr+6) = *(_currentPtr++);
*(ptr+5) = *(_currentPtr++); *(ptr+5) = *(_currentPtr++);
*(ptr+4) = *(_currentPtr++); *(ptr+4) = *(_currentPtr++);
*(ptr+3) = *(_currentPtr++); *(ptr+3) = *(_currentPtr++);
*(ptr+2) = *(_currentPtr++); *(ptr+2) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++); *(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++); *(ptr) = *(_currentPtr++);
} }
else 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.setModKeyMask(readUInt());
event.setTime(readDouble()); event.setTime(readDouble());
} }
void write(CameraPacket& cameraPacket) void write(CameraPacket& cameraPacket)
{ {
writeUInt(cameraPacket._byte_order); writeUInt(cameraPacket._byte_order);
writeUInt(cameraPacket._masterKilled); writeUInt(cameraPacket._masterKilled);
write(cameraPacket._matrix); write(cameraPacket._matrix);
write(cameraPacket._frameStamp); write(cameraPacket._frameStamp);
writeUInt(cameraPacket._events.size()); writeUInt(cameraPacket._events.size());
for(osgGA::EventQueue::Events::iterator itr = cameraPacket._events.begin(); for(osgGA::EventQueue::Events::iterator itr = cameraPacket._events.begin();
itr != cameraPacket._events.end(); itr != cameraPacket._events.end();
++itr) ++itr)
{ {
write(*(*itr)); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (event) write(*event);
} }
} }
@ -387,12 +388,12 @@ class DataConverter
{ {
_swapBytes = !_swapBytes; _swapBytes = !_swapBytes;
} }
cameraPacket._masterKilled = readUInt()!=0; cameraPacket._masterKilled = readUInt()!=0;
read(cameraPacket._matrix); read(cameraPacket._matrix);
read(cameraPacket._frameStamp); read(cameraPacket._frameStamp);
cameraPacket._events.clear(); cameraPacket._events.clear();
unsigned int numEvents = readUInt(); unsigned int numEvents = readUInt();
for(unsigned int i=0;i<numEvents;++i) for(unsigned int i=0;i<numEvents;++i)
@ -409,7 +410,7 @@ void CameraPacket::readEventQueue(osgViewer::Viewer& viewer)
_events.clear(); _events.clear();
osgViewer::ViewerBase::Contexts contexts; osgViewer::ViewerBase::Contexts contexts;
viewer.getContexts(contexts); viewer.getContexts(contexts);
for(osgViewer::ViewerBase::Contexts::iterator citr =contexts.begin(); citr != contexts.end(); ++citr) for(osgViewer::ViewerBase::Contexts::iterator citr =contexts.begin(); citr != contexts.end(); ++citr)
{ {
@ -423,7 +424,7 @@ void CameraPacket::readEventQueue(osgViewer::Viewer& viewer)
} }
_events.insert(_events.end(), gw_events.begin(), gw_events.end()); _events.insert(_events.end(), gw_events.begin(), gw_events.end());
} }
viewer.getEventQueue()->copyEvents(_events); viewer.getEventQueue()->copyEvents(_events);
osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl; osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl;
@ -449,7 +450,7 @@ int main( int argc, char **argv )
{ {
// use an ArgumentParser object to manage the program arguments. // use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv); osg::ArgumentParser arguments(&argc,argv);
// set up the usage document, in case we need to print out how to use this program. // set up the usage document, in case we need to print out how to use this program.
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to approach implementation of clustering."); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to approach implementation of clustering.");
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
@ -459,7 +460,7 @@ int main( int argc, char **argv )
arguments.getApplicationUsage()->addCommandLineOption("-n <int>","Socket number to transmit packets"); arguments.getApplicationUsage()->addCommandLineOption("-n <int>","Socket number to transmit packets");
arguments.getApplicationUsage()->addCommandLineOption("-f <float>","Field of view of camera"); arguments.getApplicationUsage()->addCommandLineOption("-f <float>","Field of view of camera");
arguments.getApplicationUsage()->addCommandLineOption("-o <float>","Offset angle of camera"); arguments.getApplicationUsage()->addCommandLineOption("-o <float>","Offset angle of camera");
// construct the viewer. // construct the viewer.
osgViewer::Viewer viewer; osgViewer::Viewer viewer;
@ -468,12 +469,12 @@ int main( int argc, char **argv )
ViewerMode viewerMode = STAND_ALONE; ViewerMode viewerMode = STAND_ALONE;
while (arguments.read("-m")) viewerMode = MASTER; while (arguments.read("-m")) viewerMode = MASTER;
while (arguments.read("-s")) viewerMode = SLAVE; while (arguments.read("-s")) viewerMode = SLAVE;
int socketNumber=8100; int socketNumber=8100;
while (arguments.read("-n",socketNumber)) ; while (arguments.read("-n",socketNumber)) ;
float camera_fov=-1.0f; 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); arguments.writeErrorMessages(std::cout);
return 1; return 1;
} }
if (arguments.argc()<=1) if (arguments.argc()<=1)
{ {
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 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; double fovy, aspectRatio, zNear, zFar;
viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0;
std::cout << "setting lens perspective : original "<<original_fov<<" "<<fovy<<std::endl; std::cout << "setting lens perspective : original "<<original_fov<<" "<<fovy<<std::endl;
fovy = atan(tan(osg::DegreesToRadians(camera_fov)*0.5)/aspectRatio)*2.0; fovy = atan(tan(osg::DegreesToRadians(camera_fov)*0.5)/aspectRatio)*2.0;
viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0;
std::cout << "setting lens perspective : new "<<original_fov<<" "<<fovy<<std::endl; std::cout << "setting lens perspective : new "<<original_fov<<" "<<fovy<<std::endl;
@ -549,13 +550,13 @@ int main( int argc, char **argv )
rc.setPort(static_cast<short int>(socketNumber)); rc.setPort(static_cast<short int>(socketNumber));
bool masterKilled = false; bool masterKilled = false;
DataConverter scratchPad(1024); DataConverter scratchPad(1024);
while( !viewer.done() && !masterKilled ) while( !viewer.done() && !masterKilled )
{ {
osg::Timer_t startTick = osg::Timer::instance()->tick(); osg::Timer_t startTick = osg::Timer::instance()->tick();
viewer.advance(); viewer.advance();
// special handling for working as a cluster. // special handling for working as a cluster.
@ -563,12 +564,12 @@ int main( int argc, char **argv )
{ {
case(MASTER): case(MASTER):
{ {
// take camera zero as the guide. // take camera zero as the guide.
osg::Matrix modelview(viewer.getCamera()->getViewMatrix()); osg::Matrix modelview(viewer.getCamera()->getViewMatrix());
cp->setPacket(modelview,viewer.getFrameStamp()); cp->setPacket(modelview,viewer.getFrameStamp());
cp->readEventQueue(viewer); cp->readEventQueue(viewer);
scratchPad.reset(); scratchPad.reset();
@ -578,11 +579,11 @@ int main( int argc, char **argv )
scratchPad.read(*cp); scratchPad.read(*cp);
bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes); bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
std::cout << "bc.sync()"<<scratchPad._numBytes<<std::endl; std::cout << "bc.sync()"<<scratchPad._numBytes<<std::endl;
bc.sync(); bc.sync();
} }
break; break;
case(SLAVE): case(SLAVE):
@ -591,13 +592,13 @@ int main( int argc, char **argv )
rc.setBuffer(scratchPad._startPtr, scratchPad._numBytes); rc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
rc.sync(); rc.sync();
scratchPad.reset(); scratchPad.reset();
scratchPad.read(*cp); scratchPad.read(*cp);
cp->writeEventQueue(viewer); cp->writeEventQueue(viewer);
if (cp->getMasterKilled()) if (cp->getMasterKilled())
{ {
std::cout << "Received master killed."<<std::endl; std::cout << "Received master killed."<<std::endl;
// break out of while (!done) loop since we've now want to shut down. // break out of while (!done) loop since we've now want to shut down.
@ -609,9 +610,9 @@ int main( int argc, char **argv )
// no need to anything here, just a normal interactive viewer. // no need to anything here, just a normal interactive viewer.
break; break;
} }
osg::Timer_t endTick = osg::Timer::instance()->tick(); osg::Timer_t endTick = osg::Timer::instance()->tick();
osg::notify(osg::INFO)<<"Time to do cluster sync "<<osg::Timer::instance()->delta_m(startTick,endTick)<<std::endl; osg::notify(osg::INFO)<<"Time to do cluster sync "<<osg::Timer::instance()->delta_m(startTick,endTick)<<std::endl;
// update the scene by traversing it with the the update visitor which will // update the scene by traversing it with the the update visitor which will
@ -623,14 +624,14 @@ int main( int argc, char **argv )
{ {
osg::Matrix modelview; osg::Matrix modelview;
cp->getModelView(modelview,camera_offset); cp->getModelView(modelview,camera_offset);
viewer.getCamera()->setViewMatrix(modelview); viewer.getCamera()->setViewMatrix(modelview);
} }
// fire off the cull and draw traversals of the scene. // fire off the cull and draw traversals of the scene.
if(!masterKilled) if(!masterKilled)
viewer.renderingTraversals(); viewer.renderingTraversals();
} }
// if we are master clean up by telling all slaves that we're going down. // 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. // need to broadcast my death.
cp->setPacket(osg::Matrix::identity(),viewer.getFrameStamp()); cp->setPacket(osg::Matrix::identity(),viewer.getFrameStamp());
cp->setMasterKilled(true); cp->setMasterKilled(true);
scratchPad.reset(); scratchPad.reset();
scratchPad.write(*cp); scratchPad.write(*cp);

View File

@ -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.*/ /** 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; 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. */ Default implementation simply set the camera view matrix. */
virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); } 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&) {} 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. */ /** Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);

View File

@ -29,16 +29,16 @@ class OSGGA_EXPORT Device : public osg::Object
RECEIVE_EVENTS = 1, RECEIVE_EVENTS = 1,
SEND_EVENTS = 2 SEND_EVENTS = 2
} Capabilities; } Capabilities;
Device(); Device();
Device(const Device& es, const osg::CopyOp& copyop); Device(const Device& es, const osg::CopyOp& copyop);
META_Object(osgGA,Device); META_Object(osgGA,Device);
int getCapabilities() const { return _capabilities; } int getCapabilities() const { return _capabilities; }
virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; } 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); virtual void sendEvents(const EventQueue::Events& events);
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
@ -47,17 +47,17 @@ class OSGGA_EXPORT Device : public osg::Object
protected: protected:
void setCapabilities(int capabilities) { _capabilities = capabilities; } void setCapabilities(int capabilities) { _capabilities = capabilities; }
virtual ~Device(); virtual ~Device();
/** Prevent unwanted copy operator.*/ /** Prevent unwanted copy operator.*/
Device& operator = (const Device&) { return *this; } Device& operator = (const Device&) { return *this; }
osg::ref_ptr<osgGA::EventQueue> _eventQueue; osg::ref_ptr<osgGA::EventQueue> _eventQueue;
private: private:
int _capabilities; int _capabilities;
}; };
} }

52
include/osgGA/Event Normal file
View File

@ -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 <osgGA/Export>
#include <osg/Object>
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

View File

@ -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 <vector>
#include <osg/NodeCallback>
#include <osg/Drawable>
#include <osg/ApplicationUsage>
#include <osgGA/Export>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter>
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

View File

@ -33,14 +33,14 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS); EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS);
typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events; typedef std::list< osg::ref_ptr<Event> > Events;
bool empty() const bool empty() const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
return _eventQueue.empty(); return _eventQueue.empty();
} }
/** Set events.*/ /** Set events.*/
void setEvents(Events& events); void setEvents(Events& events);
@ -57,7 +57,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
void appendEvents(Events& events); void appendEvents(Events& events);
/** Add an event to the end of the event queue.*/ /** 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 /** 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.*/ /** Set the graphics context associated with this event queue.*/
void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); } void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); } osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); } const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }

View File

@ -51,16 +51,12 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; } const osgGA::GUIActionAdapter* getActionAdapter() const { return _actionAdapter; }
void addEvent(Event* event);
typedef std::list< osg::ref_ptr<GUIEventAdapter> > EventList; void removeEvent(Event* event);
void addEvent(GUIEventAdapter* event);
void removeEvent(GUIEventAdapter* event);
void setEventHandled(bool handled) { _handled = handled; } void setEventHandled(bool handled) { _handled = handled; }
bool getEventHandled() const { return _handled; } bool getEventHandled() const { return _handled; }
void setEvents(const EventQueue::Events& events) { _events = events; } void setEvents(const EventQueue::Events& events) { _events = events; }
EventQueue::Events& getEvents() { return _events; } EventQueue::Events& getEvents() { return _events; }
const EventQueue::Events& getEvents() const { return _events; } const EventQueue::Events& getEvents() const { return _events; }
@ -137,7 +133,6 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
bool _handled; bool _handled;
EventQueue::Events _events; EventQueue::Events _events;
}; };
} }

View File

@ -11,13 +11,14 @@
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
#ifndef OSGGA_EVENT #ifndef OSGGA_GUIEVENTADAPTER
#define OSGGA_EVENT 1 #define OSGGA_GUIEVENTADAPTER 1
#include <osg/Object> #include <osg/Object>
#include <osg/Matrix> #include <osg/Matrix>
#include <osg/GraphicsContext> #include <osg/GraphicsContext>
#include <osgGA/Export>
#include <osgGA/Event>
namespace osgGA{ namespace osgGA{
@ -77,7 +78,7 @@ struct PointerData : public osg::Referenced
/** Event class for storing Keyboard, mouse and window events. /** Event class for storing Keyboard, mouse and window events.
*/ */
class OSGGA_EXPORT GUIEventAdapter : public osg::Object class OSGGA_EXPORT GUIEventAdapter : public Event
{ {
public: public:
@ -448,6 +449,9 @@ public:
META_Object(osgGA, GUIEventAdapter); META_Object(osgGA, GUIEventAdapter);
virtual GUIEventAdapter* asGUIEventAdapter() { return this; }
virtual const GUIEventAdapter* asGUIEventAdapter() const { return this; }
/** Get the accumulated event state singleton. /** Get the accumulated event state singleton.
* Typically all EventQueue will share this single GUIEventAdapter object for tracking * Typically all EventQueue will share this single GUIEventAdapter object for tracking
@ -467,12 +471,6 @@ public:
/** get the event type. */ /** get the event type. */
virtual EventType getEventType() const { return _eventType; } 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. */ /** deprecated function for getting time of event. */
double time() const { return _time; } double time() const { return _time; }
@ -709,7 +707,6 @@ public:
mutable bool _handled; mutable bool _handled;
EventType _eventType; EventType _eventType;
double _time;
osg::observer_ptr<osg::GraphicsContext> _context; osg::observer_ptr<osg::GraphicsContext> _context;
int _windowX; int _windowX;

View File

@ -20,7 +20,7 @@
#include <osg/Drawable> #include <osg/Drawable>
#include <osg/ApplicationUsage> #include <osg/ApplicationUsage>
#include <osgGA/Export> #include <osgGA/EventHandler>
#include <osgGA/GUIEventAdapter> #include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter> #include <osgGA/GUIActionAdapter>
@ -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: 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() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop): GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::NodeCallback(eh, copyop), EventHandler(eh, copyop)
osg::Drawable::EventCallback(eh, copyop),
_ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {} _ignoreHandledEventsMask(eh._ignoreHandledEventsMask) {}
#endif
META_Object(osgGA,GUIEventHandler); META_Object(osgGA,GUIEventHandler);
/** Event traversal node callback method.*/ /** Handle event. Override the handle(..) method in your event handlers to respond to events. */
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv);
/** Event traversal drawable callback method.*/
virtual void event(osg::NodeVisitor* nv, osg::Drawable* drawable);
/** Handle events, return true if handled, false otherwise. */ /** Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { return handle(ea,aa); } 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 /** 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. * 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(,,,) * Note, this method is an inline method, and not appropriate for users to override, override the handle(,,,)
@ -86,10 +89,11 @@ public:
return false; return false;
} }
} }
#endif
/** Deprecated, Handle events, return true if handled, false otherwise. */ /** Deprecated, Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter&,GUIActionAdapter&) { return false; } 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 /** 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. * 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(,) * 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 */ /** Set a mask of osgGA::GUIEeventAdapter::Event to be ignored if marked as handled */
void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; } void setIgnoreHandledEventsMask(unsigned int mask) { _ignoreHandledEventsMask = mask; }
@ -120,18 +121,8 @@ public:
protected: protected:
unsigned int _ignoreHandledEventsMask; unsigned int _ignoreHandledEventsMask;
};
#ifdef USE_DEPRECATED_API
// keep for backwards compatibility
class GUIEventHandlerVisitor
{
public:
void visit(GUIEventHandler&) {}
};
#endif #endif
};
} }

View File

@ -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 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; virtual void getUsage(osg::ApplicationUsage& usage) const;
void doOperation(); void doOperation();

View File

@ -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 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; virtual void getUsage(osg::ApplicationUsage& usage) const;
void doOperation(); void doOperation();

View File

@ -254,11 +254,6 @@ public:
void set(osg::Node* model); 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 bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void getUsage(osg::ApplicationUsage& usage) const; virtual void getUsage(osg::ApplicationUsage& usage) const;

View File

@ -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) {} ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {}
META_Object(osgViewer,ViewConfig); META_Object(osgViewer,ViewConfig);
/** configure method that is overridden by Config subclasses.*/ /** configure method that is overridden by Config subclasses.*/
virtual void configure(osgViewer::View& /*view*/) const {} virtual void configure(osgViewer::View& /*view*/) const {}
/** convinience method for getting the relavent display settings to use.*/ /** convinience method for getting the relavent display settings to use.*/
virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const; 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.*/ /** Get the const View's image pager.*/
const osgDB::ImagePager* getImagePager() const; const osgDB::ImagePager* getImagePager() const;
/** Add a Device. /** 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()*/ * 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); void addDevice(osgGA::Device* eventSource);
@ -167,13 +167,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
void home(); void home();
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers; typedef std::list< osg::ref_ptr<osgGA::EventHandler> > EventHandlers;
/** Add an EventHandler that adds handling of events to the View.*/ /** 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.*/ /** Remove an EventHandler from View.*/
void removeEventHandler(osgGA::GUIEventHandler* eventHandler); void removeEventHandler(osgGA::EventHandler* eventHandler);
/** Get the View's list of EventHandlers.*/ /** Get the View's list of EventHandlers.*/
EventHandlers& getEventHandlers() { return _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.*/ /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
float getFusionDistanceValue() const { return _fusionDistanceValue; } float getFusionDistanceValue() const { return _fusionDistanceValue; }
/** Apply a viewer configuration to set up Cameras and Windowing. */ /** Apply a viewer configuration to set up Cameras and Windowing. */
void apply(ViewConfig* config); void apply(ViewConfig* config);
ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); } ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); } const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
/** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */ /** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */
void setUpViewAcrossAllScreens(); 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). */ /** 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); 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.*/ /** Convenience method for setting up depth partitioning on the specified camera.*/
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0); 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.*/ /** Return true if this view contains a specified camera.*/
bool containsCamera(const osg::Camera* camera) const; bool containsCamera(const osg::Camera* camera) const;
/** deprecated. */ /** deprecated. */
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const; 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. */ /** deprecated. */
bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); 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. */ /** 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); 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. */ /** 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); 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. */ /** 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); 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: public:
osg::Texture* createDistortionTexture(int width, int height); osg::Texture* createDistortionTexture(int width, int height);
osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture); 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); 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<osg::DisplaySettings> _ds; osg::ref_ptr<osg::DisplaySettings> _ds;
double _eyeScale; double _eyeScale;
}; };
public: public:
@ -334,7 +334,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
float _fusionDistanceValue; float _fusionDistanceValue;
osg::ref_ptr<ViewConfig> _lastAppliedViewConfig; osg::ref_ptr<ViewConfig> _lastAppliedViewConfig;
}; };
} }

View File

@ -372,7 +372,6 @@ bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object,
{ {
if (areTypesCompatible(valueType, sourceType)) if (areTypesCompatible(valueType, sourceType))
{ {
OSG_NOTICE<<"Calling get"<<std::endl;
return serializer->get(*object, valuePtr); return serializer->get(*object, valuePtr);
} }
else else
@ -396,7 +395,6 @@ bool PropertyInterface::copyPropertyObjectToObject(osg::Object* object, const st
{ {
if (areTypesCompatible(valueType, destinationType)) if (areTypesCompatible(valueType, destinationType))
{ {
OSG_NOTICE<<"Calling set"<<std::endl;
return serializer->set(*object, const_cast<void*>(valuePtr)); return serializer->set(*object, const_cast<void*>(valuePtr));
} }
else else

View File

@ -11,6 +11,8 @@ SET(TARGET_H
${HEADER_PATH}/AnimationPathManipulator ${HEADER_PATH}/AnimationPathManipulator
${HEADER_PATH}/DriveManipulator ${HEADER_PATH}/DriveManipulator
${HEADER_PATH}/Device ${HEADER_PATH}/Device
${HEADER_PATH}/Event
${HEADER_PATH}/EventHandler
${HEADER_PATH}/EventQueue ${HEADER_PATH}/EventQueue
${HEADER_PATH}/EventVisitor ${HEADER_PATH}/EventVisitor
${HEADER_PATH}/Export ${HEADER_PATH}/Export
@ -38,6 +40,8 @@ SET(TARGET_SRC
AnimationPathManipulator.cpp AnimationPathManipulator.cpp
DriveManipulator.cpp DriveManipulator.cpp
Device.cpp Device.cpp
Event.cpp
EventHandler.cpp
EventQueue.cpp EventQueue.cpp
EventVisitor.cpp EventVisitor.cpp
FirstPersonManipulator.cpp FirstPersonManipulator.cpp

View File

@ -28,7 +28,7 @@ Device::Device(const Device& es, const osg::CopyOp& copyop):
setEventQueue(new EventQueue); setEventQueue(new EventQueue);
} }
void Device::sendEvent(const GUIEventAdapter& /*event*/) void Device::sendEvent(const Event& /*event*/)
{ {
OSG_WARN << "Device::sendEvent not implemented!" << std::endl; OSG_WARN << "Device::sendEvent not implemented!" << std::endl;
} }

25
src/osgGA/Event.cpp Normal file
View File

@ -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 <osgGA/Event>
using namespace osgGA;
Event::Event():
_time(0.0)
{}
Event::Event(const Event& rhs, const osg::CopyOp& copyop):
osg::Object(rhs, copyop),
_time(rhs._time)
{}

View File

@ -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 <osgGA/GUIEventHandler>
#include <osgGA/EventVisitor>
using namespace osgGA;
void EventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(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<osgGA::EventVisitor*>(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 "<<event<<std::endl;
return false;
}

View File

@ -51,7 +51,7 @@ void EventQueue::appendEvents(Events& events)
_eventQueue.insert(_eventQueue.end(), events.begin(), events.end()); _eventQueue.insert(_eventQueue.end(), events.begin(), events.end());
} }
void EventQueue::addEvent(GUIEventAdapter* event) void EventQueue::addEvent(Event* event)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
_eventQueue.push_back(event); _eventQueue.push_back(event);
@ -425,7 +425,7 @@ GUIEventAdapter* EventQueue::touchBegan(unsigned int id, GUIEventAdapter::Touch
event->addTouchPoint(id, phase, x, y, 0); event->addTouchPoint(id, phase, x, y, 0);
if(_firstTouchEmulatesMouse) if(_firstTouchEmulatesMouse)
event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON);
addEvent(event); addEvent(event);
return event; return event;
@ -464,7 +464,7 @@ GUIEventAdapter* EventQueue::touchEnded(unsigned int id, GUIEventAdapter::Touch
event->addTouchPoint(id, phase, x, y, tap_count); event->addTouchPoint(id, phase, x, y, tap_count);
if(_firstTouchEmulatesMouse) if(_firstTouchEmulatesMouse)
event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON);
addEvent(event); addEvent(event);
return event; return event;
@ -495,7 +495,7 @@ void EventQueue::frame(double time)
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::FRAME); event->setEventType(GUIEventAdapter::FRAME);
event->setTime(time); event->setTime(time);
// OSG_NOTICE<<"frame("<<time<<"), event->getX()="<<event->getX()<<", event->getY()="<<event->getY()<<", event->getXmin()="<<event->getXmin()<<", event->getYmin()="<<event->getYmin()<<", event->getXmax()="<<event->getXmax()<<", event->getYmax()="<<event->getYmax()<<std::endl; // OSG_NOTICE<<"frame("<<time<<"), event->getX()="<<event->getX()<<", event->getY()="<<event->getY()<<", event->getXmin()="<<event->getXmin()<<", event->getYmin()="<<event->getYmin()<<", event->getXmax()="<<event->getXmax()<<", event->getYmax()="<<event->getYmax()<<std::endl;
addEvent(event); addEvent(event);

View File

@ -28,14 +28,14 @@ EventVisitor::~EventVisitor()
{ {
} }
void EventVisitor::addEvent(GUIEventAdapter* event) void EventVisitor::addEvent(Event* event)
{ {
_events.push_back(event); _events.push_back(event);
} }
void EventVisitor::removeEvent(GUIEventAdapter* event) void EventVisitor::removeEvent(Event* event)
{ {
EventList::iterator itr = std::find(_events.begin(),_events.end(),event); EventQueue::Events::iterator itr = std::find(_events.begin(), _events.end(), event);
if (itr!=_events.end()) _events.erase(itr); if (itr!=_events.end()) _events.erase(itr);
} }

View File

@ -25,7 +25,6 @@ osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
GUIEventAdapter::GUIEventAdapter(): GUIEventAdapter::GUIEventAdapter():
_handled(false), _handled(false),
_eventType(NONE), _eventType(NONE),
_time(0.0),
_windowX(0), _windowX(0),
_windowY(0), _windowY(0),
_windowWidth(1280), _windowWidth(1280),
@ -48,10 +47,9 @@ GUIEventAdapter::GUIEventAdapter():
{} {}
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop): GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
osg::Object(rhs,copyop), osgGA::Event(rhs,copyop),
_handled(rhs._handled), _handled(rhs._handled),
_eventType(rhs._eventType), _eventType(rhs._eventType),
_time(rhs._time),
_context(rhs._context), _context(rhs._context),
_windowX(rhs._windowX), _windowX(rhs._windowX),
_windowY(rhs._windowY), _windowY(rhs._windowY),

View File

@ -16,33 +16,21 @@
using namespace osgGA; using namespace osgGA;
// adapt EventHandler usage to old style GUIEventHandler usage
void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(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(); #if 1
itr != ev->getEvents().end(); bool handled = handle(*ea, *(ev->getActionAdapter()), object, nv);
++itr) if (handled) ea->setHandled(true);
{ return handled;
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); #else
} return handleWithCheckAgainstIgnoreHandledEventsMask(*ea, *(ev->getActionAdapter()), object, nv);
} #endif
if (node->getNumChildrenRequiringEventTraversal()>0 || _nestedCallback.valid()) traverse(node,nv);
}
void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(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()), drawable, nv);
}
} }
return false;
} }

View File

@ -305,8 +305,8 @@ void Dragger::traverse(osg::NodeVisitor& nv)
itr != ev->getEvents().end(); itr != ev->getEvents().end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* ea = itr->get(); osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
if (handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true); if (ea && handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true);
} }
} }
return; return;

View File

@ -187,7 +187,9 @@ void Cursor::traverse(osg::NodeVisitor& nv)
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::PUSH): case(osgGA::GUIEventAdapter::PUSH):

View File

@ -65,12 +65,6 @@ bool KeyEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAd
return false; return false;
} }
void KeyEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }

View File

@ -131,12 +131,6 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
return false; return false;
} }
void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }

View File

@ -967,25 +967,6 @@ double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const
return _timePerSlide; return _timePerSlide;
} }
void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(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) bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{ {

View File

@ -257,7 +257,8 @@ void Timeout::traverse(osg::NodeVisitor& nv)
itr != events.end(); itr != events.end();
++itr) ++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; bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP;

View File

@ -916,7 +916,7 @@ void CompositeViewer::reprojectPointerData(osgGA::GUIEventAdapter& source_event,
struct SortEvents struct SortEvents
{ {
bool operator() (const osg::ref_ptr<osgGA::GUIEventAdapter>& lhs,const osg::ref_ptr<osgGA::GUIEventAdapter>& rhs) const bool operator() (const osg::ref_ptr<osgGA::Event>& lhs,const osg::ref_ptr<osgGA::Event>& rhs) const
{ {
return lhs->getTime() < rhs->getTime(); return lhs->getTime() < rhs->getTime();
} }
@ -961,7 +961,8 @@ void CompositeViewer::eventTraversal()
itr != gw_events.end(); itr != gw_events.end();
++itr) ++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()); all_events.insert(all_events.end(), gw_events.begin(), gw_events.end());
@ -976,7 +977,8 @@ void CompositeViewer::eventTraversal()
itr != all_events.end(); itr != all_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
@ -1059,7 +1061,9 @@ void CompositeViewer::eventTraversal()
itr != all_events.end(); itr != all_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::CLOSE_WINDOW): case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
@ -1118,7 +1122,8 @@ void CompositeViewer::eventTraversal()
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::KEYUP): case(osgGA::GUIEventAdapter::KEYUP):
@ -1148,16 +1153,15 @@ void CompositeViewer::eventTraversal()
++veitr) ++veitr)
{ {
View* view = veitr->first; View* view = veitr->first;
_eventVisitor->setActionAdapter(view);
if (view && view->getSceneData()) if (view && view->getSceneData())
{ {
_eventVisitor->setActionAdapter(view);
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
_eventVisitor->reset(); _eventVisitor->reset();
_eventVisitor->addEvent( event ); _eventVisitor->addEvent( event );
@ -1205,18 +1209,18 @@ void CompositeViewer::eventTraversal()
++veitr) ++veitr)
{ {
View* view = veitr->first; View* view = veitr->first;
_eventVisitor->setActionAdapter(view);
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin(); for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin();
hitr != view->getEventHandlers().end(); hitr != view->getEventHandlers().end();
++hitr) ++hitr)
{ {
(*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view, 0, _eventVisitor.get()); (*hitr)->handle( event, view, _eventVisitor.get());
} }
} }
} }
@ -1226,16 +1230,16 @@ void CompositeViewer::eventTraversal()
++veitr) ++veitr)
{ {
View* view = veitr->first; View* view = veitr->first;
_eventVisitor->setActionAdapter(view);
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end(); itr != veitr->second.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
if (view->getCameraManipulator()) if (view->getCameraManipulator())
{ {
view->getCameraManipulator()->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view); view->getCameraManipulator()->handle( event, view, _eventVisitor.get());
} }
} }
} }

View File

@ -270,7 +270,7 @@ void View::init()
void View::setStartTick(osg::Timer_t tick) void View::setStartTick(osg::Timer_t tick)
{ {
_startTick = tick; _startTick = tick;
for(Devices::iterator eitr = _eventSources.begin(); for(Devices::iterator eitr = _eventSources.begin();
eitr != _eventSources.end(); eitr != _eventSources.end();
++eitr) ++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); EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr == _eventHandlers.end()) 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); EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr != _eventHandlers.end()) if (itr != _eventHandlers.end())
@ -846,7 +846,7 @@ void View::requestContinuousUpdate(bool flag)
void View::requestWarpPointer(float x,float y) void View::requestWarpPointer(float x,float y)
{ {
OSG_INFO<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl; OSG_INFO<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl;
float local_x, local_y; float local_x, local_y;
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
if (camera) if (camera)
@ -887,33 +887,33 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext()); const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext());
bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
// OSG_NOTICE<<"getCameraContainingPosition("<<x<<", "<<y<<") view_invert_y = "<<view_invert_y<<", Xmin() = "<<eventState->getXmin()<<", Xmax() = "<<eventState->getXmax()<<", Ymin() = "<<eventState->getYmin()<<", Ymax() = "<<eventState->getYmax()<<std::endl; // OSG_NOTICE<<"getCameraContainingPosition("<<x<<", "<<y<<") view_invert_y = "<<view_invert_y<<", Xmin() = "<<eventState->getXmin()<<", Xmax() = "<<eventState->getXmax()<<", Ymin() = "<<eventState->getYmin()<<", Ymax() = "<<eventState->getYmax()<<std::endl;
double epsilon = 0.5; double epsilon = 0.5;
// if master camera has graphics context and eventState context matches then assume coordinates refer // if master camera has graphics context and eventState context matches then assume coordinates refer
// to master camera // to master camera
bool masterActive = (_camera->getGraphicsContext()!=0 && _camera->getViewport()); bool masterActive = (_camera->getGraphicsContext()!=0 && _camera->getViewport());
bool eventStateMatchesMaster = (gw!=0) ? _camera->getGraphicsContext()==gw : false; bool eventStateMatchesMaster = (gw!=0) ? _camera->getGraphicsContext()==gw : false;
if (masterActive && eventStateMatchesMaster) if (masterActive && eventStateMatchesMaster)
{ {
// OSG_NOTICE<<"Event state matches master"<<std::endl; // OSG_NOTICE<<"Event state matches master"<<std::endl;
const osg::Viewport* viewport = _camera->getViewport(); const osg::Viewport* viewport = _camera->getViewport();
// rescale mouse x,y first to 0 to 1 range // rescale mouse x,y first to 0 to 1 range
double new_x = (x-eventState->getXmin())/(eventState->getXmax()-eventState->getXmin()); double new_x = (x-eventState->getXmin())/(eventState->getXmax()-eventState->getXmin());
double new_y = (y-eventState->getYmin())/(eventState->getYmax()-eventState->getYmin()); double new_y = (y-eventState->getYmin())/(eventState->getYmax()-eventState->getYmin());
// flip y if required // flip y if required
if (view_invert_y) new_y = 1.0f-new_y; 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 // rescale mouse x, y to window dimensions so we can check against master Camera's viewport
new_x *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->width); new_x *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->width);
new_y *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->height); new_y *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->height);
if (new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) && 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) ) 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."<<std::endl; // OSG_NOTICE<<"master camera viewport not matched."<<std::endl;
} }
} }
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix(); osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
// convert to non dimensional // convert to non dimensional
@ -990,9 +990,9 @@ bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector
{ {
float local_x, local_y; float local_x, local_y;
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
OSG_INFO<<"computeIntersections("<<x<<", "<<y<<") local_x="<<local_x<<", local_y="<<local_y<<std::endl; OSG_INFO<<"computeIntersections("<<x<<", "<<y<<") local_x="<<local_x<<", local_y="<<local_y<<std::endl;
if (camera) return computeIntersections(camera, (camera->getViewport()==0)?osgUtil::Intersector::PROJECTION : osgUtil::Intersector::WINDOW, local_x, local_y, intersections, traversalMask); if (camera) return computeIntersections(camera, (camera->getViewport()==0)?osgUtil::Intersector::PROJECTION : osgUtil::Intersector::WINDOW, local_x, local_y, intersections, traversalMask);
else return false; else return false;
} }
@ -1001,7 +1001,7 @@ bool View::computeIntersections(float x,float y, const osg::NodePath& nodePath,
{ {
float local_x, local_y; float local_x, local_y;
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
OSG_INFO<<"computeIntersections("<<x<<", "<<y<<") local_x="<<local_x<<", local_y="<<local_y<<std::endl; OSG_INFO<<"computeIntersections("<<x<<", "<<y<<") local_x="<<local_x<<", local_y="<<local_y<<std::endl;
if (camera) return computeIntersections(camera, (camera->getViewport()==0)?osgUtil::Intersector::PROJECTION : osgUtil::Intersector::WINDOW, local_x, local_y, nodePath, intersections, traversalMask); if (camera) return computeIntersections(camera, (camera->getViewport()==0)?osgUtil::Intersector::PROJECTION : osgUtil::Intersector::WINDOW, local_x, local_y, nodePath, intersections, traversalMask);
@ -1015,7 +1015,7 @@ bool View::computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineS
{ {
const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1); const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1);
const osg::Camera* camera = dynamic_cast<const osg::Camera*>(pd->object.get()); const osg::Camera* camera = dynamic_cast<const osg::Camera*>(pd->object.get());
if (camera) if (camera)
{ {
return computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), intersections, traversalMask); return computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), intersections, traversalMask);
} }
@ -1031,7 +1031,7 @@ bool View::computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::Nod
{ {
const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1); const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1);
const osg::Camera* camera = dynamic_cast<const osg::Camera*>(pd->object.get()); const osg::Camera* camera = dynamic_cast<const osg::Camera*>(pd->object.get());
if (camera) if (camera)
{ {
return computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), nodePath, intersections, traversalMask); return computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), nodePath, intersections, traversalMask);
} }
@ -1116,7 +1116,7 @@ void View::addDevice(osgGA::Device* eventSource)
{ {
_eventSources.push_back(eventSource); _eventSources.push_back(eventSource);
} }
if (eventSource) if (eventSource)
eventSource->getEventQueue()->setStartTick(getStartTick()); eventSource->getEventQueue()->setStartTick(getStartTick());
} }
@ -1226,7 +1226,7 @@ void View::StereoSlaveCallback::updateSlave(osg::View& view, osg::View::Slave& s
{ {
// inherit any settings applied to the master Camera. // inherit any settings applied to the master Camera.
camera->inheritCullSettings(*(view.getCamera()), camera->getInheritanceMask()); camera->inheritCullSettings(*(view.getCamera()), camera->getInheritanceMask());
if (_eyeScale<0.0) if (_eyeScale<0.0)
{ {
camera->setCullMask(camera->getCullMaskLeft()); camera->setCullMask(camera->getCullMaskLeft());
@ -1235,7 +1235,7 @@ void View::StereoSlaveCallback::updateSlave(osg::View& view, osg::View::Slave& s
{ {
camera->setCullMask(camera->getCullMaskRight()); camera->setCullMask(camera->getCullMaskRight());
} }
// set projection matrix // set projection matrix
if (_eyeScale<0.0) if (_eyeScale<0.0)
{ {
@ -1389,7 +1389,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
{ {
if (!camera || camera->getGraphicsContext()==0) return; if (!camera || camera->getGraphicsContext()==0) return;
if (!ds->getStereo() && !ds->getKeystoneHint()) return; if (!ds->getStereo() && !ds->getKeystoneHint()) return;
ds->setUseSceneViewForStereoHint(false); ds->setUseSceneViewForStereoHint(false);
typedef std::vector< osg::ref_ptr<Keystone> > Keystones; typedef std::vector< osg::ref_ptr<Keystone> > Keystones;
@ -1404,13 +1404,13 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
if (keystone) keystones.push_back(keystone); if (keystone) keystones.push_back(keystone);
} }
} }
if (ds->getKeystoneHint()) if (ds->getKeystoneHint())
{ {
while(keystones.size()<2) keystones.push_back(new Keystone); while(keystones.size()<2) keystones.push_back(new Keystone);
} }
// set up view's main camera // set up view's main camera
{ {
double height = ds->getScreenHeight(); double height = ds->getScreenHeight();
@ -1420,10 +1420,10 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
camera->setProjectionMatrixAsPerspective( vfov, width/height, 1.0f,10000.0f); camera->setProjectionMatrixAsPerspective( vfov, width/height, 1.0f,10000.0f);
} }
osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext(); osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = const_cast<osg::GraphicsContext::Traits*>(camera->getGraphicsContext()->getTraits()); osg::ref_ptr<osg::GraphicsContext::Traits> traits = const_cast<osg::GraphicsContext::Traits*>(camera->getGraphicsContext()->getTraits());
if (!ds->getStereo()) if (!ds->getStereo())
@ -1432,7 +1432,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
osg::ref_ptr<osgViewer::Keystone> keystone = 0; osg::ref_ptr<osgViewer::Keystone> keystone = 0;
if (!(ds->getKeystones().empty())) keystone = dynamic_cast<osgViewer::Keystone*>(ds->getKeystones().front().get()); if (!(ds->getKeystones().empty())) keystone = dynamic_cast<osgViewer::Keystone*>(ds->getKeystones().front().get());
if (!keystone) keystone = new osgViewer::Keystone; if (!keystone) keystone = new osgViewer::Keystone;
// create distortion texture // create distortion texture
osg::ref_ptr<osg::Texture> texture = createDistortionTexture(traits->width, traits->height); osg::ref_ptr<osg::Texture> texture = createDistortionTexture(traits->width, traits->height);
@ -1446,12 +1446,12 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
texture.get(), keystone.get()); texture.get(), keystone.get());
// attach Keystone editing event handler. // attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
camera->setGraphicsContext(0); camera->setGraphicsContext(0);
return; return;
} }
switch(ds->getStereoMode()) switch(ds->getStereoMode())
{ {
case(osg::DisplaySettings::QUAD_BUFFER): case(osg::DisplaySettings::QUAD_BUFFER):
@ -1475,7 +1475,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// left keystone camera to render to left buffer // left keystone camera to render to left buffer
// left keystone camera to render to right buffer // left keystone camera to render to right buffer
// one keystone and editing for the one window // one keystone and editing for the one window
if (!keystones.empty()) if (!keystones.empty())
{ {
// for keystone: // for keystone:
@ -1484,7 +1484,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// left keystone camera to render to left viewport/window // left keystone camera to render to left viewport/window
// right keystone camera to render to right viewport/window // right keystone camera to render to right viewport/window
// two keystone, one for each of the left and right viewports/windows // two keystone, one for each of the left and right viewports/windows
osg::ref_ptr<Keystone> keystone = keystones.front(); osg::ref_ptr<Keystone> keystone = keystones.front();
// create distortion texture // create distortion texture
@ -1513,7 +1513,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// attach the texture and use it as the color buffer. // attach the texture and use it as the color buffer.
right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get()); right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get());
// create Keystone left distortion camera // create Keystone left distortion camera
keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0)); keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0));
@ -1527,7 +1527,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// attach Keystone editing event handler. // attach Keystone editing event handler.
left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get())); left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get()));
// create Keystone right distortion camera // create Keystone right distortion camera
osg::ref_ptr<osg::Camera> right_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), osg::ref_ptr<osg::Camera> right_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(),
0, 0, traits->width, traits->height, 0, 0, traits->width, traits->height,
@ -1536,7 +1536,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
right_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 3); right_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 3);
right_keystone_camera->setAllowEventFocus(false); right_keystone_camera->setAllowEventFocus(false);
} }
break; break;
@ -1567,12 +1567,12 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// one keystone and editing for the one window // one keystone and editing for the one window
osg::ref_ptr<Keystone> keystone = keystones.front(); osg::ref_ptr<Keystone> keystone = keystones.front();
bool useTwoTexture = true; bool useTwoTexture = true;
if (useTwoTexture) if (useTwoTexture)
{ {
// create left distortion texture // create left distortion texture
osg::ref_ptr<osg::Texture> left_texture = createDistortionTexture(traits->width, traits->height); osg::ref_ptr<osg::Texture> left_texture = createDistortionTexture(traits->width, traits->height);
@ -1628,10 +1628,10 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get())); left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get()));
camera->setAllowEventFocus(false); camera->setAllowEventFocus(false);
} }
else else
{ {
// create distortion texture // create distortion texture
osg::ref_ptr<osg::Texture> texture = createDistortionTexture(traits->width, traits->height); osg::ref_ptr<osg::Texture> texture = createDistortionTexture(traits->width, traits->height);
@ -1664,7 +1664,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
texture.get(), keystone.get()); texture.get(), keystone.get());
distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
// attach Keystone editing event handler. // attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
@ -1701,7 +1701,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// left keystone camera to render to left viewport/window // left keystone camera to render to left viewport/window
// right keystone camera to render to right viewport/window // right keystone camera to render to right viewport/window
// two keystone, one for each of the left and right viewports/windows // two keystone, one for each of the left and right viewports/windows
osg::ref_ptr<Keystone> left_keystone = keystones[0]; osg::ref_ptr<Keystone> left_keystone = keystones[0];
osg::ref_ptr<Keystone> right_keystone = keystones[1]; osg::ref_ptr<Keystone> right_keystone = keystones[1];
@ -1733,7 +1733,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// attach the texture and use it as the color buffer. // attach the texture and use it as the color buffer.
right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get()); right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get());
// create Keystone left distortion camera // create Keystone left distortion camera
left_keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0)); left_keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0));
@ -1761,9 +1761,9 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get())); right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get()));
camera->setAllowEventFocus(false); camera->setAllowEventFocus(false);
} }
break; break;
} }
case(osg::DisplaySettings::VERTICAL_SPLIT): case(osg::DisplaySettings::VERTICAL_SPLIT):
@ -1774,7 +1774,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
bool left_eye_bottom_viewport = ds->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_BOTTOM_VIEWPORT; bool left_eye_bottom_viewport = ds->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_BOTTOM_VIEWPORT;
int left_start = (left_eye_bottom_viewport) ? 0 : traits->height/2; int left_start = (left_eye_bottom_viewport) ? 0 : traits->height/2;
int right_start = (left_eye_bottom_viewport) ? traits->height/2 : 0; int right_start = (left_eye_bottom_viewport) ? traits->height/2 : 0;
// bottom viewport Camera // bottom viewport Camera
osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(),
0, left_start, traits->width, traits->height/2, traits->doubleBuffer ? GL_BACK : GL_FRONT, 0, left_start, traits->width, traits->height/2, traits->doubleBuffer ? GL_BACK : GL_FRONT,
@ -1832,7 +1832,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// attach the texture and use it as the color buffer. // attach the texture and use it as the color buffer.
right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get()); right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get());
// create Keystone left distortion camera // create Keystone left distortion camera
left_keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0)); left_keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0));
@ -1860,7 +1860,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get())); right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get()));
camera->setAllowEventFocus(false); camera->setAllowEventFocus(false);
} }
break; break;
@ -1910,7 +1910,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
texture.get(), keystone.get()); texture.get(), keystone.get());
distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
// attach Keystone editing event handler. // attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
} }
@ -1960,7 +1960,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
texture.get(), keystone.get()); texture.get(), keystone.get());
distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1);
// attach Keystone editing event handler. // attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
} }
@ -1992,7 +1992,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
camera->addChild(geode.get()); camera->addChild(geode.get());
geode->setCullingActive(false); geode->setCullingActive(false);
osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet(); osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
// set up stencil // set up stencil

View File

@ -889,7 +889,8 @@ void Viewer::eventTraversal()
itr != gw_events.end(); itr != gw_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
event->setGraphicsContext(gw); event->setGraphicsContext(gw);
@ -943,7 +944,8 @@ void Viewer::eventTraversal()
itr != gw_events.end(); itr != gw_events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::CLOSE_WINDOW): case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
@ -981,7 +983,8 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
switch(event->getEventType()) switch(event->getEventType())
{ {
case(osgGA::GUIEventAdapter::KEYUP): case(osgGA::GUIEventAdapter::KEYUP):
@ -1009,7 +1012,8 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
_eventVisitor->reset(); _eventVisitor->reset();
_eventVisitor->addEvent( event ); _eventVisitor->addEvent( event );
@ -1055,13 +1059,12 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
for(EventHandlers::iterator hitr = _eventHandlers.begin(); for(EventHandlers::iterator hitr = _eventHandlers.begin();
hitr != _eventHandlers.end(); hitr != _eventHandlers.end();
++hitr) ++hitr)
{ {
(*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this, 0, _eventVisitor.get()); (*hitr)->handle( event, 0, _eventVisitor.get());
} }
} }
@ -1070,10 +1073,10 @@ void Viewer::eventTraversal()
itr != events.end(); itr != events.end();
++itr) ++itr)
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::Event* event = itr->get();
if (_cameraManipulator.valid()) if (event && _cameraManipulator.valid())
{ {
_cameraManipulator->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this); _cameraManipulator->handle( event, 0, _eventVisitor.get());
} }
} }