1
0
Fork 0

Canvas GUIMgr: remove coupling on FGRenderer

This commit is contained in:
James Turner 2022-03-09 16:45:41 +00:00
parent 52731a7c04
commit 7613cb3ce7
4 changed files with 42 additions and 26 deletions

View file

@ -21,8 +21,6 @@
#include <Main/fg_os.hxx> #include <Main/fg_os.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Viewer/CameraGroup.hxx>
#include <Viewer/renderer.hxx>
#include <simgear/canvas/Canvas.hxx> #include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasPlacement.hxx> #include <simgear/canvas/CanvasPlacement.hxx>
@ -32,6 +30,7 @@
#include <osg/BlendFunc> #include <osg/BlendFunc>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <osgViewer/View>
#include <osgGA/GUIEventHandler> #include <osgGA/GUIEventHandler>
class DesktopGroup; class DesktopGroup;
@ -117,7 +116,7 @@ class DesktopGroup:
public sc::Group public sc::Group
{ {
public: public:
DesktopGroup(); DesktopGroup(osgViewer::View* view);
void setFocusWindow(const sc::WindowPtr& window); void setFocusWindow(const sc::WindowPtr& window);
@ -203,7 +202,7 @@ bool GUIEventHandler::handle( const osgEA& ea,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
DesktopGroup::DesktopGroup(): DesktopGroup::DesktopGroup(osgViewer::View* view):
Group(sc::CanvasPtr(), fgGetNode("/sim/gui/canvas", true)), Group(sc::CanvasPtr(), fgGetNode("/sim/gui/canvas", true)),
_cb_mouse_mode( this, _cb_mouse_mode( this,
&DesktopGroup::handleMouseMode, &DesktopGroup::handleMouseMode,
@ -211,7 +210,7 @@ DesktopGroup::DesktopGroup():
_width(_node, "size[0]"), _width(_node, "size[0]"),
_height(_node, "size[1]") _height(_node, "size[1]")
{ {
auto camera = flightgear::getGUICamera(flightgear::CameraGroup::getDefault()); auto camera = view->getCamera();
if( !camera ) if( !camera )
{ {
SG_LOG(SG_GUI, SG_WARN, "DesktopGroup: failed to get GUI camera."); SG_LOG(SG_GUI, SG_WARN, "DesktopGroup: failed to get GUI camera.");
@ -642,6 +641,12 @@ GUIMgr::GUIMgr()
} }
//------------------------------------------------------------------------------
void GUIMgr::setGUIView(osgViewer::View* view)
{
_viewerView = view;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
sc::WindowPtr GUIMgr::createWindow(const std::string& name) sc::WindowPtr GUIMgr::createWindow(const std::string& name)
{ {
@ -654,13 +659,14 @@ sc::WindowPtr GUIMgr::createWindow(const std::string& name)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void GUIMgr::init() void GUIMgr::init()
{ {
if( _desktop && _event_handler ) assert(_viewerView);
if( _desktop && _event_handler )
{ {
SG_LOG(SG_GUI, SG_WARN, "GUIMgr::init() already initialized."); SG_LOG(SG_GUI, SG_WARN, "GUIMgr::init() already initialized.");
return; return;
} }
DesktopPtr desktop( new DesktopGroup ); DesktopPtr desktop( new DesktopGroup(_viewerView) );
desktop->handleResize desktop->handleResize
( (
0, 0,
@ -671,9 +677,7 @@ void GUIMgr::init()
_desktop = desktop; _desktop = desktop;
_event_handler = new GUIEventHandler(desktop); _event_handler = new GUIEventHandler(desktop);
globals->get_renderer() _viewerView->getEventHandlers()
->getView()
->getEventHandlers()
// GUI is on top of everything so lets install as first event handler // GUI is on top of everything so lets install as first event handler
.push_front( _event_handler ); .push_front( _event_handler );
@ -705,11 +709,11 @@ void GUIMgr::shutdown()
if( _event_handler ) if( _event_handler )
{ {
globals->get_renderer() _viewerView->removeEventHandler( _event_handler );
->getView()
->removeEventHandler( _event_handler );
_event_handler = 0; _event_handler = 0;
} }
_viewerView = nullptr;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -766,5 +770,6 @@ GUIMgr::addWindowPlacement( SGPropertyNode* placement,
// Register the subsystem. // Register the subsystem.
SGSubsystemMgr::Registrant<GUIMgr> registrantGUIMgr( SGSubsystemMgr::Registrant<GUIMgr> registrantGUIMgr(
SGSubsystemMgr::DISPLAY, SGSubsystemMgr::DISPLAY,
{{"viewer", SGSubsystemMgr::Dependency::HARD}, {
{"FGRenderer", SGSubsystemMgr::Dependency::NONSUBSYSTEM_HARD}}); {"viewer", SGSubsystemMgr::Dependency::HARD},
});

View file

@ -28,6 +28,7 @@
#include <osg/Geode> #include <osg/Geode>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
namespace osgViewer { class View; }
namespace osgGA namespace osgGA
{ {
class GUIEventAdapter; class GUIEventAdapter;
@ -70,9 +71,14 @@ public:
*/ */
void ungrabPointer(const simgear::canvas::WindowPtr& window); void ungrabPointer(const simgear::canvas::WindowPtr& window);
/**
* specify the osgViewer::View which contains the GUI.
*/
void setGUIView(osgViewer::View* view);
protected: protected:
simgear::canvas::GroupPtr _desktop; simgear::canvas::GroupPtr _desktop;
osg::ref_ptr<GUIEventHandler> _event_handler; osg::ref_ptr<GUIEventHandler> _event_handler;
osg::ref_ptr<osgViewer::View> _viewerView;;
simgear::canvas::Placements simgear::canvas::Placements
addWindowPlacement( SGPropertyNode* placement, addWindowPlacement( SGPropertyNode* placement,

View file

@ -126,18 +126,20 @@ NewGUI::init ()
SGPath p(globals->get_fg_root(), "gui/dialogs"); SGPath p(globals->get_fg_root(), "gui/dialogs");
readDir(p); readDir(p);
SGPath aircraftDialogDir(fgGetString("/sim/aircraft-dir"), "gui/dialogs"); if (fgGetBool("/sim/gui/startup") == false) {
if (aircraftDialogDir.exists()) { SGPath aircraftDialogDir(fgGetString("/sim/aircraft-dir"), "gui/dialogs");
readDir(aircraftDialogDir); if (aircraftDialogDir.exists()) {
} readDir(aircraftDialogDir);
}
// Read XML dialogs made available by registered add-ons // Read XML dialogs made available by registered add-ons
const auto& addonManager = flightgear::addons::AddonManager::instance(); const auto& addonManager = flightgear::addons::AddonManager::instance();
for (const auto& addon: addonManager->registeredAddons()) { for (const auto& addon: addonManager->registeredAddons()) {
SGPath addonDialogDir = addon->getBasePath() / "gui/dialogs"; SGPath addonDialogDir = addon->getBasePath() / "gui/dialogs";
if (addonDialogDir.exists()) { if (addonDialogDir.exists()) {
readDir(addonDialogDir); readDir(addonDialogDir);
}
} }
} }

View file

@ -1103,7 +1103,10 @@ void fgCreateSubsystems(bool duringReset) {
simgear::canvas::SystemAdapterPtr(new canvas::FGCanvasSystemAdapter) simgear::canvas::SystemAdapterPtr(new canvas::FGCanvasSystemAdapter)
); );
globals->add_subsystem("Canvas", new CanvasMgr, SGSubsystemMgr::DISPLAY); globals->add_subsystem("Canvas", new CanvasMgr, SGSubsystemMgr::DISPLAY);
globals->add_subsystem("CanvasGUI", new GUIMgr, SGSubsystemMgr::DISPLAY);
auto canvasGui = new GUIMgr;
globals->add_subsystem("CanvasGUI", canvasGui, SGSubsystemMgr::DISPLAY);
canvasGui->setGUIView(globals->get_renderer()->getView());
#ifdef ENABLE_AUDIO_SUPPORT #ifdef ENABLE_AUDIO_SUPPORT
globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY); globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);