-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
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.

Tim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFGcxeieDhWHdXrDRURAmeTAJ9kjtkOv6Pkef8mebYhyMHVjcK+XwCfQNFY
o0QZMHTUi9ysQ5tgiHJXGtQ=
=nHI6
-----END PGP SIGNATURE-----
diff --git a/src/Main/FGManipulator.cxx b/src/Main/FGManipulator.cxx
index 6442484..de88d5e 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 dae69d2..e20033d 100644
--- a/src/Main/FGManipulator.hxx
+++ b/src/Main/FGManipulator.hxx
@@ -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);
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to