From b61cc37e305f55136604708e96dd697def1feae8 Mon Sep 17 00:00:00 2001 From: mfranz Date: Sun, 20 Apr 2008 18:24:52 +0000 Subject: [PATCH] - let the OSG on-screen-statistics function no longer be hard-coded on the '*'-key, but allow to cycle it by setting /sim/rendering/on-screen-statistics to "true" - move that function to the Debug menu (no more key assigned!) - add "print-statistics" menu entry --- src/Main/FGManipulator.cxx | 35 ++++++++++++++++++++++++++++++++--- src/Main/FGManipulator.hxx | 4 ++++ src/Main/fg_os_osgviewer.cxx | 4 ---- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/Main/FGManipulator.cxx b/src/Main/FGManipulator.cxx index 8e9d20dcc..b8a6095ca 100644 --- a/src/Main/FGManipulator.cxx +++ b/src/Main/FGManipulator.cxx @@ -4,24 +4,33 @@ #include #include #include +#include
#include "FGManipulator.hxx" #if !defined(X_DISPLAY_MISSING) #define X_DOUBLE_SCROLL_BUG 1 #endif +const int displayStatsKey = 1; +const int printStatsKey = 2; + + // The manipulator is responsible for updating a Viewer's camera. It's // event handling method is also a convenient place to run the the FG // idle and draw handlers. FGManipulator::FGManipulator() : idleHandler(0), drawHandler(0), windowResizeHandler(0), keyHandler(0), - mouseClickHandler(0), mouseMotionHandler(0), currentModifiers(0), - osgModifiers(0), resizable(true), mouseWarped(false), + mouseClickHandler(0), mouseMotionHandler(0), + statsHandler(new osgViewer::StatsHandler), statsEvent(new osgGA::GUIEventAdapter), + currentModifiers(0), osgModifiers(0), resizable(true), mouseWarped(false), scrollButtonPressed(false), useEventModifiers(false) { using namespace osgGA; - + statsHandler->setKeyEventTogglesOnScreenStats(displayStatsKey); + statsHandler->setKeyEventPrintsOutStats(printStatsKey); + statsEvent->setEventType(GUIEventAdapter::KEYDOWN); + keyMaskMap[GUIEventAdapter::KEY_Shift_L] = GUIEventAdapter::MODKEY_LEFT_SHIFT; keyMaskMap[GUIEventAdapter::KEY_Shift_R] @@ -142,6 +151,8 @@ bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea, { int x = 0; int y = 0; + handleStats(us); + switch (ea.getEventType()) { case osgGA::GUIEventAdapter::FRAME: if (idleHandler) @@ -309,3 +320,21 @@ void FGManipulator::handleKey(const osgGA::GUIEventAdapter& ea, int& key, } } +void FGManipulator::handleStats(osgGA::GUIActionAdapter& us) +{ + static SGPropertyNode_ptr display = fgGetNode("/sim/rendering/on-screen-statistics", true); + static SGPropertyNode_ptr print = fgGetNode("/sim/rendering/print-statistics", true); + + if (display->getBoolValue()) { + statsEvent->setKey(displayStatsKey); + statsHandler->handle(*statsEvent, us); + display->setBoolValue(false); + } + + if (print->getBoolValue()) { + statsEvent->setKey(printStatsKey); + statsHandler->handle(*statsEvent, us); + print->setBoolValue(false); + } +} + diff --git a/src/Main/FGManipulator.hxx b/src/Main/FGManipulator.hxx index d61cf40c2..b0812917a 100644 --- a/src/Main/FGManipulator.hxx +++ b/src/Main/FGManipulator.hxx @@ -4,6 +4,7 @@ #include #include #include +#include #include "fg_os.hxx" @@ -128,6 +129,8 @@ protected: fgKeyHandler keyHandler; fgMouseClickHandler mouseClickHandler; fgMouseMotionHandler mouseMotionHandler; + osg::ref_ptr statsHandler; + osg::ref_ptr statsEvent; int currentModifiers; // work-around for OSG bug int osgModifiers; @@ -145,5 +148,6 @@ protected: // When the viewer is embedded, the host toolkit may deliver a // valid event mask but not control keys. bool useEventModifiers; + void handleStats(osgGA::GUIActionAdapter& us); }; #endif diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index c652dc3cd..95bc447f2 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -248,10 +248,6 @@ void fgOSOpenWindow(int w, int h, int bpp, viewer->setCameraManipulator(globals->get_renderer()->getManipulator()); // Let FG handle the escape key with a confirmation viewer->setKeyEventSetsDone(0); - osgViewer::StatsHandler* statsHandler = new osgViewer::StatsHandler; - statsHandler->setKeyEventTogglesOnScreenStats('*'); - statsHandler->setKeyEventPrintsOutStats(0); - viewer->addEventHandler(statsHandler); // The viewer won't start without some root. viewer->setSceneData(new osg::Group); globals->get_renderer()->setViewer(viewer.get()); -- 2.39.5