]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/FGEventHandler.cxx
Hopefully fix the shadow disappearing because of range animation issue in a more...
[flightgear.git] / src / Main / FGEventHandler.cxx
index e4d1d104308c8cb478b9d7280256286276822d52..936b02fc34ac19ecbb3ba01d8460ba8989f1551c 100644 (file)
 #include "CameraGroup.hxx"
 #include "FGEventHandler.hxx"
 #include "WindowSystemAdapter.hxx"
+#include "renderer.hxx"
 
 #if !defined(X_DISPLAY_MISSING)
 #define X_DOUBLE_SCROLL_BUG 1
 #endif
 
+#ifdef SG_MAC
+// hack - during interactive resize on Mac, OSG queues and then flushes
+// a large number of resize events, without doing any drawing.
+extern void puCleanUpJunk ( void ) ;
+#endif
+
 namespace flightgear
 {
 const int displayStatsKey = 1;
@@ -29,12 +36,10 @@ const int printStatsKey = 2;
 
 FGEventHandler::FGEventHandler() :
     idleHandler(0),
-    drawHandler(0),
-    windowResizeHandler(0),
     keyHandler(0),
     mouseClickHandler(0),
     mouseMotionHandler(0),
-    statsHandler(new osgViewer::StatsHandler),
+    statsHandler(new FGStatsHandler),
     statsEvent(new osgGA::GUIEventAdapter),
     statsType(osgViewer::StatsHandler::NO_STATS),
     currentModifiers(0),
@@ -60,6 +65,20 @@ FGEventHandler::FGEventHandler() :
     numlockKeyMap[GUIEventAdapter::KEY_KP_Home] = '7';
     numlockKeyMap[GUIEventAdapter::KEY_KP_Up] = '8';
     numlockKeyMap[GUIEventAdapter::KEY_KP_Page_Up] = '9';
+    numlockKeyMap[GUIEventAdapter::KEY_KP_Delete] = '.';
+
+    // mapping when NumLock is off
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Insert]     = PU_KEY_INSERT;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_End]        = PU_KEY_END;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Down]       = PU_KEY_DOWN;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Page_Down]  = PU_KEY_PAGE_DOWN;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Left]       = PU_KEY_LEFT;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Begin]      = '5';
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Right]      = PU_KEY_RIGHT;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Home]       = PU_KEY_HOME;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Up]         = PU_KEY_UP;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Page_Up]    = PU_KEY_PAGE_UP;
+    noNumlockKeyMap[GUIEventAdapter::KEY_KP_Delete]     = 127;
 
     for (int i = 0; i < 128; i++)
         release_keys[i] = i;
@@ -191,11 +210,18 @@ bool FGEventHandler::handle(const osgGA::GUIEventAdapter& ea,
             return true;
 #endif
         int button;
-        if (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_UP)
+        if (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_2D) {
+            if (ea.getScrollingDeltaY() > 0)
+                button = 3;
+            else if (ea.getScrollingDeltaY() < 0)
+                button = 4;
+            else
+                button = -1;
+        } else if (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_UP)
             button = 3;
         else
             button = 4;
-        if (mouseClickHandler) {
+        if (mouseClickHandler && button != -1) {
             (*mouseClickHandler)(button, 0, x, y, mainWindow, &ea);
             (*mouseClickHandler)(button, 1, x, y, mainWindow, &ea);
         }
@@ -213,9 +239,17 @@ bool FGEventHandler::handle(const osgGA::GUIEventAdapter& ea,
             (*mouseMotionHandler)(x, y);
         return true;
     case osgGA::GUIEventAdapter::RESIZE:
+        SG_LOG(SG_VIEW, SG_DEBUG, "FGEventHandler::handle: RESIZE event " << ea.getWindowHeight() << " x " << ea.getWindowWidth() << ", resizable: " << resizable);
         CameraGroup::getDefault()->resized();
-        if (resizable && windowResizeHandler)
-            (*windowResizeHandler)(ea.getWindowWidth(), ea.getWindowHeight());
+        if (resizable)
+          globals->get_renderer()->resize(ea.getWindowWidth(), ea.getWindowHeight());
+        statsHandler->handle(ea, us);
+      #ifdef SG_MAC
+        // work around OSG Cocoa-Viewer issue with resize event handling,
+        // where resize events are queued up, then dispatched in a batch, with
+        // no interveningd drawing calls.
+        puCleanUpJunk();
+      #endif
         return true;
      case osgGA::GUIEventAdapter::CLOSE_WINDOW:
     case osgGA::GUIEventAdapter::QUIT_APPLICATION:
@@ -259,7 +293,6 @@ void FGEventHandler::handleKey(const osgGA::GUIEventAdapter& ea, int& key,
     case GUIEventAdapter::KEY_F10:         key = PU_KEY_F10;       break;
     case GUIEventAdapter::KEY_F11:         key = PU_KEY_F11;       break;
     case GUIEventAdapter::KEY_F12:         key = PU_KEY_F12;       break;
-    case GUIEventAdapter::KEY_KP_Delete:   key = '.';  break;
     case GUIEventAdapter::KEY_KP_Enter:    key = '\r'; break;
     case GUIEventAdapter::KEY_KP_Add:      key = '+';  break;
     case GUIEventAdapter::KEY_KP_Divide:   key = '/';  break;
@@ -268,13 +301,30 @@ void FGEventHandler::handleKey(const osgGA::GUIEventAdapter& ea, int& key,
     }
     osgGA::GUIEventAdapter::EventType eventType = ea.getEventType();
 
+#ifdef __APPLE__
+    // Num Lock is always true on Mac
     std::map<int, int>::iterator numPadIter = numlockKeyMap.find(key);
-
     if (numPadIter != numlockKeyMap.end()) {
-        if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_NUM_LOCK) {
+        key = numPadIter->second;
+    }
+#else
+    if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_NUM_LOCK)
+    {
+        // NumLock on: map to numeric keys
+        std::map<int, int>::iterator numPadIter = numlockKeyMap.find(key);
+        if (numPadIter != numlockKeyMap.end()) {
             key = numPadIter->second;
         }
     }
+    else
+    {
+        // NumLock off: map to PU arrow keys
+        std::map<int, int>::iterator numPadIter = noNumlockKeyMap.find(key);
+        if (numPadIter != noNumlockKeyMap.end()) {
+            key = numPadIter->second;
+        }
+    }
+#endif
 
     modifiers = osgToFGModifiers(ea.getModKeyMask());
     currentModifiers = modifiers;