From 0d3f78350a38982fb0876f8b41491fe9593be76e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 19 Feb 2003 10:43:02 +0000 Subject: [PATCH] Added keyboard mouse binding usage to the osg::ApplicationUsage and osgGA::GUIEventHandler and its subclasses. --- include/osgGA/AnimationPathManipulator | 4 ++ include/osgGA/DriveManipulator | 5 ++ include/osgGA/FlightManipulator | 5 ++ include/osgGA/GUIEventHandler | 18 +++++-- include/osgGA/KeySwitchCameraManipulator | 5 ++ include/osgGA/StateSetManipulator | 5 ++ include/osgGA/TrackballManipulator | 6 ++- include/osgProducer/StatsEventHandler | 56 +++++++++----------- include/osgProducer/Viewer | 2 + src/Demos/osgproducer/osgproducer_viewer.cpp | 19 +++++-- src/osgGA/AnimationPathManipulator.cpp | 5 ++ src/osgGA/DriveManipulator.cpp | 10 +++- src/osgGA/FlightManipulator.cpp | 8 +++ src/osgGA/GUIEventHandler.cpp | 10 ++++ src/osgGA/KeySwitchCameraManipulator.cpp | 17 +++++- src/osgGA/StateSetManipulator.cpp | 7 +++ src/osgGA/TrackballManipulator.cpp | 8 +++ src/osgProducer/Makefile | 1 + src/osgProducer/StatsEventHandler.cpp | 41 ++++++++++++++ src/osgProducer/Viewer.cpp | 9 ++++ 20 files changed, 202 insertions(+), 39 deletions(-) create mode 100644 src/osgProducer/StatsEventHandler.cpp diff --git a/include/osgGA/AnimationPathManipulator b/include/osgGA/AnimationPathManipulator index 9dfdceb7e..2d6cc560e 100644 --- a/include/osgGA/AnimationPathManipulator +++ b/include/osgGA/AnimationPathManipulator @@ -39,6 +39,7 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator AnimationPathManipulator( const std::string& filename ); + virtual const char* className() const { return "AnimationPath"; } void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; } @@ -53,6 +54,9 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator void home(const GUIEventAdapter& ea,GUIActionAdapter& us); virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); + + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; private: diff --git a/include/osgGA/DriveManipulator b/include/osgGA/DriveManipulator index 8eb508fd9..0bd474e3f 100644 --- a/include/osgGA/DriveManipulator +++ b/include/osgGA/DriveManipulator @@ -33,6 +33,8 @@ class OSGGA_EXPORT DriveManipulator : public CameraManipulator virtual ~DriveManipulator(); + virtual const char* className() { return "Drive"; } + virtual void setNode(osg::Node*); virtual const osg::Node* getNode() const; @@ -45,6 +47,9 @@ class OSGGA_EXPORT DriveManipulator : public CameraManipulator virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + protected: /** Reset the internal GUIEvent stack.*/ diff --git a/include/osgGA/FlightManipulator b/include/osgGA/FlightManipulator index 8351c58c1..99ef38422 100644 --- a/include/osgGA/FlightManipulator +++ b/include/osgGA/FlightManipulator @@ -32,6 +32,8 @@ class OSGGA_EXPORT FlightManipulator : public CameraManipulator FlightManipulator(); virtual ~FlightManipulator(); + virtual const char* className() { return "Flight"; } + virtual void setNode(osg::Node*); virtual const osg::Node* getNode() const; @@ -44,6 +46,9 @@ class OSGGA_EXPORT FlightManipulator : public CameraManipulator virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + enum YawControlMode { YAW_AUTOMATICALLY_WHEN_BANKED, NO_AUTOMATIC_YAW diff --git a/include/osgGA/GUIEventHandler b/include/osgGA/GUIEventHandler index e8cd108e2..5362a2ab4 100644 --- a/include/osgGA/GUIEventHandler +++ b/include/osgGA/GUIEventHandler @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -49,8 +50,7 @@ class OSGGA_EXPORT GUIEventHandler : public osg::Referenced { public: - /** Handle events, return true if handled, false otherwise. */ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us)=0; + virtual const char* className() { return "GUIEventHandler"; } /** Returns 0 if this GUIEventHandler is not a CompositeGUIEventHandler. */ virtual const CompositeGUIEventHandler* getComposite() const { return 0; } @@ -58,8 +58,14 @@ public: /** Returns 0 if this GUIEventHandler is not a CompositeGUIEventHandler. */ virtual CompositeGUIEventHandler* getComposite() { return 0; } + /** Handle events, return true if handled, false otherwise. */ + virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us)=0; + /** Accept visits from GUIEventHandler visitors */ virtual void accept(GUIEventHandlerVisitor&) = 0; + + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage&) const {} }; @@ -73,14 +79,20 @@ public: typedef std::vector< osg::ref_ptr > ChildList; - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa); + virtual const char* className() { return "CompositeGUIEventHandler"; } virtual const CompositeGUIEventHandler* getComposite() const { return this; } virtual CompositeGUIEventHandler* getComposite() { return this; } + virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa); + virtual void accept(GUIEventHandlerVisitor& v) { v.visit(*this); } + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + + // Composite-specific methods below virtual bool addChild(GUIEventHandler *geh); diff --git a/include/osgGA/KeySwitchCameraManipulator b/include/osgGA/KeySwitchCameraManipulator index a7490e3b5..804065074 100644 --- a/include/osgGA/KeySwitchCameraManipulator +++ b/include/osgGA/KeySwitchCameraManipulator @@ -34,6 +34,8 @@ class OSGGA_EXPORT KeySwitchCameraManipulator : public CameraManipulator { public: + virtual const char* className() { return "KeySwitchCamera"; } + /** Add a camera manipulator with an associated name, and a key to trigger the switch, @@ -75,6 +77,9 @@ public: virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + private: typedef std::pair > NamedManipulator; diff --git a/include/osgGA/StateSetManipulator b/include/osgGA/StateSetManipulator index 6241c8f4a..33781ded3 100644 --- a/include/osgGA/StateSetManipulator +++ b/include/osgGA/StateSetManipulator @@ -34,6 +34,8 @@ public: StateSetManipulator(); virtual ~StateSetManipulator(); + virtual const char* className() { return "StateSetManipulator"; } + /** attach a geostate to the manipulator to be used for specifying view.*/ virtual void setStateSet(osg::StateSet*); @@ -49,6 +51,9 @@ public: /** Handle visitations */ virtual void accept(GUIEventHandlerVisitor&); + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + protected: // Reference pointer to a geostate diff --git a/include/osgGA/TrackballManipulator b/include/osgGA/TrackballManipulator index c58a0641f..01d9c0bae 100644 --- a/include/osgGA/TrackballManipulator +++ b/include/osgGA/TrackballManipulator @@ -25,6 +25,8 @@ class OSGGA_EXPORT TrackballManipulator : public CameraManipulator TrackballManipulator(); virtual ~TrackballManipulator(); + virtual const char* className() { return "Trackball"; } + /** Attach a node to the manipulator. Automatically detaches previously attached node. setNode(NULL) detaches previously nodes. @@ -44,10 +46,12 @@ class OSGGA_EXPORT TrackballManipulator : public CameraManipulator /** Start/restart the manipulator.*/ virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us); - /** handle events, return true if handled, false otherwise.*/ virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + protected: /** Reset the internal GUIEvent stack.*/ diff --git a/include/osgProducer/StatsEventHandler b/include/osgProducer/StatsEventHandler index c79fb9ace..e45c76e3e 100644 --- a/include/osgProducer/StatsEventHandler +++ b/include/osgProducer/StatsEventHandler @@ -1,6 +1,23 @@ +/* -*-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. +*/ + +#ifndef OSGPRODUCER_STATSEVENTHANDLER +#define OSGPRODUCER_STATSEVENTHANDLER 1 #include -#include +#include + +namespace osgProducer { class StatsEventHandler : public osgGA::GUIEventHandler { @@ -8,39 +25,18 @@ class StatsEventHandler : public osgGA::GUIEventHandler StatsEventHandler(osgProducer::Viewer* cg):_cg(cg) {} - virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) - { - if(!_cg) return false; + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); - if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN) - { + virtual void accept(osgGA::GUIEventHandlerVisitor& gehv); - switch( ea.getKey() ) - { - case 's' : - _cg->setInstrumentationMode(!_cg->getInstrumentationMode()); - return true; - - case 'v' : - _cg->setBlockOnVsync(!_cg->getBlockOnVsync()); - //std::cout<<"_cg->getBlockOnVsync()="<<_cg->getBlockOnVsync()< #include @@ -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")) { diff --git a/src/osgGA/AnimationPathManipulator.cpp b/src/osgGA/AnimationPathManipulator.cpp index ac0ef6c52..194baf617 100644 --- a/src/osgGA/AnimationPathManipulator.cpp +++ b/src/osgGA/AnimationPathManipulator.cpp @@ -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; diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index 115b05d51..1d6d801bd 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -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() { diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index e27c49752..2c78dad77 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -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() { diff --git a/src/osgGA/GUIEventHandler.cpp b/src/osgGA/GUIEventHandler.cpp index 962da7607..c59d151bb 100644 --- a/src/osgGA/GUIEventHandler.cpp +++ b/src/osgGA/GUIEventHandler.cpp @@ -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; diff --git a/src/osgGA/KeySwitchCameraManipulator.cpp b/src/osgGA/KeySwitchCameraManipulator.cpp index fd3d736ff..eb21de05a 100644 --- a/src/osgGA/KeySwitchCameraManipulator.cpp +++ b/src/osgGA/KeySwitchCameraManipulator.cpp @@ -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); + } +} diff --git a/src/osgGA/StateSetManipulator.cpp b/src/osgGA/StateSetManipulator.cpp index d15afb3af..50b3f0edf 100644 --- a/src/osgGA/StateSetManipulator.cpp +++ b/src/osgGA/StateSetManipulator.cpp @@ -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); diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index 7515d5eaa..c55830e4c 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -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; diff --git a/src/osgProducer/Makefile b/src/osgProducer/Makefile index 35d930412..6025a4a61 100644 --- a/src/osgProducer/Makefile +++ b/src/osgProducer/Makefile @@ -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) diff --git a/src/osgProducer/StatsEventHandler.cpp b/src/osgProducer/StatsEventHandler.cpp new file mode 100644 index 000000000..d31a713f5 --- /dev/null +++ b/src/osgProducer/StatsEventHandler.cpp @@ -0,0 +1,41 @@ +#include + +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()<getUsage(usage); + } +}