1
0
Fork 0

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.
This commit is contained in:
Julian Smith 2021-04-11 14:01:46 +01:00
parent f08076c391
commit 04e664bb33
2 changed files with 32 additions and 25 deletions

View file

@ -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 <ea>'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

View file

@ -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);