#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;
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),
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;
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);
}
return true;
case osgGA::GUIEventAdapter::RESIZE:
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:
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;
}
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;