#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]
{
int x = 0;
int y = 0;
+ handleStats(us);
+
switch (ea.getEventType()) {
case osgGA::GUIEventAdapter::FRAME:
if (idleHandler)
}
}
+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);
+ }
+}
+
#include <map>
#include <osg/Quat>
#include <osgGA/MatrixManipulator>
+#include <osgViewer/ViewerEventHandlers>
#include "fg_os.hxx"
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;
// 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
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());