Added help support for display help on screen to osgProducer::Viewer.
This commit is contained in:
parent
e00b8f2868
commit
8779fe20a7
@ -12,9 +12,9 @@ SRC_DIRS = \
|
||||
osgDB\
|
||||
osgGA\
|
||||
osgParticle\
|
||||
osgProducer\
|
||||
osgText\
|
||||
osgSim\
|
||||
osgProducer\
|
||||
osgPlugins\
|
||||
../examples
|
||||
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -34,6 +34,13 @@ class SG_EXPORT ApplicationUsage
|
||||
|
||||
typedef std::map<std::string,std::string> 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;
|
||||
|
@ -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):
|
||||
|
@ -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*);
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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.*/
|
||||
|
@ -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.*/
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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<osg::RefMatrix> mm;
|
||||
osg::ref_ptr<osg::RefMatrix> pm;
|
||||
|
||||
osg::ref_ptr<Callback> _clearCallback;
|
||||
osg::ref_ptr<Callback> _cullCallback;
|
||||
osg::ref_ptr<Callback> _drawCallback;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ void OsgSceneHandler::init()
|
||||
osg::notify(osg::INFO)<<" unlocked "<<this<<" init."<<std::endl;
|
||||
}
|
||||
|
||||
void OsgSceneHandler::clear(Producer::Camera& /*camera*/)
|
||||
void OsgSceneHandler::clearImplementation(Producer::Camera& /*camera*/)
|
||||
{
|
||||
// no-op right now as scene view manages its own cleaer.
|
||||
// no-op right now as scene view manages its own clear.
|
||||
}
|
||||
|
||||
void OsgSceneHandler::cull(Producer::Camera &cam)
|
||||
void OsgSceneHandler::cullImplementation(Producer::Camera &cam)
|
||||
{
|
||||
|
||||
pm->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();
|
||||
}
|
||||
|
@ -1,12 +1,256 @@
|
||||
#include <osgProducer/ViewerEventHandler>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgText/Text>
|
||||
|
||||
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<osg::StateSet> _stateset;
|
||||
osg::ref_ptr<osg::Viewport> _viewport;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osgText::Text> > 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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user