]> git.mxchange.org Git - flightgear.git/commitdiff
- let the OSG on-screen-statistics function no longer be hard-coded
authormfranz <mfranz>
Sun, 20 Apr 2008 18:24:52 +0000 (18:24 +0000)
committermfranz <mfranz>
Sun, 20 Apr 2008 18:24:52 +0000 (18:24 +0000)
  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
src/Main/FGManipulator.hxx
src/Main/fg_os_osgviewer.cxx

index 8e9d20dccc2c5ee8baac0178be59f9237c37690a..b8a6095ca3f4a0d98600f49de751b2371302a0f4 100644 (file)
@@ -4,24 +4,33 @@
 #include <osg/Math>
 #include <osgViewer/Viewer>
 #include <plib/pu.h>
+#include <Main/fg_props.hxx>
 #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);
+    }
+}
+
index d61cf40c2735ffc93f451c9db89cf116ea947d8c..b0812917aca1f345336777c603b003fb2dd29a4f 100644 (file)
@@ -4,6 +4,7 @@
 #include <map>
 #include <osg/Quat>
 #include <osgGA/MatrixManipulator>
+#include <osgViewer/ViewerEventHandlers>
 
 #include "fg_os.hxx"
 
@@ -128,6 +129,8 @@ protected:
     fgKeyHandler keyHandler;
     fgMouseClickHandler mouseClickHandler;
     fgMouseMotionHandler mouseMotionHandler;
+    osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
+    osg::ref_ptr<osgGA::GUIEventAdapter> 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
index c652dc3cdf9c3860b71025bbe1141bd35b81eb9f..95bc447f2b4d2b506d27217036332a6f8e3cee09 100644 (file)
@@ -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());