]> git.mxchange.org Git - flightgear.git/commitdiff
Tim MOORE:
authormfranz <mfranz>
Sat, 16 Jun 2007 09:39:56 +0000 (09:39 +0000)
committermfranz <mfranz>
Sat, 16 Jun 2007 09:39:56 +0000 (09:39 +0000)
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."

src/Main/FGManipulator.cxx
src/Main/FGManipulator.hxx
src/Main/fg_os_osgviewer.cxx

index 644248474e2e6dfc10574bee48f6cf21a753a8be..de88d5e5111b4bbcecfb96c18d38a677fce53d0b 100644 (file)
 // 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;
 }
 
index dae69d24398f4ac6989a367483c2d4faa375eb28..e20033d1fdf089fcf511fa6e024f8b7de944c028 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef FGMANIPULATOR_H
 #define FGMANIPULATOR_H 1
 
+#include <map>
 #include <osg/Quat>
 #include <osgGA/MatrixManipulator>
 
@@ -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<int, osgGA::GUIEventAdapter::ModKeyMask> KeyMaskMap;
+    KeyMaskMap keyMaskMap;
     osg::Vec3d position;
     osg::Quat attitude;
     void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
index 3a1685ac6fb5b9635bcce636c3c1b404f11d01c7..a89c0d9efa7f1446dc7863ed4fc1a817b265bcbe 100644 (file)
@@ -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)