From Mathias Froehlich, "Attached is a change to the stats handler so that the aspect ratio of the
viewer stats coordinates always stay about 1:1 to the pixels. This helps for more readable stats with very wide windows for example."
This commit is contained in:
parent
af01a9e984
commit
5d50913722
@ -149,6 +149,7 @@ class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
||||
protected:
|
||||
|
||||
void setUpHUDCamera(osgViewer::ViewerBase* viewer);
|
||||
void setWindowSize(int width, int height);
|
||||
|
||||
osg::Geometry* createBackgroundRectangle(const osg::Vec3& pos, const float width, const float height, osg::Vec4& color);
|
||||
|
||||
|
@ -235,6 +235,9 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::RESIZE):
|
||||
setWindowSize(ea.getWindowWidth(), ea.getWindowHeight());
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@ -315,13 +318,11 @@ void StatsHandler::setUpHUDCamera(osgViewer::ViewerBase* viewer)
|
||||
|
||||
_camera->setGraphicsContext(context);
|
||||
|
||||
_camera->setViewport(0, 0, context->getTraits()->width, context->getTraits()->height);
|
||||
|
||||
_camera->setRenderOrder(osg::Camera::POST_RENDER, 10);
|
||||
|
||||
_camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0,_statsWidth,0.0,_statsHeight));
|
||||
_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
_camera->setViewMatrix(osg::Matrix::identity());
|
||||
setWindowSize(context->getTraits()->width, context->getTraits()->height);
|
||||
|
||||
// only clear the depth buffer
|
||||
_camera->setClearMask(0);
|
||||
@ -331,6 +332,22 @@ void StatsHandler::setUpHUDCamera(osgViewer::ViewerBase* viewer)
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
void StatsHandler::setWindowSize(int width, int height)
|
||||
{
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
|
||||
_camera->setViewport(0, 0, width, height);
|
||||
if (fabs(height*_statsWidth) <= fabs(width*_statsHeight))
|
||||
{
|
||||
_camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0,width*_statsHeight/height,0.0,_statsHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
_camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0,_statsWidth,_statsHeight-height*_statsWidth/width,_statsHeight));
|
||||
}
|
||||
}
|
||||
|
||||
// Drawcallback to draw averaged attribute
|
||||
struct AveragedValueTextDrawCallback : public virtual osg::Drawable::DrawCallback
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user