2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-04-25 05:04:54 +08:00
|
|
|
*
|
|
|
|
* This application is open source and may be redistributed and/or modified
|
|
|
|
* freely and without restriction, both in commericial and non commericial
|
|
|
|
* applications, as long as this copyright notice is maintained.
|
|
|
|
*
|
|
|
|
* This application is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osg/StateAttribute>
|
2005-04-25 21:37:12 +08:00
|
|
|
#include <osg/StateSet>
|
|
|
|
#include <osg/Notify>
|
2005-04-25 05:04:54 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
void StateAttribute::addParent(osg::StateSet* object)
|
|
|
|
{
|
|
|
|
_parents.push_back(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateAttribute::removeParent(osg::StateSet* object)
|
|
|
|
{
|
|
|
|
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object);
|
|
|
|
if (pitr!=_parents.end()) _parents.erase(pitr);
|
|
|
|
}
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
void StateAttribute::setUpdateCallback(Callback* uc)
|
|
|
|
{
|
2005-04-25 22:28:16 +08:00
|
|
|
osg::notify(osg::INFO)<<"StateAttribute::Setting Update callbacks"<<std::endl;
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
if (_updateCallback==uc) return;
|
|
|
|
|
|
|
|
int delta = 0;
|
|
|
|
if (_updateCallback.valid()) --delta;
|
|
|
|
if (uc) ++delta;
|
|
|
|
|
|
|
|
_updateCallback = uc;
|
|
|
|
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
2005-04-25 22:28:16 +08:00
|
|
|
osg::notify(osg::INFO)<<"Going to set StateAttribute parents"<<std::endl;
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
for(ParentList::iterator itr=_parents.begin();
|
|
|
|
itr!=_parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2005-04-25 22:28:16 +08:00
|
|
|
osg::notify(osg::INFO)<<" Setting StateAttribute parent"<<std::endl;
|
|
|
|
|
2005-04-25 21:37:12 +08:00
|
|
|
(*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateAttribute::setEventCallback(Callback* ec)
|
|
|
|
{
|
2005-04-25 22:28:16 +08:00
|
|
|
osg::notify(osg::INFO)<<"StateAttribute::Setting Event callbacks"<<std::endl;
|
2005-04-25 21:37:12 +08:00
|
|
|
|
2005-05-19 02:31:03 +08:00
|
|
|
if (_eventCallback==ec) return;
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
int delta = 0;
|
2005-05-19 02:31:03 +08:00
|
|
|
if (_eventCallback.valid()) --delta;
|
2005-04-25 21:37:12 +08:00
|
|
|
if (ec) ++delta;
|
|
|
|
|
2005-05-19 02:31:03 +08:00
|
|
|
_eventCallback = ec;
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
for(ParentList::iterator itr=_parents.begin();
|
|
|
|
itr!=_parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2005-05-19 02:31:03 +08:00
|
|
|
(*itr)->setNumChildrenRequiringEventTraversal((*itr)->getNumChildrenRequiringEventTraversal()+delta);
|
2005-04-25 21:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|