]> git.mxchange.org Git - simgear.git/commitdiff
Allow canvas::Placements to have own properties
authorThomas Geymayer <tomgey@gmail.com>
Wed, 21 Nov 2012 12:05:19 +0000 (13:05 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Wed, 21 Nov 2012 12:05:19 +0000 (13:05 +0100)
simgear/canvas/Canvas.cxx
simgear/canvas/Canvas.hxx
simgear/canvas/CanvasPlacement.cxx
simgear/canvas/CanvasPlacement.hxx

index 350fdf9563edec6521d2e888c122a80aa91720b6..3112fcb3b9133eb7f5628c4b10adbdf9e8b1f61c 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "Canvas.hxx"
 #include <simgear/canvas/MouseEvent.hxx>
+#include <simgear/canvas/CanvasPlacement.hxx>
 #include <simgear/scene/util/parse_color.hxx>
 #include <simgear/scene/util/RenderConstants.hxx>
 
@@ -382,6 +383,21 @@ namespace canvas
     if(    node->getParent()->getParent() == _node
         && node->getParent()->getNameString() == "placement" )
     {
+      bool placement_dirty = false;
+      BOOST_FOREACH(Placements& placements, _placements)
+      {
+        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;
+
       // prevent double updates...
       for( size_t i = 0; i < _dirty_placements.size(); ++i )
       {
index 11c832c943bbcc501f735ea9c50d4eb43174091e..848908c36bbd7067242efe65f2e71f6d44a4b506 100644 (file)
@@ -159,12 +159,12 @@ namespace canvas
       bool _render_always; //<! Used to disable automatic lazy rendering (culling)
 
       std::vector<SGPropertyNode*> _dirty_placements;
-      std::vector<canvas::Placements> _placements;
+      std::vector<Placements> _placements;
       std::set<CanvasWeakPtr> _dependent_canvases; //<! Canvases which use this
                                                    //   canvas and should be
                                                    //   notified about changes
 
-      typedef std::map<std::string, canvas::PlacementFactory> PlacementFactoryMap;
+      typedef std::map<std::string, PlacementFactory> PlacementFactoryMap;
       static PlacementFactoryMap _placement_factories;
 
       virtual void setSelf(const PropertyBasedElementPtr& self);
index 3024f302ae65d0e804f7226d7ba32a3e405b4c81..1ff2a45f335866fe2dfc9f11c18733fc314cf4d2 100644 (file)
@@ -17,6 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
 
 #include "CanvasPlacement.hxx"
+#include <simgear/props/props.hxx>
 
 namespace simgear
 {
@@ -24,7 +25,8 @@ namespace canvas
 {
 
   //----------------------------------------------------------------------------
-  Placement::Placement()
+  Placement::Placement(SGPropertyNode* node):
+    _node(node)
   {
 
   }
@@ -35,5 +37,23 @@ namespace canvas
 
   }
 
+  //----------------------------------------------------------------------------
+  SGConstPropertyNode_ptr Placement::getProps() const
+  {
+    return _node;
+  }
+
+  //----------------------------------------------------------------------------
+  SGPropertyNode_ptr Placement::getProps()
+  {
+    return _node;
+  }
+
+  //----------------------------------------------------------------------------
+  bool Placement::childChanged(SGPropertyNode* child)
+  {
+    return false;
+  }
+
 } // namespace canvas
 } // namespace simgear
index 05d85ba35f145e0caa7afd2e6858d70d8c2aec03..cda367955ccdf34e0c3051bca49a9dac19a5596a 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef CANVAS_PLACEMENT_HXX_
 #define CANVAS_PLACEMENT_HXX_
 
+#include <simgear/props/propsfwd.hxx>
+
 namespace simgear
 {
 namespace canvas
@@ -27,9 +29,17 @@ namespace canvas
   class Placement
   {
     public:
-      Placement();
+      Placement(SGPropertyNode* node);
       virtual ~Placement() = 0;
 
+      SGConstPropertyNode_ptr getProps() const;
+      SGPropertyNode_ptr getProps();
+
+      virtual bool childChanged(SGPropertyNode* child);
+
+    protected:
+      SGPropertyNode_ptr _node;
+
     private:
       Placement(const Placement&) /* = delete */;
       Placement& operator=(const Placement&) /* = delete */;