]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: Propagate style changes on groups to children
authorThomas Geymayer <tomgey@gmail.com>
Thu, 6 Dec 2012 10:33:51 +0000 (11:33 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Thu, 6 Dec 2012 10:33:51 +0000 (11:33 +0100)
simgear/canvas/elements/CanvasElement.cxx
simgear/canvas/elements/CanvasElement.hxx
simgear/canvas/elements/CanvasGroup.cxx
simgear/canvas/elements/CanvasGroup.hxx

index 0ca940d1376ae3667581776fae65f8964ea3ca3a..b20fbd4bc54aa81a1d0aafcdee227282754a6944 100644 (file)
@@ -297,6 +297,18 @@ namespace canvas
     childChanged(child);
   }
 
+  //----------------------------------------------------------------------------
+  bool Element::setStyle(const SGPropertyNode* child)
+  {
+    StyleSetters::const_iterator setter =
+      _style_setters.find(child->getNameString());
+    if( setter == _style_setters.end() )
+      return false;
+
+    setter->second(child);
+    return true;
+  }
+
   //----------------------------------------------------------------------------
   void Element::setBoundingBox(const osg::BoundingBox& bb)
   {
@@ -364,17 +376,5 @@ namespace canvas
       setStyle(style.second);
   }
 
-  //----------------------------------------------------------------------------
-  bool Element::setStyle(const SGPropertyNode* child)
-  {
-    StyleSetters::const_iterator setter =
-      _style_setters.find(child->getNameString());
-    if( setter == _style_setters.end() )
-      return false;
-
-    setter->second(child);
-    return true;
-  }
-
 } // namespace canvas
 } // namespace simgear
index 9067c7295172dd89f0d49b953074b7efa5156aec..0d70390ebe467edf1c522b6292005edd79718973 100644 (file)
@@ -91,6 +91,8 @@ namespace canvas
                                  SGPropertyNode * child );
       virtual void valueChanged(SGPropertyNode * child);
 
+      virtual bool setStyle(const SGPropertyNode* child);
+
       /**
        * Write the given bounding box to the property tree
        */
@@ -182,7 +184,6 @@ namespace canvas
       void setDrawable(osg::Drawable* drawable);
 
       void setupStyle();
-      bool setStyle(const SGPropertyNode* child);
 
     private:
 
index e8158edf476c9a7838e93d4a65eba354b9c82b76..176af793e2e9d1cf5ff1c254d7366bf4c993e03b 100644 (file)
@@ -132,6 +132,23 @@ namespace canvas
     return false;
   }
 
+  //----------------------------------------------------------------------------
+  bool Group::setStyle(const SGPropertyNode* style)
+  {
+    if(    style->getParent() != _node
+        && _style.find(style->getNameString()) != _style.end() )
+      return false;
+
+    bool handled = false;
+    BOOST_FOREACH( ChildList::value_type child, _children )
+    {
+      if( child.second->setStyle(style) )
+        handled = true;
+    }
+
+    return handled;
+  }
+
   //----------------------------------------------------------------------------
   osg::BoundingBox Group::getTransformedBounds(const osg::Matrix& m) const
   {
@@ -174,6 +191,7 @@ namespace canvas
     }
 
     _style[ child->getNameString() ] = child;
+    setStyle(child);
   }
 
   //----------------------------------------------------------------------------
index 02ea7e8b82873edd6fb42858828c01be5615ed3e..cd9c0bfdbbc22bfecb5f0f6e27bb9976d60ac227 100644 (file)
@@ -58,6 +58,8 @@ namespace canvas
 
       virtual bool traverse(EventVisitor& visitor);
 
+      virtual bool setStyle(const SGPropertyNode* child);
+
       virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
 
     protected: