Added keyboard mouse binding usage to the osg::ApplicationUsage and

osgGA::GUIEventHandler and its subclasses.
This commit is contained in:
Robert Osfield
2003-02-19 10:43:02 +00:00
parent 73f741d16f
commit 0d3f78350a
20 changed files with 202 additions and 39 deletions

View File

@@ -1,6 +1,15 @@
//C++ source file - Open Producer - Copyright (C) 2002 Don Burns
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
//as published by the Free Software Foundation.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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 <osg/ArgumentParser>
#include <osg/ApplicationUsage>
@@ -21,12 +30,16 @@ int main( int argc, char **argv )
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ...");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
// construct the viewer.
osgProducer::Viewer viewer(arguments);
// set up the value with sensible default event handlers.
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
// get details on keyboard and mouse bindings used by the viewer.
viewer.getUsage(*arguments.getApplicationUsage());
// if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help"))
{

View File

@@ -83,6 +83,11 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU
return retval;
}
void AnimationPathManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("AnimationPath: Space","Reset the viewing position to start of animation");
}
void AnimationPathManipulator::handleFrame( double time )
{
osg::AnimationPath::ControlPoint cp;

View File

@@ -164,7 +164,6 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
computeLocalDataFromCamera();
}
void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
flushMouseEventStack();
@@ -360,6 +359,15 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
}
}
void DriveManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("Drive: Space","Reset the viewing position to home");
usage.addKeyboardMouseBinding("Drive: +","When in stereo, increase the fusion distance");
usage.addKeyboardMouseBinding("Drive: -","When in stereo, reduse the fusion distance");
usage.addKeyboardMouseBinding("Drive: q","Use mouse y for controlling speed");
usage.addKeyboardMouseBinding("Drive: a","Use mouse middle,right mouse buttons for speed");
}
void DriveManipulator::flushMouseEventStack()
{

View File

@@ -175,6 +175,14 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
}
}
void FlightManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("Flight: Space","Reset the viewing position to home");
usage.addKeyboardMouseBinding("Flight: +","When in stereo, increase the fusion distance");
usage.addKeyboardMouseBinding("Flight: -","When in stereo, reduse the fusion distance");
usage.addKeyboardMouseBinding("Flight: q","Automatically yaw when banked (default)");
usage.addKeyboardMouseBinding("Flight: a","No yaw when banked");
}
void FlightManipulator::flushMouseEventStack()
{

View File

@@ -2,6 +2,16 @@
using namespace osgGA;
void CompositeGUIEventHandler::getUsage(osg::ApplicationUsage& usage) const
{
for (ChildList::const_iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->getUsage(usage);
}
}
bool CompositeGUIEventHandler::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
bool result=false;

View File

@@ -18,7 +18,7 @@ void KeySwitchCameraManipulator::addCameraManipulator(int key, std::string name,
void KeySwitchCameraManipulator::addNumberedCameraManipulator(CameraManipulator *cm)
{
if(!cm) return;
addCameraManipulator('1'+_manips.size(),"camera",cm);
addCameraManipulator('1'+_manips.size(),cm->className(),cm);
}
void KeySwitchCameraManipulator::selectCameraManipulator(unsigned int num)
@@ -61,3 +61,18 @@ bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapt
return _current->handle(ea,aa);
}
void KeySwitchCameraManipulator::getUsage(osg::ApplicationUsage& usage) const
{
for(KeyManipMap::const_iterator itr=_manips.begin();
itr!=_manips.end();
++itr)
{
string key; key += (char)(itr->first);
string explanation(std::string("Select '")+itr->second.first+std::string("' camera manipulator"));
if (_current==itr->second.second) explanation += " (default)";
usage.addKeyboardMouseBinding(key,explanation);
itr->second.second->getUsage(usage);
}
}

View File

@@ -67,6 +67,13 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
return false;
}
void StateSetManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("b","Toggle backface culling");
usage.addKeyboardMouseBinding("l","Toggle lighting");
usage.addKeyboardMouseBinding("t","Toggle texturing");
}
void StateSetManipulator::accept(GUIEventHandlerVisitor& gehv)
{
gehv.visit(*this);

View File

@@ -69,6 +69,14 @@ void TrackballManipulator::init(const GUIEventAdapter& ,GUIActionAdapter& )
computeLocalDataFromCamera();
}
void TrackballManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("Trackball: Space","Reset the viewing position to home");
usage.addKeyboardMouseBinding("Trackball: +","When in stereo, increase the fusion distance");
usage.addKeyboardMouseBinding("Trackball: -","When in stereo, reduse the fusion distance");
}
bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(!_camera.get()) return false;

View File

@@ -6,6 +6,7 @@ CXXFILES =\
EventAdapter.cpp\
KeyboardMouseCallback.cpp\
SceneHandler.cpp\
StatsEventHandler.cpp\
Viewer.cpp\
LIBS += -lProducer $(GL_LIBS) -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS)

View File

@@ -0,0 +1,41 @@
#include <osgProducer/StatsEventHandler>
using namespace osgProducer;
bool StatsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
{
if(!_cg) return false;
if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN)
{
switch( ea.getKey() )
{
case 's' :
_cg->setInstrumentationMode(!_cg->getInstrumentationMode());
return true;
case 'v' :
_cg->setBlockOnVsync(!_cg->getBlockOnVsync());
//std::cout<<"_cg->getBlockOnVsync()="<<_cg->getBlockOnVsync()<<std::endl;
return true;
default:
break;
}
}
return false;
}
void StatsEventHandler::accept(osgGA::GUIEventHandlerVisitor& gehv)
{
gehv.visit(*this);
}
void StatsEventHandler::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("s","Toggle intrumention");
usage.addKeyboardMouseBinding("v","Toggle block and vsync");
}

View File

@@ -241,3 +241,12 @@ void Viewer::requestWarpPointer(int x,int y)
}
void Viewer::getUsage(osg::ApplicationUsage& usage) const
{
for(EventHandlerList::const_iterator itr=_eventHandlerList.begin();
itr!=_eventHandlerList.end();
++itr)
{
(*itr)->getUsage(usage);
}
}