]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/FGEventHandler.cxx
commradio: improvements for atis speech
[flightgear.git] / src / Viewer / FGEventHandler.cxx
index 9951c00278d2060f87f61f63048540e3f5d14a52..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;
@@ -83,8 +98,18 @@ FGEventHandler::FGEventHandler() :
 
     for (int i = 0; i < 128; i++)
         release_keys[i] = i;
+
+    _display = fgGetNode("/sim/rendering/on-screen-statistics", true);
+    _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.
@@ -133,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)
@@ -162,6 +189,19 @@ eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
 bool FGEventHandler::handle(const osgGA::GUIEventAdapter& ea,
                             osgGA::GUIActionAdapter& us)
 {
+    // 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()
+           // 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;
     int y = 0;
 
@@ -218,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
@@ -237,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);
@@ -356,10 +408,7 @@ void FGEventHandler::handleKey(const osgGA::GUIEventAdapter& ea, int& key,
 
 void FGEventHandler::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);
-
-    int type = display->getIntValue() % osgViewer::StatsHandler::LAST;
+    int type = _display->getIntValue() % osgViewer::StatsHandler::LAST;
     if (type != statsType) {
         statsEvent->setKey(displayStatsKey);
         do {
@@ -371,13 +420,13 @@ void FGEventHandler::handleStats(osgGA::GUIActionAdapter& us)
             }
         } while (statsType != type);
 
-        display->setIntValue(statsType);
+        _display->setIntValue(statsType);
     }
 
-    if (print->getBoolValue()) {
+    if (_print->getBoolValue()) {
         statsEvent->setKey(printStatsKey);
         statsHandler->handle(*statsEvent, us);
-        print->setBoolValue(false);
+        _print->setBoolValue(false);
     }
 }
 
@@ -396,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)
 {
@@ -410,4 +460,6 @@ void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
     if (ea->getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS)
         y = (double)traits->height - y;
 }
+#endif
+    
 }