Canvas: proper forwarding of dirty and visible flags within nested canvases.
This commit is contained in:
parent
d18cc81531
commit
d61b5827fd
@ -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();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
|
@ -98,6 +98,12 @@ namespace canvas
|
||||
updateCoordinateFrame();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
osg::Vec2s ODGauge::getViewSize() const
|
||||
{
|
||||
return osg::Vec2s(_view_width, _view_height);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void ODGauge::useImageCoords(bool use)
|
||||
{
|
||||
|
@ -71,6 +71,8 @@ namespace canvas
|
||||
*/
|
||||
void setViewSize(int width, int height = -1);
|
||||
|
||||
osg::Vec2s getViewSize() const;
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user