From: mfranz Date: Sat, 16 Jun 2007 09:39:56 +0000 (+0000) Subject: Tim MOORE: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b5917d62d225feb9588aed25dba3d3617e38f79f;p=flightgear.git Tim MOORE: FGManipulator.*: "This patch works around a bug in OSG's handling of modifier keys. The symptom of the bug is that modifier keys don't appear to be released." fg_os_osgviewer.cxx: "This patch fixes the test for support of cursor changes in OSG 2.0." --- diff --git a/src/Main/FGManipulator.cxx b/src/Main/FGManipulator.cxx index 644248474..de88d5e51 100644 --- a/src/Main/FGManipulator.cxx +++ b/src/Main/FGManipulator.cxx @@ -10,6 +10,25 @@ // 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) +{ + keyMaskMap[osgGA::GUIEventAdapter::KEY_Shift_L] + = osgGA::GUIEventAdapter::MODKEY_LEFT_SHIFT; + keyMaskMap[osgGA::GUIEventAdapter::KEY_Shift_R] + = osgGA::GUIEventAdapter::MODKEY_RIGHT_SHIFT; + keyMaskMap[osgGA::GUIEventAdapter::KEY_Control_L] + = osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL; + keyMaskMap[osgGA::GUIEventAdapter::KEY_Control_R] + = osgGA::GUIEventAdapter::MODKEY_RIGHT_CTRL; + keyMaskMap[osgGA::GUIEventAdapter::KEY_Alt_L] + = osgGA::GUIEventAdapter::MODKEY_LEFT_ALT; + keyMaskMap[osgGA::GUIEventAdapter::KEY_Alt_R] + = osgGA::GUIEventAdapter::MODKEY_RIGHT_ALT; +} + void FGManipulator::setByMatrix(const osg::Matrixd& matrix) { // Yuck @@ -194,9 +213,19 @@ void FGManipulator::handleKey(const osgGA::GUIEventAdapter& ea, int& key, case osgGA::GUIEventAdapter::KEY_KP_9: key = 360; break; case osgGA::GUIEventAdapter::KEY_KP_Enter: key = 269; break; } - modifiers = osgToFGModifiers(ea.getModKeyMask()); + osgGA::GUIEventAdapter::EventType eventType = ea.getEventType(); + // Track the modifiers because OSG is currently (2.0) broken + KeyMaskMap::iterator iter = keyMaskMap.find(key); + if (iter != keyMaskMap.end()) { + int mask = iter->second; + if (eventType == osgGA::GUIEventAdapter::KEYUP) + osgModifiers &= ~mask; + else + osgModifiers |= mask; + } + modifiers = osgToFGModifiers(osgModifiers); currentModifiers = modifiers; - if (ea.getEventType() == osgGA::GUIEventAdapter::KEYUP) + if (eventType == osgGA::GUIEventAdapter::KEYUP) modifiers |= KEYMOD_RELEASED; } diff --git a/src/Main/FGManipulator.hxx b/src/Main/FGManipulator.hxx index dae69d243..e20033d1f 100644 --- a/src/Main/FGManipulator.hxx +++ b/src/Main/FGManipulator.hxx @@ -1,6 +1,7 @@ #ifndef FGMANIPULATOR_H #define FGMANIPULATOR_H 1 +#include #include #include @@ -8,10 +9,8 @@ class FGManipulator : public osgGA::MatrixManipulator { public: - FGManipulator() : - idleHandler(0), drawHandler(0), windowResizeHandler(0), keyHandler(0), - mouseClickHandler(0), mouseMotionHandler(0), currentModifiers(0) - {} + FGManipulator(); + virtual ~FGManipulator() {} virtual const char* className() const {return "FGManipulator"; } @@ -116,6 +115,10 @@ protected: fgMouseClickHandler mouseClickHandler; fgMouseMotionHandler mouseMotionHandler; int currentModifiers; + // work-around for OSG bug + int osgModifiers; + typedef std::map KeyMaskMap; + KeyMaskMap keyMaskMap; osg::Vec3d position; osg::Quat attitude; void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers); diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index 3a1685ac6..a89c0d9ef 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -19,7 +19,8 @@ #include "globals.hxx" #include "renderer.hxx" -#if ((1 == OSG_VERSION_MAJOR) && (9 == OSG_VERSION_MINOR) && \ +#if ((2 <= OSG_VERSION_MAJOR) || \ + (1 == OSG_VERSION_MAJOR) && (9 == OSG_VERSION_MINOR) && \ (8 <= OSG_VERSION_PATCH)) || \ ((1 == OSG_VERSION_MAJOR) && (9 < OSG_VERSION_MINOR)) || \ (1 < OSG_VERSION_MAJOR)