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:
parent
f08076c391
commit
04e664bb33
2 changed files with 32 additions and 25 deletions
|
@ -43,7 +43,8 @@ FGEventHandler::FGEventHandler() :
|
||||||
resizable(true),
|
resizable(true),
|
||||||
mouseWarped(false),
|
mouseWarped(false),
|
||||||
scrollButtonPressed(false),
|
scrollButtonPressed(false),
|
||||||
changeStatsCameraRenderOrder(false)
|
changeStatsCameraRenderOrder(false),
|
||||||
|
m_composite_viewer_enabled(fgGetNode("/sim/rendering/composite-viewer-enabled", true))
|
||||||
{
|
{
|
||||||
using namespace osgGA;
|
using namespace osgGA;
|
||||||
statsHandler->setKeyEventTogglesOnScreenStats(displayStatsKey);
|
statsHandler->setKeyEventTogglesOnScreenStats(displayStatsKey);
|
||||||
|
@ -79,19 +80,10 @@ void FGEventHandler::init(const osgGA::GUIEventAdapter& ea,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
enum WindowType
|
|
||||||
{
|
|
||||||
WindowType_NONE,
|
|
||||||
WindowType_MAIN,
|
|
||||||
WindowType_SVIEW
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calculate event coordinates in the viewport of the GUI camera, if
|
// Calculate event coordinates in the viewport of the GUI camera, if
|
||||||
// possible. Otherwise sets (x, y) to (-1, -1).
|
// possible. Otherwise sets (x, y) to (-1, -1).
|
||||||
WindowType
|
FGEventHandler::WindowType
|
||||||
eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
|
FGEventHandler::eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
|
||||||
int& x, int& y)
|
int& x, int& y)
|
||||||
{
|
{
|
||||||
WindowType ret = WindowType_NONE;
|
WindowType ret = WindowType_NONE;
|
||||||
|
@ -109,16 +101,9 @@ eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
|
||||||
|
|
||||||
osg::Viewport* vport;
|
osg::Viewport* vport;
|
||||||
|
|
||||||
if (eventGC == main_window->gc.get()) {
|
if (m_composite_viewer_enabled->getBoolValue()
|
||||||
osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
|
&& eventGC != main_window->gc.get()) {
|
||||||
if (!guiCamera)
|
// CompositeViewer is enabled and this is not the main window.
|
||||||
return WindowType_NONE;
|
|
||||||
vport = guiCamera->getViewport();
|
|
||||||
if (!vport)
|
|
||||||
return WindowType_NONE;
|
|
||||||
ret = WindowType_MAIN;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
simgear::compositor::Compositor* compositor = SviewGetEventViewport(ea);
|
simgear::compositor::Compositor* compositor = SviewGetEventViewport(ea);
|
||||||
if (!compositor) {
|
if (!compositor) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "SviewGetEventViewport() returned nullptr");
|
SG_LOG(SG_GENERAL, SG_ALERT, "SviewGetEventViewport() returned nullptr");
|
||||||
|
@ -131,6 +116,15 @@ eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
|
||||||
}
|
}
|
||||||
ret = WindowType_SVIEW;
|
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
|
// Scale x, y to the dimensions of the window
|
||||||
double wx = (((ea.getX() - ea.getXmin()) / (ea.getXmax() - ea.getXmin()))
|
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
|
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
|
this. Unfortunately OSG also messes up <ea>'s graphics context pointer so this
|
||||||
does't alwys work. */
|
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 x;
|
||||||
int y;
|
int y;
|
||||||
return eventToViewport(ea, us, x, y) == WindowType_MAIN;
|
return eventToViewport(ea, us, x, y) == WindowType_MAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FGEventHandler::setWindowRectangleInteriorWithCorrection(osgViewer::GraphicsWindow* window, int x, int y, int width, int height)
|
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
|
// Store (x y) in our state so that our handle() event handler can
|
||||||
|
|
|
@ -133,6 +133,21 @@ private:
|
||||||
int m_setWindowRectangle_called_y = 0;
|
int m_setWindowRectangle_called_y = 0;
|
||||||
int m_setWindowRectangle_delta_x = 0;
|
int m_setWindowRectangle_delta_x = 0;
|
||||||
int m_setWindowRectangle_delta_y = 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);
|
bool eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
|
||||||
|
|
Loading…
Add table
Reference in a new issue