]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/Canvas.cxx
Canvas::Text: add line-height property.
[simgear.git] / simgear / canvas / Canvas.cxx
index 7651635b9ba79f1c6fa73aad33650e8cc9384bf7..fa6712389c22ecaf2357cfb9b225f98f090ed63d 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/foreach.hpp>
-#include <iostream>
 
 namespace simgear
 {
@@ -76,9 +75,13 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  Canvas::~Canvas()
+  void Canvas::onDestroy()
   {
-
+    if( _root_group )
+    {
+      _root_group->clearEventListener();
+      _root_group->onDestroy();
+    }
   }
 
   //----------------------------------------------------------------------------
@@ -106,6 +109,12 @@ namespace canvas
     return _canvas_mgr;
   }
 
+  //----------------------------------------------------------------------------
+  bool Canvas::isInit() const
+  {
+    return _texture.serviceable();
+  }
+
   //----------------------------------------------------------------------------
   void Canvas::addParentCanvas(const CanvasWeakPtr& canvas)
   {
@@ -115,7 +124,8 @@ namespace canvas
       (
         SG_GENERAL,
         SG_WARN,
-        "Canvas::addParentCanvas: got an expired parent: " << _node->getPath()
+        "Canvas::addParentCanvas(" << _node->getPath(true) << "): "
+        "got an expired parent!"
       );
       return;
     }
@@ -132,7 +142,8 @@ namespace canvas
       (
         SG_GENERAL,
         SG_WARN,
-        "Canvas::addChildCanvas: got an expired child: " << _node->getPath()
+        "Canvas::addChildCanvas(" << _node->getPath(true) << "): "
+        " got an expired child!"
       );
       return;
     }
@@ -155,10 +166,25 @@ namespace canvas
   //----------------------------------------------------------------------------
   GroupPtr Canvas::createGroup(const std::string& name)
   {
-    return boost::dynamic_pointer_cast<Group>
-    (
-      _root_group->createChild("group", name)
-    );
+    return _root_group->createChild<Group>(name);
+  }
+
+  //----------------------------------------------------------------------------
+  GroupPtr Canvas::getGroup(const std::string& name)
+  {
+    return _root_group->getChild<Group>(name);
+  }
+
+  //----------------------------------------------------------------------------
+  GroupPtr Canvas::getOrCreateGroup(const std::string& name)
+  {
+    return _root_group->getOrCreateChild<Group>(name);
+  }
+
+  //----------------------------------------------------------------------------
+  GroupPtr Canvas::getRootGroup()
+  {
+    return _root_group;
   }
 
   //----------------------------------------------------------------------------
@@ -201,9 +227,6 @@ namespace canvas
 
       camera->addChild(_root_group->getMatrixTransform());
 
-      // Ensure objects are drawn in order of traversal
-      camera->getOrCreateStateSet()->setBinName("TraversalOrderBin");
-
       if( _texture.serviceable() )
       {
         setStatusFlags(STATUS_OK);
@@ -379,6 +402,12 @@ namespace canvas
     return _texture.getViewSize().y();
   }
 
+  //----------------------------------------------------------------------------
+  SGRect<int> Canvas::getViewport() const
+  {
+    return SGRect<int>(0, 0, getViewWidth(), getViewHeight());
+  }
+
   //----------------------------------------------------------------------------
   bool Canvas::handleMouseEvent(const MouseEventPtr& event)
   {
@@ -387,7 +416,8 @@ namespace canvas
 
     EventVisitor visitor( EventVisitor::TRAVERSE_DOWN,
                           event->getClientPos(),
-                          event->getDelta() );
+                          event->getDelta(),
+                          _root_group );
     if( !_root_group->accept(visitor) )
       return false;
 
@@ -434,21 +464,26 @@ namespace canvas
     if(    node->getParent()->getParent() == _node
         && node->getParent()->getNameString() == "placement" )
     {
-      bool placement_dirty = false;
-      BOOST_FOREACH(Placements& placements, _placements)
+      size_t index = node->getIndex();
+      if( index < _placements.size() )
       {
-        BOOST_FOREACH(PlacementPtr& placement, placements)
+        Placements& placements = _placements[index];
+        if( !placements.empty() )
         {
-          // check if change can be directly handled by placement
-          if(    placement->getProps() == node->getParent()
-              && !placement->childChanged(node) )
-            placement_dirty = true;
+          bool placement_dirty = false;
+          BOOST_FOREACH(PlacementPtr& placement, placements)
+          {
+            // check if change can be directly handled by placement
+            if(    placement->getProps() == node->getParent()
+                && !placement->childChanged(node) )
+              placement_dirty = true;
+          }
+
+          if( !placement_dirty )
+            return;
         }
       }
 
-      if( !placement_dirty )
-        return;
-
       // prevent double updates...
       for( size_t i = 0; i < _dirty_placements.size(); ++i )
       {