From 8779fe20a7bd8d056019df66ce71476405aed7f7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 26 Mar 2003 12:50:30 +0000 Subject: [PATCH] Added help support for display help on screen to osgProducer::Viewer. --- Make/makedirdefs | 2 +- examples/osgtexture3D/osgtexture3D.cpp | 4 +- examples/osgviewer/osgviewer.cpp | 2 + include/osg/ApplicationUsage | 12 +- include/osg/Viewport | 7 + include/osgGA/CameraManipulator | 3 + include/osgGA/DriveManipulator | 4 +- include/osgGA/FlightManipulator | 3 +- include/osgGA/TrackballManipulator | 3 +- include/osgProducer/FrameStatsHandler | 7 +- include/osgProducer/OsgCameraGroup | 5 +- include/osgProducer/OsgSceneHandler | 53 ++++- include/osgProducer/ViewerEventHandler | 15 +- src/osg/ApplicationUsage.cpp | 14 +- src/osgProducer/GNUmakefile | 2 +- src/osgProducer/OsgCameraGroup.cpp | 8 +- src/osgProducer/OsgSceneHandler.cpp | 8 +- src/osgProducer/ViewerEventHandler.cpp | 257 ++++++++++++++++++++++++- 18 files changed, 370 insertions(+), 39 deletions(-) diff --git a/Make/makedirdefs b/Make/makedirdefs index 932769e6e..4e17da6c5 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -12,9 +12,9 @@ SRC_DIRS = \ osgDB\ osgGA\ osgParticle\ - osgProducer\ osgText\ osgSim\ + osgProducer\ osgPlugins\ ../examples diff --git a/examples/osgtexture3D/osgtexture3D.cpp b/examples/osgtexture3D/osgtexture3D.cpp index 24919b893..d9315fd12 100644 --- a/examples/osgtexture3D/osgtexture3D.cpp +++ b/examples/osgtexture3D/osgtexture3D.cpp @@ -100,7 +100,7 @@ class ConstructStateCallback : public osgProducer::OsgCameraGroup::RealizeCallba return stateset; } - virtual void operator()(const Producer::RenderSurface&, osgProducer::OsgCameraGroup* , osgProducer::OsgSceneHandler* sh) + virtual void operator()( osgProducer::OsgCameraGroup&, osgProducer::OsgSceneHandler& sh, const Producer::RenderSurface& ) { if (!_initialized) { @@ -111,7 +111,7 @@ class ConstructStateCallback : public osgProducer::OsgCameraGroup::RealizeCallba if (_node) _node->setStateSet(constructState()); } // now safe to con - sh->init(); + sh.init(); } diff --git a/examples/osgviewer/osgviewer.cpp b/examples/osgviewer/osgviewer.cpp index edf9c6a11..0e7e5badc 100644 --- a/examples/osgviewer/osgviewer.cpp +++ b/examples/osgviewer/osgviewer.cpp @@ -20,6 +20,8 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setApplicatonName(arguments.getProgramName()); + arguments.getApplicationUsage()->setDescription(arguments.getProgramName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); diff --git a/include/osg/ApplicationUsage b/include/osg/ApplicationUsage index e42224c19..1257b860f 100644 --- a/include/osg/ApplicationUsage +++ b/include/osg/ApplicationUsage @@ -34,6 +34,13 @@ class SG_EXPORT ApplicationUsage typedef std::map UsageMap; + + void setApplicatonName(const std::string& name) { _applicationName = name; } + const std::string& getApplicatonName() const { return _applicationName; } + + void setDescription(const std::string& desc) { _description = desc; } + const std::string& getDescription() const { return _description; } + enum Type { COMMAND_LINE_OPTION, @@ -63,13 +70,16 @@ class SG_EXPORT ApplicationUsage const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; } + void getFormatedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80); + void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80); void write(std::ostream& output,unsigned int widthOfOutput=80); protected: - + std::string _applicationName; + std::string _description; std::string _commandLineUsage; UsageMap _commandLineOptions; UsageMap _environmentalVariables; diff --git a/include/osg/Viewport b/include/osg/Viewport index 86227ae99..6ed8d5150 100644 --- a/include/osg/Viewport +++ b/include/osg/Viewport @@ -27,6 +27,13 @@ class SG_EXPORT Viewport : public StateAttribute Viewport(); + + Viewport(int x,int y,int width,int height): + _x(x), + _y(y), + _width(width), + _height(height) {} + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ Viewport(const Viewport& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY): diff --git a/include/osgGA/CameraManipulator b/include/osgGA/CameraManipulator index 191a94d7a..252f55214 100644 --- a/include/osgGA/CameraManipulator +++ b/include/osgGA/CameraManipulator @@ -35,6 +35,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler { public: + + virtual const char* className() { return "CameraManipulator"; } + /** Attach a camera to the manipulator to be used for specifying view.*/ virtual void setCamera(osg::Camera*); diff --git a/include/osgGA/DriveManipulator b/include/osgGA/DriveManipulator index 0bd474e3f..74f54bc3e 100644 --- a/include/osgGA/DriveManipulator +++ b/include/osgGA/DriveManipulator @@ -31,8 +31,6 @@ class OSGGA_EXPORT DriveManipulator : public CameraManipulator DriveManipulator(); - virtual ~DriveManipulator(); - virtual const char* className() { return "Drive"; } virtual void setNode(osg::Node*); @@ -52,6 +50,8 @@ class OSGGA_EXPORT DriveManipulator : public CameraManipulator protected: + virtual ~DriveManipulator(); + /** Reset the internal GUIEvent stack.*/ void flushMouseEventStack(); diff --git a/include/osgGA/FlightManipulator b/include/osgGA/FlightManipulator index 99ef38422..8f9b3ab4e 100644 --- a/include/osgGA/FlightManipulator +++ b/include/osgGA/FlightManipulator @@ -30,7 +30,6 @@ class OSGGA_EXPORT FlightManipulator : public CameraManipulator public: FlightManipulator(); - virtual ~FlightManipulator(); virtual const char* className() { return "Flight"; } @@ -59,6 +58,8 @@ class OSGGA_EXPORT FlightManipulator : public CameraManipulator protected: + virtual ~FlightManipulator(); + /** Reset the internal GUIEvent stack.*/ void flushMouseEventStack(); /** Add the current mouse GUIEvent to internal stack.*/ diff --git a/include/osgGA/TrackballManipulator b/include/osgGA/TrackballManipulator index 01d9c0bae..4061663c9 100644 --- a/include/osgGA/TrackballManipulator +++ b/include/osgGA/TrackballManipulator @@ -23,7 +23,6 @@ class OSGGA_EXPORT TrackballManipulator : public CameraManipulator public: TrackballManipulator(); - virtual ~TrackballManipulator(); virtual const char* className() { return "Trackball"; } @@ -54,6 +53,8 @@ class OSGGA_EXPORT TrackballManipulator : public CameraManipulator protected: + virtual ~TrackballManipulator(); + /** Reset the internal GUIEvent stack.*/ void flushMouseEventStack(); /** Add the current mouse GUIEvent to internal stack.*/ diff --git a/include/osgProducer/FrameStatsHandler b/include/osgProducer/FrameStatsHandler index db29c1fd3..e8b86d7b4 100644 --- a/include/osgProducer/FrameStatsHandler +++ b/include/osgProducer/FrameStatsHandler @@ -44,7 +44,12 @@ class FrameStatsHandler : public Producer::CameraGroup::StatsHandler, public Pro { if (!camera.getInstrumentationMode()) return; - glViewport( 0, 0, 1280, 1024 ); + int x,y; + unsigned int width,height; + camera.getProjectionRect(x,y,width,height); + + glViewport( x, y, width, height ); + // Set up the Orthographic view glMatrixMode( GL_PROJECTION ); glPushMatrix(); diff --git a/include/osgProducer/OsgCameraGroup b/include/osgProducer/OsgCameraGroup index 24d375fc4..2165eb824 100644 --- a/include/osgProducer/OsgCameraGroup +++ b/include/osgProducer/OsgCameraGroup @@ -119,7 +119,7 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup class OSGPRODUCER_EXPORT RealizeCallback : public osg::Referenced { public: - virtual void operator()( const Producer::RenderSurface & rs, OsgCameraGroup* cg, OsgSceneHandler* sh) = 0; + virtual void operator()( OsgCameraGroup& cg, OsgSceneHandler& sh, const Producer::RenderSurface & rs) = 0; protected: virtual ~RealizeCallback() {} @@ -133,9 +133,6 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup /** Get the const realize callback.*/ const RealizeCallback* getRealizeCallback() const { return _realizeCallback.get(); } - - - void advance(); diff --git a/include/osgProducer/OsgSceneHandler b/include/osgProducer/OsgSceneHandler index 7d0d7a1a4..5ec38b045 100644 --- a/include/osgProducer/OsgSceneHandler +++ b/include/osgProducer/OsgSceneHandler @@ -30,12 +30,54 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler /// override the init method to force it be run one at a time. virtual void init(); + + + class Callback : public osg::Referenced + { + public: + virtual ~Callback() {} + virtual void operator()(OsgSceneHandler&, const Producer::Camera &) = 0; + }; + + virtual void clear(Producer::Camera& camera) + { + if (_clearCallback.valid()) (*_clearCallback)(*this,camera); + else clearImplementation(camera); + } - virtual void clear(Producer::Camera& camera); + virtual void clearImplementation(Producer::Camera& camera); + + void setClearCallback(Callback* callback) { _clearCallback = callback; } + Callback* getClearCallback() { return _clearCallback.get(); } + const Callback* getClearCallback() const { return _clearCallback.get(); } + + + virtual void cull(Producer::Camera& camera) + { + if (_cullCallback.valid()) (*_cullCallback)(*this,camera); + else cullImplementation(camera); + } + + virtual void cullImplementation(Producer::Camera& camera); + + void setCullCallback(Callback* callback) { _cullCallback = callback; } + Callback* getCullCallback() { return _cullCallback.get(); } + const Callback* getCullCallback() const { return _cullCallback.get(); } + + + virtual void draw(Producer::Camera& camera) + { + if (_drawCallback.valid()) (*_drawCallback)(*this,camera); + else drawImplementation(camera); + } + + virtual void drawImplementation(Producer::Camera& camera); + + void setDrawCallback(Callback* callback) { _drawCallback = callback; } + Callback* getDrawCallback() { return _drawCallback.get(); } + const Callback* getDrawCallback() const { return _drawCallback.get(); } - virtual void cull(Producer::Camera& camera); - virtual void draw(Producer::Camera& camera); void setContextID( int id ); @@ -43,8 +85,13 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler virtual ~OsgSceneHandler() {} + osg::ref_ptr mm; osg::ref_ptr pm; + + osg::ref_ptr _clearCallback; + osg::ref_ptr _cullCallback; + osg::ref_ptr _drawCallback; }; } diff --git a/include/osgProducer/ViewerEventHandler b/include/osgProducer/ViewerEventHandler index 86efb5a36..6e1aadfde 100644 --- a/include/osgProducer/ViewerEventHandler +++ b/include/osgProducer/ViewerEventHandler @@ -23,7 +23,7 @@ class ViewerEventHandler : public osgGA::GUIEventHandler { public: - ViewerEventHandler(osgProducer::OsgCameraGroup* cg); + ViewerEventHandler(OsgCameraGroup* cg); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); @@ -31,12 +31,25 @@ class ViewerEventHandler : public osgGA::GUIEventHandler /** Get the keyboard and mouse usage of this manipulator.*/ virtual void getUsage(osg::ApplicationUsage& usage) const; + + OsgCameraGroup* getOsgCameraGroup() { return _cg; } + const OsgCameraGroup* getOsgCameraGroup() const { return _cg; } + + + void setWriteNodeFileName(const std::string& filename) { _writeNodeFileName = filename; } + const std::string& getWriteNodeFileName() const { return _writeNodeFileName; } + + + void setDisplayHelp(bool displayHelp) { _displayHelp = displayHelp; } + bool getDisplayHelp() const { return _displayHelp; } protected: osgProducer::OsgCameraGroup* _cg; std::string _writeNodeFileName; + + bool _displayHelp; }; } diff --git a/src/osg/ApplicationUsage.cpp b/src/osg/ApplicationUsage.cpp index 201b36a58..2b83c7241 100644 --- a/src/osg/ApplicationUsage.cpp +++ b/src/osg/ApplicationUsage.cpp @@ -45,7 +45,7 @@ void ApplicationUsage::addKeyboardMouseBinding(const std::string& option,const s _keyboardMouse[option]=explanation; } -void ApplicationUsage::write(std::ostream& output, const ApplicationUsage::UsageMap& um,unsigned int widthOfOutput) +void ApplicationUsage::getFormatedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput) { unsigned int maxNumCharsInOptions = 0; ApplicationUsage::UsageMap::const_iterator citr; @@ -125,9 +125,8 @@ void ApplicationUsage::write(std::ostream& output, const ApplicationUsage::Usage } line.replace(explanationPos+offset,explanationWidth, explanation, pos, width); - if (concatinated) output << line << '-' << std::endl; - else output << line << std::endl; - + if (concatinated) { str += line; str += "-\n"; } + else { str += line; str += "\n"; } // move to the next line of output. line.assign(fullWidth,' '); @@ -139,6 +138,13 @@ void ApplicationUsage::write(std::ostream& output, const ApplicationUsage::Usage } } +void ApplicationUsage::write(std::ostream& output, const ApplicationUsage::UsageMap& um,unsigned int widthOfOutput) +{ + std::string str; + getFormatedString(str, um, widthOfOutput); + output << str << std::endl; +} + void ApplicationUsage::write(std::ostream& output,unsigned int widthOfOutput) { diff --git a/src/osgProducer/GNUmakefile b/src/osgProducer/GNUmakefile index e5057f3a0..81bec2d6b 100644 --- a/src/osgProducer/GNUmakefile +++ b/src/osgProducer/GNUmakefile @@ -10,7 +10,7 @@ CXXFILES =\ ViewerEventHandler.cpp\ Viewer.cpp\ -LIBS += -lProducer $(GL_LIBS) -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS) +LIBS += -lProducer $(GL_LIBS) -losgText -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS) DEF += -DOSGPRODUCER_LIBRARY INC += -I/usr/X11R6/include TARGET_BASENAME = osgProducer diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index 628bc1515..5f3b48ef9 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -33,13 +33,9 @@ public: virtual void operator()( const Producer::RenderSurface & rs) { - if (_cameraGroup) + if (_cameraGroup->getRealizeCallback()) { - if (_cameraGroup->getRealizeCallback()) - { - (*(_cameraGroup->getRealizeCallback()))(rs,_cameraGroup,_sceneHandler); - } - else if (_sceneHandler) _sceneHandler->init(); + (*(_cameraGroup->getRealizeCallback()))(*_cameraGroup,*_sceneHandler,rs); } else if (_sceneHandler) _sceneHandler->init(); } diff --git a/src/osgProducer/OsgSceneHandler.cpp b/src/osgProducer/OsgSceneHandler.cpp index 15e018222..e6926389d 100644 --- a/src/osgProducer/OsgSceneHandler.cpp +++ b/src/osgProducer/OsgSceneHandler.cpp @@ -38,12 +38,12 @@ void OsgSceneHandler::init() osg::notify(osg::INFO)<<" unlocked "<set(cam.getProjectionMatrix()); @@ -60,7 +60,7 @@ void OsgSceneHandler::cull(Producer::Camera &cam) SceneView::cull(); } -void OsgSceneHandler::draw(Producer::Camera &) +void OsgSceneHandler::drawImplementation(Producer::Camera &) { SceneView::draw(); } diff --git a/src/osgProducer/ViewerEventHandler.cpp b/src/osgProducer/ViewerEventHandler.cpp index f461f54ea..f3f794a5b 100644 --- a/src/osgProducer/ViewerEventHandler.cpp +++ b/src/osgProducer/ViewerEventHandler.cpp @@ -1,12 +1,256 @@ #include #include +#include using namespace osgProducer; -ViewerEventHandler::ViewerEventHandler(osgProducer::OsgCameraGroup* cg): - _cg(cg), - _writeNodeFileName("savedmodel.osg") +class DrawHelpCallback : public Producer::Camera::Callback { +public: + + DrawHelpCallback(ViewerEventHandler* veh): + _veh(veh), + _initialized(false) + { + } + + virtual void operator()( const Producer::Camera & camera) + { + + if (_veh->getDisplayHelp()) + { + if (!_initialized) createText(); + + OsgSceneHandler* osh = _veh->getOsgCameraGroup()->getSceneHandlerList()[0].get(); + + int x,y; + unsigned int width,height; + camera.getProjectionRect(x,y,width,height); + _viewport->setViewport(x,y,width,height); + + // should possibly update _viewport... + + // Set up the Orthographic view + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + glOrtho( 0.0, 1280.0, 0.0, 1024, -1.0, 1.0 ); + + glPushAttrib( GL_ENABLE_BIT ); + glDisable( GL_LIGHTING ); + glDisable( GL_DEPTH_TEST ); + glEnable( GL_BLEND ); + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glLoadIdentity(); + + osh->getState()->pushStateSet(_stateset.get()); + + for(TextList::iterator ditr=_descriptionList.begin(); + ditr!=_descriptionList.end(); + ++ditr) + { + (*ditr)->draw(*(osh->getState())); + } + + for(TextList::iterator oitr=_optionList.begin(); + oitr!=_optionList.end(); + ++oitr) + { + (*oitr)->draw(*(osh->getState())); + } + + for(TextList::iterator eitr=_explanationList.begin(); + eitr!=_explanationList.end(); + ++eitr) + { + (*eitr)->draw(*(osh->getState())); + } + + osh->getState()->popStateSet(); + + glPopMatrix(); + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + + glPopAttrib(); + + } + + } + + void createText() + { + _stateset = new osg::StateSet; + _viewport = new osg::Viewport(0,0,1280,1024); + _stateset->setAttribute(_viewport.get()); + + OsgCameraGroup* ocg = _veh->getOsgCameraGroup(); + if (ocg->getApplicationUsage()) + { + + const osg::ApplicationUsage::UsageMap& um = ocg->getApplicationUsage()->getKeyboardMouseBindings(); + + float maxWidthOfDisplayRegion = 1200.0f; + float bottomOfDescription = 1000.0f; + osg::Vec3 posDescription(0.0f,bottomOfDescription,0.0f); + osg::Vec4 colorDescription(1.0f,1.0f,0.0f,1.0f); + float characterSize = 20.0f; + + if (!(ocg->getApplicationUsage()->getDescription()).empty()) + { + osgText::Text* text = new osgText::Text; + text->setFont("fonts/arial.ttf"); + text->setColor(colorDescription); + text->setCharacterSize(characterSize); + text->setPosition(posDescription); + text->setMaximumWidth(maxWidthOfDisplayRegion); + text->setAlignment(osgText::Text::BASE_LINE); + text->setText(ocg->getApplicationUsage()->getDescription()); + + bottomOfDescription = text->getBound().yMin()-characterSize*2.0f; + + _descriptionList.push_back(text); + + } + + osg::Vec3 posOption(0.0f,bottomOfDescription,0.0f); + osg::Vec4 colorOption(1.0f,1.0f,0.0f,1.0f); + float maxX = 0.0f; + + // create option strings. + osg::ApplicationUsage::UsageMap::const_iterator citr; + for(citr=um.begin(); + citr!=um.end(); + ++citr) + { + osgText::Text* text = new osgText::Text; + text->setFont("fonts/arial.ttf"); + text->setColor(colorOption); + text->setCharacterSize(characterSize); + text->setPosition(posOption); + text->setAlignment(osgText::Text::BASE_LINE); + text->setText(citr->first); + + if (text->getBound().xMax()>maxX) maxX=text->getBound().xMax(); + + _optionList.push_back(text); + + } + + osg::Vec3 posExplanation(maxX+characterSize,bottomOfDescription,0.0f); + osg::Vec4 colorExplanation(1.0f,1.0f,0.0f,1.0f); + float maxWidth = maxWidthOfDisplayRegion-maxX; + + TextList::iterator oitr; + TextList::iterator eitr; + TextList::iterator ditr; + + for(citr=um.begin(), oitr=_optionList.begin(); + citr!=um.end(); + ++citr,++oitr) + { + osgText::Text* text = new osgText::Text; + text->setFont("fonts/arial.ttf"); + text->setColor(colorExplanation); + text->setCharacterSize(characterSize); + text->setPosition(posExplanation); + text->setMaximumWidth(maxWidth); + text->setAlignment(osgText::Text::BASE_LINE); + text->setText(citr->second); + + if (text->getBound().xMax()>maxX) maxX=text->getBound().xMax(); + + // fix the position of option text to be the same height as the examplanation. + osg::Vec3 pos((*oitr)->getPosition()); + (*oitr)->setPosition(osg::Vec3(pos.x(),posExplanation.y(),pos.z())); + + posExplanation.y() = text->getBound().yMin()-characterSize; + + _explanationList.push_back(text); + + } + + // compute the boundings of the all the text. + osg::BoundingBox bb; + for(ditr=_descriptionList.begin(); + ditr!=_descriptionList.end(); + ++ditr) + { + bb.expandBy((*ditr)->getBound()); + } + + for(oitr=_optionList.begin(); + oitr!=_optionList.end(); + ++oitr) + { + bb.expandBy((*oitr)->getBound()); + } + + for(eitr=_explanationList.begin(); + eitr!=_explanationList.end(); + ++eitr) + { + bb.expandBy((*eitr)->getBound()); + } + + float totalWidth = bb.xMax()-bb.xMin(); + float totalHeight = bb.yMax()-bb.yMin(); + float widthMargin = (1280.0f-totalWidth)*0.5f; + float heightMargin = (1024.0f-totalHeight)*0.5f; + + osg::Vec3 delta(widthMargin-bb.xMin(),heightMargin-bb.yMin(),0.0f); + + // shift the text to center it. + for(ditr=_descriptionList.begin(); + ditr!=_descriptionList.end(); + ++ditr) + { + (*ditr)->setPosition((*ditr)->getPosition()+delta); + } + + for(oitr=_optionList.begin(); + oitr!=_optionList.end(); + ++oitr) + { + (*oitr)->setPosition((*oitr)->getPosition()+delta); + } + + for(eitr=_explanationList.begin(); + eitr!=_explanationList.end(); + ++eitr) + { + (*eitr)->setPosition((*eitr)->getPosition()+delta); + } + + + } + _initialized = true; + } + + ViewerEventHandler* _veh; + bool _initialized; + + osg::ref_ptr _stateset; + osg::ref_ptr _viewport; + + typedef std::vector< osg::ref_ptr > TextList; + TextList _descriptionList; + TextList _optionList; + TextList _explanationList; +}; + + +ViewerEventHandler::ViewerEventHandler(OsgCameraGroup* cg): + _cg(cg), + _writeNodeFileName("savedmodel.osg"), + _displayHelp(false) +{ + Producer::CameraConfig* cfg = _cg->getCameraConfig(); + Producer::Camera *cam = cfg->getCamera(0); + cam->addPostDrawCallback(new DrawHelpCallback(this)); } bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) @@ -46,10 +290,7 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio case '/' : case '?' : { - if (_cg->getApplicationUsage()) - { - _cg->getApplicationUsage()->write(std::cout,_cg->getApplicationUsage()->getKeyboardMouseBindings()); - } + setDisplayHelp(!getDisplayHelp()); return true; } @@ -71,4 +312,6 @@ void ViewerEventHandler::accept(osgGA::GUIEventHandlerVisitor& gehv) void ViewerEventHandler::getUsage(osg::ApplicationUsage& usage) const { usage.addKeyboardMouseBinding("f","Toggle fullscreen"); + usage.addKeyboardMouseBinding("?","Display help"); + usage.addKeyboardMouseBinding("o","Write scene graph to file"); }