From 04e664bb33f5ae35881b3b01a63b430b51a63ba9 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sun, 11 Apr 2021 14:01:46 +0100 Subject: [PATCH] src/Viewer/FGEventHandler.*: fixed mouse events in non-main window without CompositeViewer. Need to only test for sview window if /sim/rendering/composite-viewer-enabled is true. --- src/Viewer/FGEventHandler.cxx | 42 ++++++++++++++--------------------- src/Viewer/FGEventHandler.hxx | 15 +++++++++++++ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/Viewer/FGEventHandler.cxx b/src/Viewer/FGEventHandler.cxx index bf6d0550c..1569757db 100644 --- a/src/Viewer/FGEventHandler.cxx +++ b/src/Viewer/FGEventHandler.cxx @@ -43,7 +43,8 @@ FGEventHandler::FGEventHandler() : resizable(true), mouseWarped(false), scrollButtonPressed(false), - changeStatsCameraRenderOrder(false) + changeStatsCameraRenderOrder(false), + m_composite_viewer_enabled(fgGetNode("/sim/rendering/composite-viewer-enabled", true)) { using namespace osgGA; statsHandler->setKeyEventTogglesOnScreenStats(displayStatsKey); @@ -79,19 +80,10 @@ void FGEventHandler::init(const osgGA::GUIEventAdapter& ea, } #endif -namespace -{ -enum WindowType -{ - WindowType_NONE, - WindowType_MAIN, - WindowType_SVIEW -}; - // Calculate event coordinates in the viewport of the GUI camera, if // possible. Otherwise sets (x, y) to (-1, -1). -WindowType -eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us, +FGEventHandler::WindowType +FGEventHandler::eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us, int& x, int& y) { WindowType ret = WindowType_NONE; @@ -109,16 +101,9 @@ eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us, osg::Viewport* vport; - if (eventGC == main_window->gc.get()) { - osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault()); - if (!guiCamera) - return WindowType_NONE; - vport = guiCamera->getViewport(); - if (!vport) - return WindowType_NONE; - ret = WindowType_MAIN; - } - else { + if (m_composite_viewer_enabled->getBoolValue() + && eventGC != main_window->gc.get()) { + // CompositeViewer is enabled and this is not the main window. simgear::compositor::Compositor* compositor = SviewGetEventViewport(ea); if (!compositor) { SG_LOG(SG_GENERAL, SG_ALERT, "SviewGetEventViewport() returned nullptr"); @@ -131,6 +116,15 @@ eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us, } ret = WindowType_SVIEW; } + else { + osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault()); + if (!guiCamera) + return WindowType_NONE; + vport = guiCamera->getViewport(); + if (!vport) + return WindowType_NONE; + ret = WindowType_MAIN; + } // Scale x, y to the dimensions of the window double wx = (((ea.getX() - ea.getXmin()) / (ea.getXmax() - ea.getXmin())) @@ -152,15 +146,13 @@ enabled. It seems that OSG-3.4 incorrectly calls our event handler for extra view windows (e.g. resize/close events), so we try to detect this. Unfortunately OSG also messes up 's graphics context pointer so this does't alwys work. */ -bool isMainWindow(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us) +bool FGEventHandler::isMainWindow(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us) { int x; int y; return eventToViewport(ea, us, x, y) == WindowType_MAIN; } -} - void FGEventHandler::setWindowRectangleInteriorWithCorrection(osgViewer::GraphicsWindow* window, int x, int y, int width, int height) { // Store (x y) in our state so that our handle() event handler can diff --git a/src/Viewer/FGEventHandler.hxx b/src/Viewer/FGEventHandler.hxx index b593ee6e1..cb07f6fa8 100644 --- a/src/Viewer/FGEventHandler.hxx +++ b/src/Viewer/FGEventHandler.hxx @@ -133,6 +133,21 @@ private: int m_setWindowRectangle_called_y = 0; int m_setWindowRectangle_delta_x = 0; int m_setWindowRectangle_delta_y = 0; + + SGPropertyNode_ptr m_composite_viewer_enabled; + + enum WindowType + { + WindowType_NONE, + WindowType_MAIN, + WindowType_SVIEW + }; + WindowType + eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us, + int& x, int& y); + + bool isMainWindow(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); + }; bool eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);