2007-05-21 19:24:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2008-08-01 15:57:29 +00:00
|
|
|
#include <osg/Camera>
|
|
|
|
#include <osg/GraphicsContext>
|
2007-05-21 17:50:02 +00:00
|
|
|
#include <osg/Math>
|
2008-08-01 15:57:29 +00:00
|
|
|
#include <osg/Viewport>
|
2007-05-21 17:50:02 +00:00
|
|
|
#include <osgViewer/Viewer>
|
2008-08-01 15:57:29 +00:00
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
#include <plib/pu.h>
|
2008-04-20 18:24:52 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2008-08-01 15:57:29 +00:00
|
|
|
#include "CameraGroup.hxx"
|
2007-05-21 17:50:02 +00:00
|
|
|
#include "FGManipulator.hxx"
|
2008-08-01 15:57:29 +00:00
|
|
|
#include "WindowSystemAdapter.hxx"
|
2007-05-21 17:50:02 +00:00
|
|
|
|
2007-08-20 21:38:25 +00:00
|
|
|
#if !defined(X_DISPLAY_MISSING)
|
|
|
|
#define X_DOUBLE_SCROLL_BUG 1
|
|
|
|
#endif
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
namespace flightgear
|
|
|
|
{
|
2008-04-20 18:24:52 +00:00
|
|
|
const int displayStatsKey = 1;
|
|
|
|
const int printStatsKey = 2;
|
|
|
|
|
|
|
|
|
2008-04-29 14:49:44 +00:00
|
|
|
// The manipulator is responsible for updating a Viewer's camera. Its
|
|
|
|
// event handling method is also a convenient place to run the FG idle
|
|
|
|
// and draw handlers.
|
2007-05-21 17:50:02 +00:00
|
|
|
|
2007-06-16 09:39:56 +00:00
|
|
|
FGManipulator::FGManipulator() :
|
2008-04-21 14:18:30 +00:00
|
|
|
idleHandler(0),
|
|
|
|
drawHandler(0),
|
|
|
|
windowResizeHandler(0),
|
|
|
|
keyHandler(0),
|
|
|
|
mouseClickHandler(0),
|
|
|
|
mouseMotionHandler(0),
|
|
|
|
statsHandler(new osgViewer::StatsHandler),
|
|
|
|
statsEvent(new osgGA::GUIEventAdapter),
|
|
|
|
statsType(osgViewer::StatsHandler::NO_STATS),
|
|
|
|
currentModifiers(0),
|
|
|
|
resizable(true),
|
|
|
|
mouseWarped(false),
|
2008-04-25 22:45:43 +00:00
|
|
|
scrollButtonPressed(false)
|
2007-06-16 09:39:56 +00:00
|
|
|
{
|
2007-07-01 16:39:52 +00:00
|
|
|
using namespace osgGA;
|
2008-04-20 18:24:52 +00:00
|
|
|
statsHandler->setKeyEventTogglesOnScreenStats(displayStatsKey);
|
|
|
|
statsHandler->setKeyEventPrintsOutStats(printStatsKey);
|
|
|
|
statsEvent->setEventType(GUIEventAdapter::KEYDOWN);
|
|
|
|
|
2008-04-29 14:49:44 +00:00
|
|
|
// OSG reports NumPad keycodes independent of the NumLock modifier.
|
|
|
|
// Both KP-4 and KP-Left are reported as KEY_KP_Left (0xff96), so we
|
|
|
|
// have to generate the locked keys ourselves.
|
2007-07-01 16:39:52 +00:00
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Insert] = '0';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_End] = '1';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Down] = '2';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Page_Down] = '3';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Left] = '4';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Begin] = '5';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Right] = '6';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Home] = '7';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Up] = '8';
|
|
|
|
numlockKeyMap[GUIEventAdapter::KEY_KP_Page_Up] = '9';
|
2007-11-17 17:38:48 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 128; i++)
|
|
|
|
release_keys[i] = i;
|
2007-06-16 09:39:56 +00:00
|
|
|
}
|
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
void FGManipulator::setByMatrix(const osg::Matrixd& matrix)
|
|
|
|
{
|
|
|
|
// Yuck
|
|
|
|
position = matrix.getTrans();
|
|
|
|
attitude = matrix.getRotate();
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Matrixd FGManipulator::getMatrix() const
|
|
|
|
{
|
|
|
|
return osg::Matrixd::rotate(attitude) * osg::Matrixd::translate(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Matrixd FGManipulator::getInverseMatrix() const
|
|
|
|
{
|
|
|
|
return (osg::Matrixd::translate(-position)
|
2008-04-29 14:49:44 +00:00
|
|
|
* osg::Matrixd::rotate(attitude.inverse())) ;
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not used, but part of the interface.
|
|
|
|
void FGManipulator::setNode(osg::Node* node)
|
|
|
|
{
|
|
|
|
_node = node;
|
|
|
|
}
|
2008-04-29 14:49:44 +00:00
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
const osg::Node* FGManipulator::getNode() const
|
|
|
|
{
|
|
|
|
return _node.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* FGManipulator::getNode()
|
|
|
|
{
|
|
|
|
return _node.get();
|
|
|
|
}
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
namespace
|
|
|
|
{
|
2008-04-29 14:49:44 +00:00
|
|
|
// Translate OSG modifier mask to FG modifier mask.
|
2008-08-01 15:57:29 +00:00
|
|
|
int osgToFGModifiers(int modifiers)
|
2007-05-21 17:50:02 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
2008-04-25 23:21:47 +00:00
|
|
|
if (modifiers & osgGA::GUIEventAdapter::MODKEY_SHIFT)
|
|
|
|
result |= KEYMOD_SHIFT;
|
|
|
|
|
|
|
|
if (modifiers & osgGA::GUIEventAdapter::MODKEY_CTRL)
|
|
|
|
result |= KEYMOD_CTRL;
|
|
|
|
|
|
|
|
if (modifiers & osgGA::GUIEventAdapter::MODKEY_ALT)
|
|
|
|
result |= KEYMOD_ALT;
|
|
|
|
|
|
|
|
if (modifiers & osgGA::GUIEventAdapter::MODKEY_META)
|
|
|
|
result |= KEYMOD_META;
|
|
|
|
|
|
|
|
if (modifiers & osgGA::GUIEventAdapter::MODKEY_SUPER)
|
|
|
|
result |= KEYMOD_SUPER;
|
|
|
|
|
|
|
|
if (modifiers & osgGA::GUIEventAdapter::MODKEY_HYPER)
|
|
|
|
result |= KEYMOD_HYPER;
|
2007-05-21 17:50:02 +00:00
|
|
|
return result;
|
|
|
|
}
|
2008-08-01 15:57:29 +00:00
|
|
|
}
|
2007-05-21 17:50:02 +00:00
|
|
|
|
|
|
|
void FGManipulator::init(const osgGA::GUIEventAdapter& ea,
|
2008-04-29 14:49:44 +00:00
|
|
|
osgGA::GUIActionAdapter& us)
|
2007-05-21 17:50:02 +00:00
|
|
|
{
|
|
|
|
currentModifiers = osgToFGModifiers(ea.getModKeyMask());
|
|
|
|
(void)handle(ea, us);
|
|
|
|
}
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
// Calculate event coordinates in the viewport of the GUI camera, if
|
|
|
|
// possible. Otherwise return false and (-1, -1).
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
bool
|
2007-05-26 13:53:46 +00:00
|
|
|
eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
|
|
|
|
int& x, int& y)
|
2007-05-21 17:50:02 +00:00
|
|
|
{
|
2008-04-29 14:49:44 +00:00
|
|
|
x = -1;
|
|
|
|
y = -1;
|
2007-05-26 13:53:46 +00:00
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
const osg::GraphicsContext* eventGC = ea.getGraphicsContext();
|
|
|
|
const osg::GraphicsContext::Traits* traits = eventGC->getTraits();
|
|
|
|
osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
|
|
|
|
if (!guiCamera)
|
2008-04-29 14:49:44 +00:00
|
|
|
return false;
|
2008-08-01 15:57:29 +00:00
|
|
|
osg::Viewport* vport = guiCamera->getViewport();
|
|
|
|
if (!vport)
|
2008-04-29 14:49:44 +00:00
|
|
|
return false;
|
2008-08-01 15:57:29 +00:00
|
|
|
|
|
|
|
// Scale x, y to the dimensions of the window
|
|
|
|
double wx = (((ea.getX() - ea.getXmin()) / (ea.getXmax() - ea.getXmin()))
|
|
|
|
* (float)traits->width);
|
|
|
|
double wy = (((ea.getY() - ea.getYmin()) / (ea.getYmax() - ea.getYmin()))
|
|
|
|
* (float)traits->height);
|
|
|
|
if (vport->x() <= wx && wx <= vport->x() + vport->width()
|
|
|
|
&& vport->y() <= wy && wy <= vport->y() + vport->height()) {
|
|
|
|
// Finally, into viewport coordinates. Change y to "increasing
|
|
|
|
// downwards".
|
|
|
|
x = wx - vport->x();
|
|
|
|
y = vport->height() - (wy - vport->y());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea,
|
2008-04-29 14:49:44 +00:00
|
|
|
osgGA::GUIActionAdapter& us)
|
2007-05-21 17:50:02 +00:00
|
|
|
{
|
2007-11-30 00:01:01 +00:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2008-04-20 18:24:52 +00:00
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
switch (ea.getEventType()) {
|
|
|
|
case osgGA::GUIEventAdapter::FRAME:
|
2008-04-29 14:49:44 +00:00
|
|
|
if (idleHandler)
|
|
|
|
(*idleHandler)();
|
|
|
|
if (drawHandler)
|
|
|
|
(*drawHandler)();
|
|
|
|
mouseWarped = false;
|
|
|
|
handleStats(us);
|
|
|
|
return true;
|
2007-05-21 17:50:02 +00:00
|
|
|
case osgGA::GUIEventAdapter::KEYDOWN:
|
|
|
|
case osgGA::GUIEventAdapter::KEYUP:
|
|
|
|
{
|
2008-04-29 14:49:44 +00:00
|
|
|
int key, modmask;
|
|
|
|
handleKey(ea, key, modmask);
|
|
|
|
eventToViewport(ea, us, x, y);
|
|
|
|
if (keyHandler)
|
|
|
|
(*keyHandler)(key, modmask, x, y);
|
2007-05-26 13:53:46 +00:00
|
|
|
return true;
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
|
|
|
case osgGA::GUIEventAdapter::PUSH:
|
|
|
|
case osgGA::GUIEventAdapter::RELEASE:
|
|
|
|
{
|
2007-05-26 13:53:46 +00:00
|
|
|
bool mainWindow = eventToViewport(ea, us, x, y);
|
2008-04-29 14:49:44 +00:00
|
|
|
int button = 0;
|
|
|
|
switch (ea.getButton()) {
|
|
|
|
case osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON:
|
|
|
|
button = 0;
|
|
|
|
break;
|
|
|
|
case osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON:
|
|
|
|
button = 1;
|
|
|
|
break;
|
|
|
|
case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON:
|
|
|
|
button = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mouseClickHandler)
|
|
|
|
(*mouseClickHandler)(button,
|
|
|
|
(ea.getEventType()
|
|
|
|
== osgGA::GUIEventAdapter::RELEASE), x, y, mainWindow, &ea);
|
|
|
|
return true;
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
2007-08-20 21:38:25 +00:00
|
|
|
case osgGA::GUIEventAdapter::SCROLL:
|
|
|
|
{
|
|
|
|
bool mainWindow = eventToViewport(ea, us, x, y);
|
|
|
|
#ifdef X_DOUBLE_SCROLL_BUG
|
|
|
|
scrollButtonPressed = !scrollButtonPressed;
|
|
|
|
if (!scrollButtonPressed) // Drop the button release event
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
int button;
|
|
|
|
if (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_UP)
|
|
|
|
button = 3;
|
|
|
|
else
|
|
|
|
button = 4;
|
|
|
|
if (mouseClickHandler) {
|
|
|
|
(*mouseClickHandler)(button, 0, x, y, mainWindow, &ea);
|
|
|
|
(*mouseClickHandler)(button, 1, x, y, mainWindow, &ea);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-05-21 17:50:02 +00:00
|
|
|
case osgGA::GUIEventAdapter::MOVE:
|
|
|
|
case osgGA::GUIEventAdapter::DRAG:
|
2007-08-19 05:29:00 +00:00
|
|
|
// If we warped the mouse, then disregard all pointer motion
|
|
|
|
// events for this frame. We really want to flush the event
|
|
|
|
// queue of mouse events, but don't have the ability to do
|
|
|
|
// that with osgViewer.
|
2008-04-29 14:49:44 +00:00
|
|
|
if (mouseWarped)
|
|
|
|
return true;
|
|
|
|
if (eventToViewport(ea, us, x, y) && mouseMotionHandler)
|
|
|
|
(*mouseMotionHandler)(x, y);
|
|
|
|
return true;
|
2007-07-01 16:39:52 +00:00
|
|
|
case osgGA::GUIEventAdapter::RESIZE:
|
2008-04-29 14:49:44 +00:00
|
|
|
if (resizable && windowResizeHandler)
|
|
|
|
(*windowResizeHandler)(ea.getWindowWidth(), ea.getWindowHeight());
|
|
|
|
return true;
|
2007-07-01 16:39:52 +00:00
|
|
|
case osgGA::GUIEventAdapter::CLOSE_WINDOW:
|
2007-05-23 17:57:05 +00:00
|
|
|
case osgGA::GUIEventAdapter::QUIT_APPLICATION:
|
|
|
|
fgOSExit(0);
|
|
|
|
return true;
|
2007-05-21 17:50:02 +00:00
|
|
|
default:
|
2008-04-29 14:49:44 +00:00
|
|
|
return false;
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-26 13:53:46 +00:00
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
void FGManipulator::handleKey(const osgGA::GUIEventAdapter& ea, int& key,
|
2008-04-29 14:49:44 +00:00
|
|
|
int& modifiers)
|
2007-05-21 17:50:02 +00:00
|
|
|
{
|
2008-04-29 14:49:44 +00:00
|
|
|
using namespace osgGA;
|
2007-05-21 17:50:02 +00:00
|
|
|
key = ea.getKey();
|
|
|
|
// XXX Probably other translations are needed too.
|
|
|
|
switch (key) {
|
2008-04-29 14:49:44 +00:00
|
|
|
case GUIEventAdapter::KEY_Escape: key = 0x1b; break;
|
|
|
|
case GUIEventAdapter::KEY_Return: key = '\n'; break;
|
|
|
|
case GUIEventAdapter::KEY_BackSpace: key = '\b'; break;
|
|
|
|
case GUIEventAdapter::KEY_Delete: key = 0x7f; break;
|
|
|
|
case GUIEventAdapter::KEY_Tab: key = '\t'; break;
|
|
|
|
case GUIEventAdapter::KEY_Left: key = PU_KEY_LEFT; break;
|
|
|
|
case GUIEventAdapter::KEY_Up: key = PU_KEY_UP; break;
|
|
|
|
case GUIEventAdapter::KEY_Right: key = PU_KEY_RIGHT; break;
|
|
|
|
case GUIEventAdapter::KEY_Down: key = PU_KEY_DOWN; break;
|
|
|
|
case GUIEventAdapter::KEY_Page_Up: key = PU_KEY_PAGE_UP; break;
|
|
|
|
case GUIEventAdapter::KEY_Page_Down: key = PU_KEY_PAGE_DOWN; break;
|
|
|
|
case GUIEventAdapter::KEY_Home: key = PU_KEY_HOME; break;
|
|
|
|
case GUIEventAdapter::KEY_End: key = PU_KEY_END; break;
|
|
|
|
case GUIEventAdapter::KEY_Insert: key = PU_KEY_INSERT; break;
|
|
|
|
case GUIEventAdapter::KEY_F1: key = PU_KEY_F1; break;
|
|
|
|
case GUIEventAdapter::KEY_F2: key = PU_KEY_F2; break;
|
|
|
|
case GUIEventAdapter::KEY_F3: key = PU_KEY_F3; break;
|
|
|
|
case GUIEventAdapter::KEY_F4: key = PU_KEY_F4; break;
|
|
|
|
case GUIEventAdapter::KEY_F5: key = PU_KEY_F5; break;
|
|
|
|
case GUIEventAdapter::KEY_F6: key = PU_KEY_F6; break;
|
|
|
|
case GUIEventAdapter::KEY_F7: key = PU_KEY_F7; break;
|
|
|
|
case GUIEventAdapter::KEY_F8: key = PU_KEY_F8; break;
|
|
|
|
case GUIEventAdapter::KEY_F9: key = PU_KEY_F9; break;
|
|
|
|
case GUIEventAdapter::KEY_F10: key = PU_KEY_F10; break;
|
|
|
|
case GUIEventAdapter::KEY_F11: key = PU_KEY_F11; break;
|
|
|
|
case GUIEventAdapter::KEY_F12: key = PU_KEY_F12; break;
|
|
|
|
case GUIEventAdapter::KEY_KP_Delete: key = '.'; break;
|
|
|
|
case GUIEventAdapter::KEY_KP_Enter: key = '\r'; break;
|
|
|
|
case GUIEventAdapter::KEY_KP_Add: key = '+'; break;
|
|
|
|
case GUIEventAdapter::KEY_KP_Divide: key = '/'; break;
|
|
|
|
case GUIEventAdapter::KEY_KP_Multiply: key = '*'; break;
|
|
|
|
case GUIEventAdapter::KEY_KP_Subtract: key = '-'; break;
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
2007-06-16 09:39:56 +00:00
|
|
|
osgGA::GUIEventAdapter::EventType eventType = ea.getEventType();
|
2008-04-25 22:45:43 +00:00
|
|
|
|
2007-07-01 16:39:52 +00:00
|
|
|
std::map<int, int>::iterator numPadIter = numlockKeyMap.find(key);
|
|
|
|
|
|
|
|
if (numPadIter != numlockKeyMap.end()) {
|
2008-04-29 14:49:44 +00:00
|
|
|
if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_NUM_LOCK) {
|
|
|
|
key = numPadIter->second;
|
|
|
|
}
|
2007-06-16 09:39:56 +00:00
|
|
|
}
|
2008-04-26 17:01:08 +00:00
|
|
|
|
2008-04-25 22:45:43 +00:00
|
|
|
modifiers = osgToFGModifiers(ea.getModKeyMask());
|
2007-05-21 17:50:02 +00:00
|
|
|
currentModifiers = modifiers;
|
2007-06-16 09:39:56 +00:00
|
|
|
if (eventType == osgGA::GUIEventAdapter::KEYUP)
|
2008-04-29 14:49:44 +00:00
|
|
|
modifiers |= KEYMOD_RELEASED;
|
2007-11-12 19:29:08 +00:00
|
|
|
|
2008-04-29 14:49:44 +00:00
|
|
|
// Release the letter key, for which the key press was reported. This
|
|
|
|
// is to deal with Ctrl-press -> a-press -> Ctrl-release -> a-release
|
|
|
|
// correctly.
|
2007-11-17 17:38:48 +00:00
|
|
|
if (key >= 0 && key < 128) {
|
2007-11-12 19:29:08 +00:00
|
|
|
if (modifiers & KEYMOD_RELEASED) {
|
|
|
|
key = release_keys[key];
|
|
|
|
} else {
|
|
|
|
release_keys[key] = key;
|
|
|
|
if (key >= 1 && key <= 26) {
|
|
|
|
release_keys[key + '@'] = key;
|
|
|
|
release_keys[key + '`'] = key;
|
|
|
|
} else if (key >= 'A' && key <= 'Z') {
|
|
|
|
release_keys[key - '@'] = key;
|
|
|
|
release_keys[tolower(key)] = key;
|
|
|
|
} else if (key >= 'a' && key <= 'z') {
|
|
|
|
release_keys[key - '`'] = key;
|
|
|
|
release_keys[toupper(key)] = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-21 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 18:24:52 +00:00
|
|
|
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);
|
|
|
|
|
2008-04-21 14:18:30 +00:00
|
|
|
int type = display->getIntValue() % osgViewer::StatsHandler::LAST;
|
|
|
|
if (type != statsType) {
|
2008-04-20 18:24:52 +00:00
|
|
|
statsEvent->setKey(displayStatsKey);
|
2008-04-21 14:18:30 +00:00
|
|
|
do {
|
2008-04-29 14:49:44 +00:00
|
|
|
statsType = (statsType + 1) % osgViewer::StatsHandler::LAST;
|
2008-04-21 14:18:30 +00:00
|
|
|
statsHandler->handle(*statsEvent, us);
|
|
|
|
} while (statsType != type);
|
|
|
|
|
|
|
|
display->setIntValue(statsType);
|
2008-04-20 18:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (print->getBoolValue()) {
|
|
|
|
statsEvent->setKey(printStatsKey);
|
|
|
|
statsHandler->handle(*statsEvent, us);
|
|
|
|
print->setBoolValue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
void eventToWindowCoords(const osgGA::GUIEventAdapter* ea,
|
|
|
|
double& x, double& y)
|
|
|
|
{
|
|
|
|
using namespace osg;
|
|
|
|
const GraphicsContext* gc = ea->getGraphicsContext();
|
|
|
|
const GraphicsContext::Traits* traits = gc->getTraits() ;
|
|
|
|
// Scale x, y to the dimensions of the window
|
|
|
|
x = (((ea->getX() - ea->getXmin()) / (ea->getXmax() - ea->getXmin()))
|
|
|
|
* (double)traits->width);
|
|
|
|
y = (((ea->getY() - ea->getYmin()) / (ea->getYmax() - ea->getYmin()))
|
|
|
|
* (double)traits->height);
|
|
|
|
if (ea->getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
|
|
|
|
y = (double)traits->height - y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
|
|
|
|
double& x, double& y)
|
|
|
|
{
|
|
|
|
using namespace osg;
|
|
|
|
const GraphicsContext* gc = ea->getGraphicsContext();
|
|
|
|
const GraphicsContext::Traits* traits = gc->getTraits() ;
|
|
|
|
// Scale x, y to the dimensions of the window
|
|
|
|
x = (((ea->getX() - ea->getXmin()) / (ea->getXmax() - ea->getXmin()))
|
|
|
|
* (double)traits->width);
|
|
|
|
y = (((ea->getY() - ea->getYmin()) / (ea->getYmax() - ea->getYmin()))
|
|
|
|
* (double)traits->height);
|
|
|
|
if (ea->getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS)
|
|
|
|
y = (double)traits->height - y;
|
|
|
|
}
|
|
|
|
}
|