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 full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/
@ -39,9 +39,9 @@
#elif defined(__sgi)
#include <unistd.h>
#include <net/soioctl.h>
#elif defined(__CYGWIN__)
#elif defined(__CYGWIN__)
#include <unistd.h>
#elif defined(__sun)
#elif defined(__sun)
#include <unistd.h>
#include <sys/sockio.h>
#elif defined (__APPLE__)
@ -202,7 +202,8 @@ void DataConverter::write(CameraPacket& cameraPacket)
itr != cameraPacket._events.end();
++itr)
{
write(*(*itr));
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (event) write(*(event));
}
}
@ -249,7 +250,7 @@ void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer)
//////////////////////////////////////////////////////////////////////////////
//
// Reciever
// Reciever
//
Receiver::Receiver( void )
{
@ -338,7 +339,7 @@ void Receiver::sync( void )
#if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || \
defined(__DragonFly__)
socklen_t
socklen_t
#else
int
#endif
@ -381,7 +382,7 @@ void Receiver::sync( void )
//////////////////////////////////////////////////////////////////////////////
//
// Broadcaster
// Broadcaster
//
Broadcaster::Broadcaster( void )
{

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

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 full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/
@ -22,25 +22,23 @@ class PointsEventHandler : public osgGA::GUIEventHandler
{
public:
PointsEventHandler();
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
void getUsage(osg::ApplicationUsage& usage) const;
void setStateSet(osg::StateSet* stateset) { _stateset=stateset; }
osg::StateSet* getStateSet() { return _stateset.get(); }
const osg::StateSet* getStateSet() const { return _stateset.get(); }
void setPointSize(float psize);
float getPointSize() const;
void changePointSize(float delta);
void changePointAttenuation(float scale);
osg::ref_ptr<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 full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/
@ -28,13 +28,13 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
case(osgGA::GUIEventAdapter::KEYUP):
{
osg::notify(osg::INFO)<<"ShowEventHandler KEYUP "<<(int)ea.getKey()<<std::endl;
if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 &&
if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 &&
ea.getKey()<=osgGA::GUIEventAdapter::KEY_F8)
{
unsigned int child = ea.getKey()-osgGA::GUIEventAdapter::KEY_F1;
osg::notify(osg::INFO)<<" Select "<<child<<std::endl;
osg::Switch* showSwitch = dynamic_cast<osg::Switch*>(object);
if (showSwitch)
if (showSwitch)
{
if (child<showSwitch->getNumChildren())
{
@ -52,12 +52,6 @@ bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
return false;
}
void ShowEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
{
v.visit(*this);
}
void ShowEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{
}

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 full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/
@ -28,11 +28,9 @@ class ShowEventHandler : public osgGA::GUIEventHandler
ShowEventHandler();
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv);
virtual void accept(osgGA::GUIEventHandlerVisitor& v);
virtual void getUsage(osg::ApplicationUsage& usage) const;
};
}

View File

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

View File

@ -48,13 +48,13 @@ const unsigned int MAX_NUM_EVENTS = 10;
const unsigned int SWAP_BYTES_COMPARE = 0x12345678;
class CameraPacket {
public:
CameraPacket():_masterKilled(false)
CameraPacket():_masterKilled(false)
{
_byte_order = SWAP_BYTES_COMPARE;
}
void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp)
{
_matrix = matrix;
@ -63,20 +63,20 @@ class CameraPacket {
_frameStamp = *frameStamp;
}
}
void getModelView(osg::Matrix& matrix,float angle_offset=0.0f)
{
matrix = _matrix * osg::Matrix::rotate(osg::DegreesToRadians(angle_offset),0.0f,1.0f,0.0f);
}
void readEventQueue(osgViewer::Viewer& viewer);
void writeEventQueue(osgViewer::Viewer& viewer);
void setMasterKilled(const bool flag) { _masterKilled = flag; }
const bool getMasterKilled() const { return _masterKilled; }
unsigned int _byte_order;
bool _masterKilled;
osg::Matrix _matrix;
@ -84,11 +84,11 @@ class CameraPacket {
// note don't use a ref_ptr as used elsewhere for FrameStamp
// since we don't want to copy the pointer - but the memory.
// FrameStamp doesn't have a private destructor to allow
// us to do this, even though its a reference counted object.
// us to do this, even though its a reference counted object.
osg::FrameStamp _frameStamp;
osgGA::EventQueue::Events _events;
};
class DataConverter
@ -112,7 +112,7 @@ class DataConverter
bool _swapBytes;
char* _currentPtr;
void reset()
{
_currentPtr = _startPtr;
@ -122,22 +122,22 @@ class DataConverter
{
if (_currentPtr+1>=_endPtr) return;
*(_currentPtr++) = *(ptr);
*(_currentPtr++) = *(ptr);
}
inline void read1(char* ptr)
{
if (_currentPtr+1>=_endPtr) return;
*(ptr) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
inline void write2(char* ptr)
{
if (_currentPtr+2>=_endPtr) return;
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr);
}
inline void read2(char* ptr)
@ -146,13 +146,13 @@ class DataConverter
if (_swapBytes)
{
*(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
else
{
*(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
}
@ -160,10 +160,10 @@ class DataConverter
{
if (_currentPtr+4>=_endPtr) return;
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr);
}
inline void read4(char* ptr)
@ -172,17 +172,17 @@ class DataConverter
if (_swapBytes)
{
*(ptr+3) = *(_currentPtr++);
*(ptr+2) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
*(ptr+3) = *(_currentPtr++);
*(ptr+2) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
else
{
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
}
@ -190,15 +190,15 @@ class DataConverter
{
if (_currentPtr+8>=_endPtr) return;
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr++);
*(_currentPtr++) = *(ptr);
}
inline void read8(char* ptr)
@ -208,27 +208,27 @@ class DataConverter
if (_swapBytes)
{
*(ptr+7) = *(_currentPtr++);
*(ptr+6) = *(_currentPtr++);
*(ptr+5) = *(_currentPtr++);
*(ptr+4) = *(_currentPtr++);
*(ptr+7) = *(_currentPtr++);
*(ptr+6) = *(_currentPtr++);
*(ptr+5) = *(_currentPtr++);
*(ptr+4) = *(_currentPtr++);
*(ptr+3) = *(_currentPtr++);
*(ptr+2) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
*(ptr+3) = *(_currentPtr++);
*(ptr+2) = *(_currentPtr++);
*(ptr+1) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
else
{
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr++) = *(_currentPtr++);
*(ptr) = *(_currentPtr++);
}
}
@ -361,22 +361,23 @@ class DataConverter
event.setModKeyMask(readUInt());
event.setTime(readDouble());
}
void write(CameraPacket& cameraPacket)
{
writeUInt(cameraPacket._byte_order);
writeUInt(cameraPacket._masterKilled);
write(cameraPacket._matrix);
write(cameraPacket._frameStamp);
writeUInt(cameraPacket._events.size());
for(osgGA::EventQueue::Events::iterator itr = cameraPacket._events.begin();
itr != cameraPacket._events.end();
++itr)
{
write(*(*itr));
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (event) write(*event);
}
}
@ -387,12 +388,12 @@ class DataConverter
{
_swapBytes = !_swapBytes;
}
cameraPacket._masterKilled = readUInt()!=0;
read(cameraPacket._matrix);
read(cameraPacket._frameStamp);
cameraPacket._events.clear();
unsigned int numEvents = readUInt();
for(unsigned int i=0;i<numEvents;++i)
@ -409,7 +410,7 @@ void CameraPacket::readEventQueue(osgViewer::Viewer& viewer)
_events.clear();
osgViewer::ViewerBase::Contexts contexts;
viewer.getContexts(contexts);
viewer.getContexts(contexts);
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());
}
viewer.getEventQueue()->copyEvents(_events);
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.
osg::ArgumentParser arguments(&argc,argv);
// 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()->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("-f <float>","Field of view of camera");
arguments.getApplicationUsage()->addCommandLineOption("-o <float>","Offset angle of camera");
// construct the viewer.
osgViewer::Viewer viewer;
@ -468,12 +469,12 @@ int main( int argc, char **argv )
ViewerMode viewerMode = STAND_ALONE;
while (arguments.read("-m")) viewerMode = MASTER;
while (arguments.read("-s")) viewerMode = SLAVE;
int socketNumber=8100;
while (arguments.read("-n",socketNumber)) ;
float camera_fov=-1.0f;
while (arguments.read("-f",camera_fov))
while (arguments.read("-f",camera_fov))
{
}
@ -497,7 +498,7 @@ int main( int argc, char **argv )
arguments.writeErrorMessages(std::cout);
return 1;
}
if (arguments.argc()<=1)
{
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
@ -514,13 +515,13 @@ int main( int argc, char **argv )
{
double fovy, aspectRatio, zNear, zFar;
viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0;
std::cout << "setting lens perspective : original "<<original_fov<<" "<<fovy<<std::endl;
fovy = atan(tan(osg::DegreesToRadians(camera_fov)*0.5)/aspectRatio)*2.0;
viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar);
original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0;
std::cout << "setting lens perspective : new "<<original_fov<<" "<<fovy<<std::endl;
@ -549,13 +550,13 @@ int main( int argc, char **argv )
rc.setPort(static_cast<short int>(socketNumber));
bool masterKilled = false;
DataConverter scratchPad(1024);
while( !viewer.done() && !masterKilled )
{
osg::Timer_t startTick = osg::Timer::instance()->tick();
viewer.advance();
// special handling for working as a cluster.
@ -563,12 +564,12 @@ int main( int argc, char **argv )
{
case(MASTER):
{
// take camera zero as the guide.
osg::Matrix modelview(viewer.getCamera()->getViewMatrix());
cp->setPacket(modelview,viewer.getFrameStamp());
cp->readEventQueue(viewer);
scratchPad.reset();
@ -578,11 +579,11 @@ int main( int argc, char **argv )
scratchPad.read(*cp);
bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
std::cout << "bc.sync()"<<scratchPad._numBytes<<std::endl;
bc.sync();
}
break;
case(SLAVE):
@ -591,13 +592,13 @@ int main( int argc, char **argv )
rc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
rc.sync();
scratchPad.reset();
scratchPad.read(*cp);
cp->writeEventQueue(viewer);
if (cp->getMasterKilled())
if (cp->getMasterKilled())
{
std::cout << "Received master killed."<<std::endl;
// 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.
break;
}
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;
// 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;
cp->getModelView(modelview,camera_offset);
viewer.getCamera()->setViewMatrix(modelview);
}
// fire off the cull and draw traversals of the scene.
if(!masterKilled)
viewer.renderingTraversals();
}
// if we are master clean up by telling all slaves that we're going down.
@ -638,7 +639,7 @@ int main( int argc, char **argv )
{
// need to broadcast my death.
cp->setPacket(osg::Matrix::identity(),viewer.getFrameStamp());
cp->setMasterKilled(true);
cp->setMasterKilled(true);
scratchPad.reset();
scratchPad.write(*cp);

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.*/
virtual osg::Matrixd getInverseMatrix() const = 0;
/** update the camera for the current frame, typically called by the viewer classes.
/** update the camera for the current frame, typically called by the viewer classes.
Default implementation simply set the camera view matrix. */
virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
@ -163,6 +163,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
*/
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
/** Handle event. Override the handle(..) method in your event handlers to respond to events. */
virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
/** Handle events, return true if handled, false otherwise. */
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);

View File

@ -29,16 +29,16 @@ class OSGGA_EXPORT Device : public osg::Object
RECEIVE_EVENTS = 1,
SEND_EVENTS = 2
} Capabilities;
Device();
Device(const Device& es, const osg::CopyOp& copyop);
META_Object(osgGA,Device);
int getCapabilities() const { return _capabilities; }
virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; }
virtual void sendEvent(const GUIEventAdapter& ea);
virtual void sendEvent(const Event& ea);
virtual void sendEvents(const EventQueue::Events& events);
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
@ -47,17 +47,17 @@ class OSGGA_EXPORT Device : public osg::Object
protected:
void setCapabilities(int capabilities) { _capabilities = capabilities; }
virtual ~Device();
/** Prevent unwanted copy operator.*/
Device& operator = (const Device&) { return *this; }
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
private:
private:
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);
typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events;
typedef std::list< osg::ref_ptr<Event> > Events;
bool empty() const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
return _eventQueue.empty();
}
/** Set events.*/
void setEvents(Events& events);
@ -57,7 +57,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
void appendEvents(Events& events);
/** Add an event to the end of the event queue.*/
void addEvent(GUIEventAdapter* event);
void addEvent(Event* event);
/** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they
@ -70,7 +70,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
/** Set the graphics context associated with this event queue.*/
void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }

View File

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

View File

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

View File

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

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

View File

@ -254,11 +254,6 @@ public:
void set(osg::Node* model);
virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); }
/** Event traversal node callback method.*/
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void getUsage(osg::ApplicationUsage& usage) const;

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) {}
META_Object(osgViewer,ViewConfig);
/** configure method that is overridden by Config subclasses.*/
virtual void configure(osgViewer::View& /*view*/) const {}
/** convinience method for getting the relavent display settings to use.*/
virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const;
};
@ -129,7 +129,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Get the const View's image pager.*/
const osgDB::ImagePager* getImagePager() const;
/** Add a Device.
* The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
void addDevice(osgGA::Device* eventSource);
@ -167,13 +167,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
void home();
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
typedef std::list< osg::ref_ptr<osgGA::EventHandler> > EventHandlers;
/** Add an EventHandler that adds handling of events to the View.*/
void addEventHandler(osgGA::GUIEventHandler* eventHandler);
void addEventHandler(osgGA::EventHandler* eventHandler);
/** Remove an EventHandler from View.*/
void removeEventHandler(osgGA::GUIEventHandler* eventHandler);
void removeEventHandler(osgGA::EventHandler* eventHandler);
/** Get the View's list of EventHandlers.*/
EventHandlers& getEventHandlers() { return _eventHandlers; }
@ -216,14 +216,14 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
float getFusionDistanceValue() const { return _fusionDistanceValue; }
/** Apply a viewer configuration to set up Cameras and Windowing. */
void apply(ViewConfig* config);
ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
/** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */
void setUpViewAcrossAllScreens();
@ -242,7 +242,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** deprecated. use view.apply(new osgViewer::WoWVxDisplay(type (20 to 42), screenNum). */
void setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C);
/** Convenience method for setting up depth partitioning on the specified camera.*/
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
@ -254,7 +254,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Return true if this view contains a specified camera.*/
bool containsCamera(const osg::Camera* camera) const;
/** deprecated. */
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
@ -264,14 +264,14 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** deprecated. */
bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */
bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray through the specified camera. */
bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
@ -284,7 +284,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
public:
osg::Texture* createDistortionTexture(int width, int height);
osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture);
osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone);
@ -300,7 +300,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
osg::ref_ptr<osg::DisplaySettings> _ds;
double _eyeScale;
};
public:
@ -334,7 +334,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
float _fusionDistanceValue;
osg::ref_ptr<ViewConfig> _lastAppliedViewConfig;
};
}

View File

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

View File

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

View File

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

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());
}
void EventQueue::addEvent(GUIEventAdapter* event)
void EventQueue::addEvent(Event* event)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
_eventQueue.push_back(event);
@ -425,7 +425,7 @@ GUIEventAdapter* EventQueue::touchBegan(unsigned int id, GUIEventAdapter::Touch
event->addTouchPoint(id, phase, x, y, 0);
if(_firstTouchEmulatesMouse)
event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON);
addEvent(event);
return event;
@ -464,7 +464,7 @@ GUIEventAdapter* EventQueue::touchEnded(unsigned int id, GUIEventAdapter::Touch
event->addTouchPoint(id, phase, x, y, tap_count);
if(_firstTouchEmulatesMouse)
event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON);
addEvent(event);
return event;
@ -495,7 +495,7 @@ void EventQueue::frame(double time)
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::FRAME);
event->setTime(time);
// OSG_NOTICE<<"frame("<<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);

View File

@ -28,14 +28,14 @@ EventVisitor::~EventVisitor()
{
}
void EventVisitor::addEvent(GUIEventAdapter* event)
void EventVisitor::addEvent(Event* 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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -967,25 +967,6 @@ double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const
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)
{

View File

@ -257,7 +257,8 @@ void Timeout::traverse(osg::NodeVisitor& nv)
itr != events.end();
++itr)
{
osgGA::GUIEventAdapter* event = itr->get();
osgGA::GUIEventAdapter* event = (*itr)->asGUIEventAdapter();
if (!event) continue;
bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP;

View File

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

View File

@ -270,7 +270,7 @@ void View::init()
void View::setStartTick(osg::Timer_t tick)
{
_startTick = tick;
for(Devices::iterator eitr = _eventSources.begin();
eitr != _eventSources.end();
++eitr)
@ -395,7 +395,7 @@ void View::home()
}
void View::addEventHandler(osgGA::GUIEventHandler* eventHandler)
void View::addEventHandler(osgGA::EventHandler* eventHandler)
{
EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr == _eventHandlers.end())
@ -404,7 +404,7 @@ void View::addEventHandler(osgGA::GUIEventHandler* eventHandler)
}
}
void View::removeEventHandler(osgGA::GUIEventHandler* eventHandler)
void View::removeEventHandler(osgGA::EventHandler* eventHandler)
{
EventHandlers::iterator itr = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);
if (itr != _eventHandlers.end())
@ -846,7 +846,7 @@ void View::requestContinuousUpdate(bool flag)
void View::requestWarpPointer(float x,float y)
{
OSG_INFO<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl;
float local_x, local_y;
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
if (camera)
@ -887,33 +887,33 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext());
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;
double epsilon = 0.5;
// if master camera has graphics context and eventState context matches then assume coordinates refer
// to master camera
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)
{
// OSG_NOTICE<<"Event state matches master"<<std::endl;
const osg::Viewport* viewport = _camera->getViewport();
// rescale mouse x,y first to 0 to 1 range
double new_x = (x-eventState->getXmin())/(eventState->getXmax()-eventState->getXmin());
double new_y = (y-eventState->getYmin())/(eventState->getYmax()-eventState->getYmin());
// flip y if required
if (view_invert_y) new_y = 1.0f-new_y;
// rescale mouse x, y to window dimensions so we can check against master Camera's viewport
new_x *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->width);
new_y *= static_cast<double>(_camera->getGraphicsContext()->getTraits()->height);
if (new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) &&
new_x < (viewport->x()+viewport->width()-1.0+epsilon) && new_y <= (viewport->y()+viewport->height()-1.0+epsilon) )
{
@ -929,7 +929,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
// OSG_NOTICE<<"master camera viewport not matched."<<std::endl;
}
}
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
// convert to non dimensional
@ -990,9 +990,9 @@ bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector
{
float local_x, local_y;
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
OSG_INFO<<"computeIntersections("<<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);
else return false;
}
@ -1001,7 +1001,7 @@ bool View::computeIntersections(float x,float y, const osg::NodePath& nodePath,
{
float 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;
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 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);
}
@ -1031,7 +1031,7 @@ bool View::computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::Nod
{
const osgGA::PointerData* pd = ea.getPointerData(ea.getNumPointerData()-1);
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);
}
@ -1116,7 +1116,7 @@ void View::addDevice(osgGA::Device* eventSource)
{
_eventSources.push_back(eventSource);
}
if (eventSource)
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.
camera->inheritCullSettings(*(view.getCamera()), camera->getInheritanceMask());
if (_eyeScale<0.0)
{
camera->setCullMask(camera->getCullMaskLeft());
@ -1235,7 +1235,7 @@ void View::StereoSlaveCallback::updateSlave(osg::View& view, osg::View::Slave& s
{
camera->setCullMask(camera->getCullMaskRight());
}
// set projection matrix
if (_eyeScale<0.0)
{
@ -1389,7 +1389,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
{
if (!camera || camera->getGraphicsContext()==0) return;
if (!ds->getStereo() && !ds->getKeystoneHint()) return;
ds->setUseSceneViewForStereoHint(false);
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 (ds->getKeystoneHint())
{
while(keystones.size()<2) keystones.push_back(new Keystone);
}
// set up view's main camera
{
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);
}
osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = const_cast<osg::GraphicsContext::Traits*>(camera->getGraphicsContext()->getTraits());
if (!ds->getStereo())
@ -1432,7 +1432,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
osg::ref_ptr<osgViewer::Keystone> keystone = 0;
if (!(ds->getKeystones().empty())) keystone = dynamic_cast<osgViewer::Keystone*>(ds->getKeystones().front().get());
if (!keystone) keystone = new osgViewer::Keystone;
// create distortion texture
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());
// attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
camera->setGraphicsContext(0);
return;
}
switch(ds->getStereoMode())
{
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 right buffer
// one keystone and editing for the one window
if (!keystones.empty())
{
// for keystone:
@ -1484,7 +1484,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// left keystone camera to render to left viewport/window
// right keystone camera to render to right viewport/window
// two keystone, one for each of the left and right viewports/windows
osg::ref_ptr<Keystone> keystone = keystones.front();
// 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.
right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get());
// create Keystone left distortion camera
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.
left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get()));
// create Keystone right distortion camera
osg::ref_ptr<osg::Camera> right_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(),
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->setAllowEventFocus(false);
}
break;
@ -1567,12 +1567,12 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// one keystone and editing for the one window
osg::ref_ptr<Keystone> keystone = keystones.front();
bool useTwoTexture = true;
if (useTwoTexture)
{
// create left distortion texture
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()));
camera->setAllowEventFocus(false);
}
else
{
{
// create distortion texture
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());
distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
// attach Keystone editing event handler.
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
// right keystone camera to render to right viewport/window
// two keystone, one for each of the left and right viewports/windows
osg::ref_ptr<Keystone> left_keystone = keystones[0];
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.
right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get());
// create Keystone left distortion camera
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()));
camera->setAllowEventFocus(false);
}
break;
}
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;
int left_start = (left_eye_bottom_viewport) ? 0 : traits->height/2;
int right_start = (left_eye_bottom_viewport) ? traits->height/2 : 0;
// bottom viewport Camera
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,
@ -1832,7 +1832,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
// attach the texture and use it as the color buffer.
right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get());
// create Keystone left distortion camera
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()));
camera->setAllowEventFocus(false);
}
break;
@ -1910,7 +1910,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
texture.get(), keystone.get());
distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
// attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
}
@ -1960,7 +1960,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
texture.get(), keystone.get());
distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1);
// attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
}
@ -1992,7 +1992,7 @@ void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySetti
camera->addChild(geode.get());
geode->setCullingActive(false);
osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
// set up stencil

View File

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