]> git.mxchange.org Git - simgear.git/commitdiff
Ensure canvas is updated before displaying image containing a canvas
authorThomas Geymayer <tomgey@gmail.com>
Mon, 11 Mar 2013 20:22:43 +0000 (21:22 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 11 Mar 2013 20:22:43 +0000 (21:22 +0100)
simgear/canvas/elements/CanvasImage.cxx
simgear/canvas/elements/CanvasImage.hxx

index 9787b23200e45775fa699bbe41da2e6fa52cb5d3..cbf0055df9c03ee6036f5a73f921b0bb441f3091 100644 (file)
@@ -47,9 +47,11 @@ namespace canvas
   {
     public:
       CullCallback(const CanvasWeakPtr& canvas);
+      void cullNextFrame();
 
     private:
       CanvasWeakPtr _canvas;
+      mutable bool  _cull_next_frame;
 
       virtual bool cull( osg::NodeVisitor* nv,
                          osg::Drawable* drawable,
@@ -58,11 +60,18 @@ namespace canvas
 
   //----------------------------------------------------------------------------
   CullCallback::CullCallback(const CanvasWeakPtr& canvas):
-    _canvas( canvas )
+    _canvas( canvas ),
+    _cull_next_frame( false )
   {
 
   }
 
+  //----------------------------------------------------------------------------
+  void CullCallback::cullNextFrame()
+  {
+    _cull_next_frame = true;
+  }
+
   //----------------------------------------------------------------------------
   bool CullCallback::cull( osg::NodeVisitor* nv,
                            osg::Drawable* drawable,
@@ -71,8 +80,12 @@ namespace canvas
     if( !_canvas.expired() )
       _canvas.lock()->enableRendering();
 
-    // TODO check if window/image should be culled
-    return false;
+    if( !_cull_next_frame )
+      // TODO check if window/image should be culled
+      return false;
+
+    _cull_next_frame = false;
+    return true;
   }
 
   //----------------------------------------------------------------------------
@@ -288,6 +301,29 @@ namespace canvas
     }
   }
 
+  //----------------------------------------------------------------------------
+  void Image::valueChanged(SGPropertyNode* child)
+  {
+    // If the image is switched from invisible to visible, and it shows a
+    // canvas, we need to delay showing it by one frame to ensure the canvas is
+    // updated before the image is displayed.
+    //
+    // As canvas::Element handles and filters changes to the "visible" property
+    // we can not check this in Image::childChanged but instead have to override
+    // Element::valueChanged.
+    if(    !isVisible()
+        && child->getParent() == _node
+        && child->getNameString() == "visible"
+        && child->getBoolValue() )
+    {
+      CullCallback* cb = static_cast<CullCallback*>(_geom->getCullCallback());
+      if( cb )
+        cb->cullNextFrame();
+    }
+
+    Element::valueChanged(child);
+  }
+
   //----------------------------------------------------------------------------
   void Image::setSrcCanvas(CanvasPtr canvas)
   {
index 39813e343d75b7a89e37d3e42e75a053f769c3d9..fccc20f53757036677a9a87e1893860faeb038f1 100644 (file)
@@ -48,6 +48,7 @@ namespace canvas
       virtual ~Image();
 
       virtual void update(double dt);
+      virtual void valueChanged(SGPropertyNode* child);
 
       void setSrcCanvas(CanvasPtr canvas);
       CanvasWeakPtr getSrcCanvas() const;