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_props.hxx>
#include <Main/globals.hxx>
#include <Viewer/CameraGroup.hxx>
#include <Viewer/renderer.hxx>
#include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasPlacement.hxx>
@ -32,6 +30,7 @@
#include <osg/BlendFunc>
#include <osgViewer/Viewer>
#include <osgViewer/View>
#include <osgGA/GUIEventHandler>
class DesktopGroup;
@ -117,7 +116,7 @@ class DesktopGroup:
public sc::Group
{
public:
DesktopGroup();
DesktopGroup(osgViewer::View* view);
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)),
_cb_mouse_mode( this,
&DesktopGroup::handleMouseMode,
@ -211,7 +210,7 @@ DesktopGroup::DesktopGroup():
_width(_node, "size[0]"),
_height(_node, "size[1]")
{
auto camera = flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
auto camera = view->getCamera();
if( !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)
{
@ -654,13 +659,14 @@ sc::WindowPtr GUIMgr::createWindow(const std::string& name)
//------------------------------------------------------------------------------
void GUIMgr::init()
{
if( _desktop && _event_handler )
assert(_viewerView);
if( _desktop && _event_handler )
{
SG_LOG(SG_GUI, SG_WARN, "GUIMgr::init() already initialized.");
return;
}
DesktopPtr desktop( new DesktopGroup );
DesktopPtr desktop( new DesktopGroup(_viewerView) );
desktop->handleResize
(
0,
@ -671,9 +677,7 @@ void GUIMgr::init()
_desktop = desktop;
_event_handler = new GUIEventHandler(desktop);
globals->get_renderer()
->getView()
->getEventHandlers()
_viewerView->getEventHandlers()
// GUI is on top of everything so lets install as first event handler
.push_front( _event_handler );
@ -705,11 +709,11 @@ void GUIMgr::shutdown()
if( _event_handler )
{
globals->get_renderer()
->getView()
->removeEventHandler( _event_handler );
_viewerView->removeEventHandler( _event_handler );
_event_handler = 0;
}
_viewerView = nullptr;
}
//------------------------------------------------------------------------------
@ -766,5 +770,6 @@ GUIMgr::addWindowPlacement( SGPropertyNode* placement,
// Register the subsystem.
SGSubsystemMgr::Registrant<GUIMgr> registrantGUIMgr(
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/MatrixTransform>
namespace osgViewer { class View; }
namespace osgGA
{
class GUIEventAdapter;
@ -70,9 +71,14 @@ public:
*/
void ungrabPointer(const simgear::canvas::WindowPtr& window);
/**
* specify the osgViewer::View which contains the GUI.
*/
void setGUIView(osgViewer::View* view);
protected:
simgear::canvas::GroupPtr _desktop;
osg::ref_ptr<GUIEventHandler> _event_handler;
osg::ref_ptr<osgViewer::View> _viewerView;;
simgear::canvas::Placements
addWindowPlacement( SGPropertyNode* placement,

View file

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

View file

@ -1103,7 +1103,10 @@ void fgCreateSubsystems(bool duringReset) {
simgear::canvas::SystemAdapterPtr(new canvas::FGCanvasSystemAdapter)
);
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
globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);