]> git.mxchange.org Git - flightgear.git/blobdiff - src/Canvas/gui_mgr.cxx
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / Canvas / gui_mgr.cxx
index b501a2a4065107b3b7709b2ab4e23254c0c0b0b2..453893886ba6ca100590fb8b7135c330242ab758 100644 (file)
@@ -136,27 +136,6 @@ class DesktopGroup:
 
       return Group::getChildFactory(type);
     }
-
-    /**
-     *
-     */
-    simgear::canvas::Placements
-    addPlacement(SGPropertyNode* node, simgear::canvas::CanvasPtr canvas)
-    {
-      const std::string& id = node->getStringValue("id");
-
-      simgear::canvas::Placements placements;
-      canvas::WindowPtr window = getChild<canvas::Window>(id);
-      if( window )
-      {
-        window->setCanvasContent(canvas);
-        placements.push_back(
-          simgear::canvas::PlacementPtr(
-            new WindowPlacement(node, window, canvas)
-        ));
-      }
-      return placements;
-    }
 };
 
 //------------------------------------------------------------------------------
@@ -199,13 +178,6 @@ DesktopGroup::DesktopGroup():
   assert(camera);
   camera->addChild( getMatrixTransform() );
 
-  simgear::canvas::Canvas::addPlacementFactory
-  (
-    "window",
-    boost::bind(&DesktopGroup::addPlacement, this, _1, _2)
-  );
-
-
   osg::StateSet* stateSet = _transform->getOrCreateStateSet();
   stateSet->setDataVariance(osg::Object::STATIC);
   stateSet->setRenderBinDetails(1000, "RenderBin");
@@ -226,6 +198,10 @@ DesktopGroup::DesktopGroup():
   // Do not change values on reinit
   _width.node()->setAttribute(SGPropertyNode::PRESERVE, true);
   _height.node()->setAttribute(SGPropertyNode::PRESERVE, true);
+
+  // Do not restore windows on reinit (all windows will need to be recreated,
+  // but hey it's a reset ;-))
+  _node->setAttribute(SGPropertyNode::PRESERVE, true);
 }
 
 //------------------------------------------------------------------------------
@@ -508,14 +484,9 @@ void DesktopGroup::handleMouseMode(SGPropertyNode* node)
 }
 
 //------------------------------------------------------------------------------
-GUIMgr::GUIMgr():
-  _desktop( new DesktopGroup ),
-  _event_handler( new GUIEventHandler(
-    boost::static_pointer_cast<DesktopGroup>(_desktop)
-  ))
+GUIMgr::GUIMgr()
 {
-  // We handle the property listener manually within ::init and ::shutdown.
-  _desktop->removeListener();
+
 }
 
 //------------------------------------------------------------------------------
@@ -534,32 +505,43 @@ canvas::WindowPtr GUIMgr::createWindow(const std::string& name)
 //------------------------------------------------------------------------------
 void GUIMgr::init()
 {
-  boost::static_pointer_cast<DesktopGroup>(_desktop)->handleResize
+  DesktopPtr desktop( new DesktopGroup );
+  desktop->handleResize
   (
     0,
     0,
     fgGetInt("/sim/startup/xsize"),
     fgGetInt("/sim/startup/ysize")
   );
+  _desktop = desktop;
 
+  _event_handler = new GUIEventHandler(desktop);
   globals->get_renderer()
          ->getViewer()
          ->getEventHandlers()
          // GUI is on top of everything so lets install as first event handler
          .push_front( _event_handler );
 
-  _desktop->getProps()->addChangeListener(_desktop.get());
+  simgear::canvas::Canvas::addPlacementFactory
+  (
+    "window",
+    boost::bind(&GUIMgr::addWindowPlacement, this, _1, _2)
+  );
+
   _desktop->getProps()->fireCreatedRecursive();
 }
 
 //------------------------------------------------------------------------------
 void GUIMgr::shutdown()
 {
-  _desktop->getProps()->removeChangeListener(_desktop.get());
+  _desktop->destroy();
+  _desktop.reset();
+  simgear::canvas::Canvas::removePlacementFactory("window");
 
   globals->get_renderer()
          ->getViewer()
          ->removeEventHandler( _event_handler );
+  _event_handler = 0;
 }
 
 //------------------------------------------------------------------------------
@@ -573,3 +555,23 @@ simgear::canvas::GroupPtr GUIMgr::getDesktop()
 {
   return _desktop;
 }
+
+//------------------------------------------------------------------------------
+simgear::canvas::Placements
+GUIMgr::addWindowPlacement( SGPropertyNode* placement,
+                            simgear::canvas::CanvasPtr canvas )
+{
+  const std::string& id = placement->getStringValue("id");
+
+  simgear::canvas::Placements placements;
+  canvas::WindowPtr window = _desktop->getChild<canvas::Window>(id);
+  if( window )
+  {
+    window->setCanvasContent(canvas);
+    placements.push_back(
+      simgear::canvas::PlacementPtr(
+        new WindowPlacement(placement, window, canvas)
+    ));
+  }
+  return placements;
+}