]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/elements/CanvasGroup.cxx
First working version of DOM like Canvas event handling
[simgear.git] / simgear / canvas / elements / CanvasGroup.cxx
index fdcc7ae244454b882a3bc1934f99e73f51629c5c..0740026828c721d9146eeba92e56ea6a3e793514 100644 (file)
@@ -66,11 +66,11 @@ namespace canvas
 
   //----------------------------------------------------------------------------
   ElementPtr Group::createChild( const std::string& type,
-                                 const std::string& name )
+                                 const std::string& id )
   {
     SGPropertyNode* node = _node->addChild(type, 0, false);
-    if( !name.empty() )
-      node->setStringValue("name", name);
+    if( !id.empty() )
+      node->setStringValue("id", id);
 
     return getChild(node);
   }
@@ -85,6 +85,32 @@ namespace canvas
     return child->second;
   }
 
+  //----------------------------------------------------------------------------
+  ElementPtr Group::getElementById(const std::string& id)
+  {
+    std::vector<GroupPtr> groups;
+
+    BOOST_FOREACH( ChildList::value_type child, _children )
+    {
+      const ElementPtr& el = child.second;
+      if( el->getProps()->getStringValue("id") == id )
+        return el;
+
+      GroupPtr group = boost::dynamic_pointer_cast<Group>(el);
+      if( group )
+        groups.push_back(group);
+    }
+
+    BOOST_FOREACH( GroupPtr group, groups )
+    {
+      ElementPtr el = group->getElementById(id);
+      if( el )
+        return el;
+    }
+
+    return ElementPtr();
+  }
+
   //----------------------------------------------------------------------------
   void Group::update(double dt)
   {