Added support for sorting the graphics contexts so that the first context/window
returned from Viewer::getContexts/getWindows will be the left most window on the lowest screen number. Added ability for StatsHandler and HelpHandler to support end users setting their Camera's graphics context.
This commit is contained in:
@@ -33,6 +33,11 @@ class OSGVIEWER_EXPORT HelpHandler : public osgGA::GUIEventHandler
|
||||
void setKeyEventTogglesOnScreenHelp(int key) { _keyEventTogglesOnScreenHelp = key; }
|
||||
int getKeyEventTogglesOnScreenHelp() const { return _keyEventTogglesOnScreenHelp; }
|
||||
|
||||
void reset();
|
||||
|
||||
osg::Camera* getCamera() { return _camera.get(); }
|
||||
const osg::Camera* getCamera() const { return _camera.get(); }
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
@@ -49,6 +54,8 @@ class OSGVIEWER_EXPORT HelpHandler : public osgGA::GUIEventHandler
|
||||
int _keyEventTogglesOnScreenHelp;
|
||||
|
||||
bool _helpEnabled;
|
||||
|
||||
bool _initialized;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::ref_ptr<osg::Switch> _switch;
|
||||
|
||||
|
||||
@@ -41,10 +41,15 @@ class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
||||
void setKeyEventPrintsOutStats(int key) { _keyEventPrintsOutStats = key; }
|
||||
int getKeyEventPrintsOutStats() const { return _keyEventPrintsOutStats; }
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
double getBlockMultiplier() const { return _blockMultiplier; }
|
||||
|
||||
void reset();
|
||||
|
||||
osg::Camera* getCamera() { return _camera.get(); }
|
||||
const osg::Camera* getCamera() const { return _camera.get(); }
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
@@ -68,7 +73,10 @@ class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
||||
int _keyEventPrintsOutStats;
|
||||
|
||||
int _statsType;
|
||||
|
||||
bool _initialized;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
osg::ref_ptr<osg::Switch> _switch;
|
||||
|
||||
osgViewer::Viewer::ThreadingModel _threadingModel;
|
||||
|
||||
@@ -22,8 +22,10 @@ using namespace osgViewer;
|
||||
HelpHandler::HelpHandler(osg::ApplicationUsage* au):
|
||||
_applicationUsage(au),
|
||||
_keyEventTogglesOnScreenHelp('h'),
|
||||
_helpEnabled(false)
|
||||
_helpEnabled(false),
|
||||
_initialized(false)
|
||||
{
|
||||
_camera = new osg::Camera;
|
||||
}
|
||||
|
||||
bool HelpHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
||||
@@ -37,7 +39,7 @@ bool HelpHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt
|
||||
{
|
||||
if (ea.getKey()==_keyEventTogglesOnScreenHelp)
|
||||
{
|
||||
if (!_camera.valid())
|
||||
if (!_initialized)
|
||||
{
|
||||
setUpHUDCamera(viewer);
|
||||
setUpScene(viewer);
|
||||
@@ -84,6 +86,8 @@ void HelpHandler::setUpHUDCamera(osgViewer::Viewer* viewer)
|
||||
_camera->setClearMask(0);
|
||||
|
||||
viewer->setUpRenderingSupport();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
void HelpHandler::setUpScene(osgViewer::Viewer* viewer)
|
||||
|
||||
@@ -22,6 +22,7 @@ StatsHandler::StatsHandler():
|
||||
_keyEventTogglesOnScreenStats('s'),
|
||||
_keyEventPrintsOutStats('S'),
|
||||
_statsType(NO_STATS),
|
||||
_initialized(false),
|
||||
_threadingModel(osgViewer::Viewer::SingleThreaded),
|
||||
_frameRateChildNum(0),
|
||||
_viewerChildNum(0),
|
||||
@@ -29,6 +30,7 @@ StatsHandler::StatsHandler():
|
||||
_numBlocks(8),
|
||||
_blockMultiplier(10000.0)
|
||||
{
|
||||
_camera = new osg::Camera;
|
||||
}
|
||||
|
||||
bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
||||
@@ -50,7 +52,7 @@ bool StatsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdap
|
||||
{
|
||||
if (viewer->getStats())
|
||||
{
|
||||
if (!_camera.valid())
|
||||
if (!_initialized)
|
||||
{
|
||||
setUpHUDCamera(viewer);
|
||||
setUpScene(viewer);
|
||||
@@ -184,17 +186,28 @@ void StatsHandler::updateThreadingModelText()
|
||||
}
|
||||
}
|
||||
|
||||
void StatsHandler::reset()
|
||||
{
|
||||
_initialized = false;
|
||||
_camera->setGraphicsContext(0);
|
||||
}
|
||||
|
||||
void StatsHandler::setUpHUDCamera(osgViewer::Viewer* viewer)
|
||||
{
|
||||
osgViewer::Viewer::Windows windows;
|
||||
viewer->getWindows(windows);
|
||||
osgViewer::GraphicsWindow* window = dynamic_cast<osgViewer::GraphicsWindow*>(_camera->getGraphicsContext());
|
||||
|
||||
if (windows.empty()) return;
|
||||
if (!window)
|
||||
{
|
||||
osgViewer::Viewer::Windows windows;
|
||||
viewer->getWindows(windows);
|
||||
|
||||
osgViewer::GraphicsWindow* window = windows.front();
|
||||
if (windows.empty()) return;
|
||||
|
||||
window = windows.front();
|
||||
|
||||
_camera->setGraphicsContext(window);
|
||||
}
|
||||
|
||||
_camera = new osg::Camera;
|
||||
_camera->setGraphicsContext(window);
|
||||
_camera->setViewport(0, 0, window->getTraits()->width, window->getTraits()->height);
|
||||
|
||||
_camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
||||
@@ -205,6 +218,8 @@ void StatsHandler::setUpHUDCamera(osgViewer::Viewer* viewer)
|
||||
_camera->setClearMask(0);
|
||||
|
||||
viewer->setUpRenderingSupport();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
struct TextDrawCallback : public virtual osg::Drawable::DrawCallback
|
||||
|
||||
@@ -1299,6 +1299,29 @@ void Viewer::checkWindowStatus()
|
||||
}
|
||||
|
||||
|
||||
struct LessGraphicsContext
|
||||
{
|
||||
bool operator () (const osg::GraphicsContext* lhs, const osg::GraphicsContext* rhs) const
|
||||
{
|
||||
int screenLeft = lhs->getTraits()? lhs->getTraits()->screenNum : 0;
|
||||
int screenRight = rhs->getTraits()? rhs->getTraits()->screenNum : 0;
|
||||
if (screenLeft < screenRight) return true;
|
||||
if (screenLeft > screenRight) return false;
|
||||
|
||||
screenLeft = lhs->getTraits()? lhs->getTraits()->x : 0;
|
||||
screenRight = rhs->getTraits()? rhs->getTraits()->x : 0;
|
||||
if (screenLeft < screenRight) return true;
|
||||
if (screenLeft > screenRight) return false;
|
||||
|
||||
screenLeft = lhs->getTraits()? lhs->getTraits()->y : 0;
|
||||
screenRight = rhs->getTraits()? rhs->getTraits()->y : 0;
|
||||
if (screenLeft < screenRight) return true;
|
||||
if (screenLeft > screenRight) return false;
|
||||
|
||||
return lhs < rhs;
|
||||
}
|
||||
};
|
||||
|
||||
void Viewer::getContexts(Contexts& contexts, bool onlyValid)
|
||||
{
|
||||
typedef std::set<osg::GraphicsContext*> ContextSet;
|
||||
@@ -1331,6 +1354,11 @@ void Viewer::getContexts(Contexts& contexts, bool onlyValid)
|
||||
{
|
||||
contexts.push_back(const_cast<osg::GraphicsContext*>(*itr));
|
||||
}
|
||||
|
||||
if (contexts.size()>=2)
|
||||
{
|
||||
std::sort(contexts.begin(), contexts.end(), LessGraphicsContext());
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::getWindows(Windows& windows, bool onlyValid)
|
||||
|
||||
Reference in New Issue
Block a user