1
0
Fork 0

Canvas: Support z-index inside Groups/Maps

This commit is contained in:
Thomas Geymayer 2012-09-26 17:58:52 +02:00
parent 872e84d827
commit 3b10fc5f3e
4 changed files with 77 additions and 5 deletions

View file

@ -170,9 +170,14 @@ void Canvas::update(double delta_time_sec)
_texture.useImageCoords(true);
_texture.useStencil(true);
_texture.allocRT(_camera_callback);
_texture.getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f , 1.0f));
_texture.getCamera()->addChild(_root_group->getMatrixTransform());
_texture.getCamera()->setFinalDrawCallback(new DrawCallback(this));
osg::Camera* camera = _texture.getCamera();
camera->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f , 1.0f));
camera->addChild(_root_group->getMatrixTransform());
camera->setFinalDrawCallback(new DrawCallback(this));
// Ensure objects are drawn in order of traversal
camera->getOrCreateStateSet()->setBinName("TraversalOrderBin");
if( _texture.serviceable() )
{

View file

@ -147,4 +147,68 @@ namespace canvas
}
}
//----------------------------------------------------------------------------
void Group::childChanged(SGPropertyNode* node)
{
if( node->getParent()->getParent() == _node
&& node->getNameString() == "z-index" )
return handleZIndexChanged(node->getParent(), node->getIntValue());
}
//----------------------------------------------------------------------------
void Group::handleZIndexChanged(SGPropertyNode* node, int z_index)
{
ChildFinder pred(node);
ChildList::iterator child =
std::find_if(_children.begin(), _children.end(), pred);
if( child == _children.end() )
return;
osg::Node* tf = child->second->getMatrixTransform();
int index = _transform->getChildIndex(tf),
index_new = index;
ChildList::iterator next = child;
++next;
while( next != _children.end()
&& next->first->getIntValue("z-index", 0) < z_index )
{
++index_new;
++next;
}
if( index_new != index )
{
_children.insert(next, *child);
}
else
{
ChildList::iterator prev = child;
while( prev != _children.begin()
&& (--prev)->first->getIntValue("z-index", 0) > z_index)
{
--index_new;
}
if( index == index_new )
return;
_children.insert(prev, *child);
}
_transform->removeChild(index);
_transform->insertChild(index_new, tf);
_children.erase(child);
SG_LOG
(
SG_GENERAL,
SG_INFO,
"canvas::Group: Moved element " << index << " to position " << index_new
);
}
} // namespace canvas

View file

@ -51,6 +51,9 @@ namespace canvas
virtual void childAdded(SGPropertyNode * child);
virtual void childRemoved(SGPropertyNode * child);
virtual void childChanged(SGPropertyNode * child);
void handleZIndexChanged(SGPropertyNode* node, int z_index);
};
} // namespace canvas

View file

@ -178,7 +178,7 @@ namespace canvas
void Map::childChanged(SGPropertyNode * child)
{
if( child->getParent() != _node )
return;
return Group::childChanged(child);
if( child->getNameString() == "ref-lat"
|| child->getNameString() == "ref-lon" )
@ -189,7 +189,7 @@ namespace canvas
else if( child->getNameString() == "range" )
_projection->setRange(child->getDoubleValue());
else
return;
return Group::childChanged(child);
_projection_dirty = true;
}