1
0
Fork 0

Fix Camera ownership for GUI-Manager

We can't assume the default/primary Camera for the View, is the GUI
camera, so add explicit setting to get tooltips and popups working
again.
This commit is contained in:
James Turner 2022-03-11 12:42:20 +00:00
parent 5db4b5c871
commit b91b6c4516
3 changed files with 18 additions and 9 deletions

View file

@ -116,7 +116,7 @@ class DesktopGroup:
public sc::Group
{
public:
DesktopGroup(osgViewer::View* view);
DesktopGroup(osg::Camera* camera);
void setFocusWindow(const sc::WindowPtr& window);
@ -202,7 +202,7 @@ bool GUIEventHandler::handle( const osgEA& ea,
}
//------------------------------------------------------------------------------
DesktopGroup::DesktopGroup(osgViewer::View* view):
DesktopGroup::DesktopGroup(osg::Camera* camera):
Group(sc::CanvasPtr(), fgGetNode("/sim/gui/canvas", true)),
_cb_mouse_mode( this,
&DesktopGroup::handleMouseMode,
@ -210,7 +210,6 @@ DesktopGroup::DesktopGroup(osgViewer::View* view):
_width(_node, "size[0]"),
_height(_node, "size[1]")
{
auto camera = view->getCamera();
if( !camera )
{
SG_LOG(SG_GUI, SG_WARN, "DesktopGroup: failed to get GUI camera.");
@ -642,9 +641,10 @@ GUIMgr::GUIMgr()
}
//------------------------------------------------------------------------------
void GUIMgr::setGUIView(osgViewer::View* view)
void GUIMgr::setGUIViewAndCamera(osgViewer::View* view, osg::Camera* cam)
{
_viewerView = view;
_camera = cam;
}
//------------------------------------------------------------------------------
@ -666,7 +666,12 @@ void GUIMgr::init()
return;
}
DesktopPtr desktop( new DesktopGroup(_viewerView) );
auto camera = _camera;
if (!camera) {
camera = _viewerView->getCamera();
}
DesktopPtr desktop( new DesktopGroup(camera) );
desktop->handleResize
(
0,

View file

@ -29,6 +29,8 @@
#include <osg/MatrixTransform>
namespace osgViewer { class View; }
namespace osg { class Camera; }
namespace osgGA
{
class GUIEventAdapter;
@ -72,13 +74,14 @@ public:
void ungrabPointer(const simgear::canvas::WindowPtr& window);
/**
* specify the osgViewer::View which contains the GUI.
* specify the osgViewer::View and Camera
*/
void setGUIView(osgViewer::View* view);
void setGUIViewAndCamera(osgViewer::View* view, osg::Camera* cam);
protected:
simgear::canvas::GroupPtr _desktop;
osg::ref_ptr<GUIEventHandler> _event_handler;
osg::ref_ptr<osgViewer::View> _viewerView;;
osg::ref_ptr<osgViewer::View> _viewerView;
osg::ref_ptr<osg::Camera> _camera;
simgear::canvas::Placements
addWindowPlacement( SGPropertyNode* placement,

View file

@ -1106,7 +1106,8 @@ void fgCreateSubsystems(bool duringReset) {
auto canvasGui = new GUIMgr;
globals->add_subsystem("CanvasGUI", canvasGui, SGSubsystemMgr::DISPLAY);
canvasGui->setGUIView(globals->get_renderer()->getView());
auto guiCamera = flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
canvasGui->setGUIViewAndCamera(globals->get_renderer()->getView(), guiCamera);
#ifdef ENABLE_AUDIO_SUPPORT
globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);