]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/FGEventHandler.cxx
commradio: improvements for atis speech
[flightgear.git] / src / Viewer / FGEventHandler.cxx
index b0f9bcd1dd6353621a21f26f691ab61edd106185..601d5a7b8768aaf0264b788ddd286a031c9554f8 100644 (file)
@@ -68,6 +68,21 @@ FGEventHandler::FGEventHandler() :
     numlockKeyMap[GUIEventAdapter::KEY_KP_Page_Up] = '9';
     numlockKeyMap[GUIEventAdapter::KEY_KP_Delete] = '.';
 
+    // The comment above is incorrect on Mac osgViewer, at least. So we
+    // need to map the 'num-locked' key codes to real values.
+    numlockKeyMap[GUIEventAdapter::KEY_KP_0]  = '0';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_1] = '1';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_2] = '2';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_3] = '3';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_4] = '4';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_5] = '5';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_6] = '6';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_7] = '7';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_8] = '8';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_9] = '9';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_Decimal] = '.';
+
+    
     // mapping when NumLock is off
     noNumlockKeyMap[GUIEventAdapter::KEY_KP_Insert]     = PU_KEY_INSERT;
     noNumlockKeyMap[GUIEventAdapter::KEY_KP_End]        = PU_KEY_END;
@@ -88,6 +103,13 @@ FGEventHandler::FGEventHandler() :
     _print = fgGetNode("/sim/rendering/print-statistics", true);
 }
 
+void FGEventHandler::reset()
+{
+    _display = fgGetNode("/sim/rendering/on-screen-statistics", true);
+    _print = fgGetNode("/sim/rendering/print-statistics", true);
+    statsHandler->reset();
+}
+    
 namespace
 {
 // Translate OSG modifier mask to FG modifier mask.
@@ -136,6 +158,8 @@ eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
     y = -1;
 
     const osg::GraphicsContext* eventGC = ea.getGraphicsContext();
+    if( !eventGC )
+      return false; // TODO how can this happen?
     const osg::GraphicsContext::Traits* traits = eventGC->getTraits();
     osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
     if (!guiCamera)
@@ -168,7 +192,14 @@ bool FGEventHandler::handle(const osgGA::GUIEventAdapter& ea,
     // Event handlers seem to be called even if the according event has already
     // been handled. Already handled events shouldn't be handled multiple times
     // so we need to exit here manually.
-    if( ea.getHandled() )
+    if(    ea.getHandled()
+           // Let mouse move events pass to correctly handle mouse cursor hide
+           // timeout while moving just on the canvas gui.
+           // TODO We should clean up the whole mouse input and make hide
+           //      timeout independent of the event handler which consumed the
+           //      event.
+        && ea.getEventType() != osgGA::GUIEventAdapter::MOVE
+        && ea.getEventType() != osgGA::GUIEventAdapter::DRAG )
       return false;
 
     int x = 0;
@@ -227,6 +258,18 @@ bool FGEventHandler::handle(const osgGA::GUIEventAdapter& ea,
                 button = 4;
             else
                 button = -1;
+            
+#if defined(SG_MAC)
+            // bug https://code.google.com/p/flightgear-bugs/issues/detail?id=1286
+            // Mac (Cocoa) interprets shuft+wheel as horizontal scroll
+            if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_SHIFT) {
+                if (ea.getScrollingDeltaX() > 0)
+                    button = 3;
+                else if (ea.getScrollingDeltaX() < 0)
+                    button = 4;
+            }
+#endif
+            
         } else if (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_UP)
             button = 3;
         else
@@ -246,7 +289,7 @@ bool FGEventHandler::handle(const osgGA::GUIEventAdapter& ea,
         if (mouseWarped)
             return true;
         if (eventToViewport(ea, us, x, y) && mouseMotionHandler)
-            (*mouseMotionHandler)(x, y);
+            (*mouseMotionHandler)(x, y, &ea);
         return true;
     case osgGA::GUIEventAdapter::RESIZE:
         SG_LOG(SG_VIEW, SG_DEBUG, "FGEventHandler::handle: RESIZE event " << ea.getWindowHeight() << " x " << ea.getWindowWidth() << ", resizable: " << resizable);
@@ -402,6 +445,7 @@ void eventToWindowCoords(const osgGA::GUIEventAdapter* ea,
         y = (double)traits->height - y;
 }
 
+#if 0
 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
                               double& x, double& y)
 {
@@ -416,4 +460,6 @@ void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
     if (ea->getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS)
         y = (double)traits->height - y;
 }
+#endif
+    
 }