Skip to content

Commit

Permalink
Introduce new osgGA::Event and osgGA::EventHandler base classes that …
Browse files Browse the repository at this point in the history
…the old GUIEventAdapter and GUIEventHandler now subclass from.

The new osgGA::Event is written to support more generic events than the original GUIEventAdapter which are written for keyboard and mouse events.
  • Loading branch information
robertosfield committed Oct 25, 2013
1 parent 193ee6c commit b683c69
Show file tree
Hide file tree
Showing 37 changed files with 513 additions and 399 deletions.
21 changes: 11 additions & 10 deletions applications/present3D/deprecated/Cluster.cpp
@@ -1,12 +1,12 @@
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/

Expand Down Expand Up @@ -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__)
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -249,7 +250,7 @@ void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer)

//////////////////////////////////////////////////////////////////////////////
//
// Reciever
// Reciever
//
Receiver::Receiver( void )
{
Expand Down Expand Up @@ -338,7 +339,7 @@ void Receiver::sync( void )

#if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ ) || \
defined(__DragonFly__)
socklen_t
socklen_t
#else
int
#endif
Expand Down Expand Up @@ -381,7 +382,7 @@ void Receiver::sync( void )

//////////////////////////////////////////////////////////////////////////////
//
// Broadcaster
// Broadcaster
//
Broadcaster::Broadcaster( void )
{
Expand Down
13 changes: 4 additions & 9 deletions applications/present3D/deprecated/PointsEventHandler.cpp
@@ -1,12 +1,12 @@
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/

Expand Down Expand Up @@ -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");
Expand Down
26 changes: 12 additions & 14 deletions applications/present3D/deprecated/PointsEventHandler.h
@@ -1,12 +1,12 @@
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/

Expand All @@ -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;
Expand Down
18 changes: 6 additions & 12 deletions applications/present3D/deprecated/ShowEventHandler.cpp
@@ -1,12 +1,12 @@
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/

Expand All @@ -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())
{
Expand All @@ -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
{
}
Expand Down
14 changes: 6 additions & 8 deletions applications/present3D/deprecated/ShowEventHandler.h
@@ -1,12 +1,12 @@
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,.
*
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/

Expand All @@ -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;

};

}
Expand Down
39 changes: 15 additions & 24 deletions examples/osganimationtimeline/osganimationtimeline.cpp
@@ -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.
*/

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

};
Expand All @@ -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
Expand All @@ -178,30 +169,30 @@ 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;
}

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);

Expand Down

0 comments on commit b683c69

Please sign in to comment.