]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: proper forwarding of dirty and visible flags within nested canvases.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 12 May 2013 22:23:34 +0000 (00:23 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 12 May 2013 22:26:13 +0000 (00:26 +0200)
simgear/canvas/Canvas.cxx
simgear/canvas/Canvas.hxx
simgear/canvas/ODGauge.cxx
simgear/canvas/ODGauge.hxx
simgear/canvas/elements/CanvasImage.cxx

index cb8d6917d25ab3d785080b8773f957fd573c5626..7651635b9ba79f1c6fa73aad33650e8cc9384bf7 100644 (file)
@@ -107,7 +107,7 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  void Canvas::addDependentCanvas(const CanvasWeakPtr& canvas)
+  void Canvas::addParentCanvas(const CanvasWeakPtr& canvas)
   {
     if( canvas.expired() )
     {
@@ -115,19 +115,41 @@ namespace canvas
       (
         SG_GENERAL,
         SG_WARN,
-        "Canvas::addDependentCanvas: got an expired Canvas dependent on "
-        << _node->getPath()
+        "Canvas::addParentCanvas: got an expired parent: " << _node->getPath()
       );
       return;
     }
 
-    _dependent_canvases.insert(canvas);
+    _parent_canvases.insert(canvas);
   }
 
   //----------------------------------------------------------------------------
-  void Canvas::removeDependentCanvas(const CanvasWeakPtr& canvas)
+  void Canvas::addChildCanvas(const CanvasWeakPtr& canvas)
   {
-    _dependent_canvases.erase(canvas);
+    if( canvas.expired() )
+    {
+      SG_LOG
+      (
+        SG_GENERAL,
+        SG_WARN,
+        "Canvas::addChildCanvas: got an expired child: " << _node->getPath()
+      );
+      return;
+    }
+
+    _child_canvases.insert(canvas);
+  }
+
+  //----------------------------------------------------------------------------
+  void Canvas::removeParentCanvas(const CanvasWeakPtr& canvas)
+  {
+    _parent_canvases.erase(canvas);
+  }
+
+  //----------------------------------------------------------------------------
+  void Canvas::removeChildCanvas(const CanvasWeakPtr& canvas)
+  {
+    _child_canvases.erase(canvas);
   }
 
   //----------------------------------------------------------------------------
@@ -197,10 +219,18 @@ namespace canvas
 
     if( _visible || _render_always )
     {
+      BOOST_FOREACH(CanvasWeakPtr canvas, _child_canvases)
+      {
+        // TODO should we check if the image the child canvas is displayed
+        //      within is really visible?
+        if( !canvas.expired() )
+          canvas.lock()->_visible = true;
+      }
+
       if( _render_dirty )
       {
-        // Also mark all dependent (eg. recursively used) canvases as dirty
-        BOOST_FOREACH(CanvasWeakPtr canvas, _dependent_canvases)
+        // Also mark all canvases this canvas is displayed within as dirty
+        BOOST_FOREACH(CanvasWeakPtr canvas, _parent_canvases)
         {
           if( !canvas.expired() )
             canvas.lock()->_render_dirty = true;
@@ -340,13 +370,13 @@ namespace canvas
   //----------------------------------------------------------------------------
   int Canvas::getViewWidth() const
   {
-    return _view_width;
+    return _texture.getViewSize().x();
   }
 
   //----------------------------------------------------------------------------
   int Canvas::getViewHeight() const
   {
-    return _view_height;
+    return _texture.getViewSize().y();
   }
 
   //----------------------------------------------------------------------------
index efb5bdc2d32ef3f99ff8af67181f971c346763fb..c746e2876e3510baf5935f5ce8491d7ace364efa 100644 (file)
@@ -79,18 +79,24 @@ namespace canvas
       CanvasMgr* getCanvasMgr() const;
 
       /**
-       * Add a canvas which should be mared as dirty upon any change to this
+       * Add a canvas which should be marked as dirty upon any change to this
        * canvas.
        *
        * This mechanism is used to eg. redraw a canvas if it's displaying
        * another canvas (recursive canvases)
        */
-      void addDependentCanvas(const CanvasWeakPtr& canvas);
+      void addParentCanvas(const CanvasWeakPtr& canvas);
+
+      /**
+       * Add a canvas which should be marked visible if this canvas is visible.
+       */
+      void addChildCanvas(const CanvasWeakPtr& canvas);
 
       /**
        * Stop notifying the given canvas upon changes
        */
-      void removeDependentCanvas(const CanvasWeakPtr& canvas);
+      void removeParentCanvas(const CanvasWeakPtr& canvas);
+      void removeChildCanvas(const CanvasWeakPtr& canvas);
 
       GroupPtr createGroup(const std::string& name = "");
 
@@ -161,9 +167,9 @@ namespace canvas
 
       std::vector<SGPropertyNode*> _dirty_placements;
       std::vector<Placements> _placements;
-      std::set<CanvasWeakPtr> _dependent_canvases; //<! Canvases which use this
-                                                   //   canvas and should be
-                                                   //   notified about changes
+      std::set<CanvasWeakPtr> _parent_canvases, //<! Canvases showing this canvas
+                              _child_canvases;  //<! Canvases displayed within
+                                                //   this canvas
 
       typedef std::map<std::string, PlacementFactory> PlacementFactoryMap;
       static PlacementFactoryMap _placement_factories;
index 45edf9a9fa2e39e79667b641899449a1e3024192..17858db7514afb035a09786b4acd8a2e8730d12b 100644 (file)
@@ -98,6 +98,12 @@ namespace canvas
       updateCoordinateFrame();
   }
 
+  //----------------------------------------------------------------------------
+  osg::Vec2s ODGauge::getViewSize() const
+  {
+    return osg::Vec2s(_view_width, _view_height);
+  }
+
   //----------------------------------------------------------------------------
   void ODGauge::useImageCoords(bool use)
   {
index fc3d8b770d1c41204ed93f142f6e19479242348b..6c62823ef825f5c94d6e66b572f9c26a22dbded2 100644 (file)
@@ -71,6 +71,8 @@ namespace canvas
        */
       void setViewSize(int width, int height = -1);
 
+      osg::Vec2s getViewSize() const;
+
       /**
        * DEPRECATED
        *
index 7400833f19e5c11712792d0a42869e9fbdae878d..d4e56601908788c8f4972a6c0fb72f94bc5d45f1 100644 (file)
@@ -331,7 +331,9 @@ namespace canvas
   void Image::setSrcCanvas(CanvasPtr canvas)
   {
     if( !_src_canvas.expired() )
-      _src_canvas.lock()->removeDependentCanvas(_canvas);
+      _src_canvas.lock()->removeParentCanvas(_canvas);
+    if( !_canvas.expired() )
+      _canvas.lock()->removeChildCanvas(_src_canvas);
 
     _src_canvas = canvas;
     _geom->getOrCreateStateSet()
@@ -341,7 +343,10 @@ namespace canvas
     if( !_src_canvas.expired() )
     {
       setupDefaultDimensions();
-      _src_canvas.lock()->addDependentCanvas(_canvas);
+      _src_canvas.lock()->addParentCanvas(_canvas);
+
+      if( !_canvas.expired() )
+        _canvas.lock()->addChildCanvas(_src_canvas);
     }
   }