Fixes to Switch so that it defaults to adding children switched on, and adds

a flag to control whether children and added as true or false.
This commit is contained in:
Robert Osfield
2002-10-07 20:17:57 +00:00
parent 525fc2f746
commit 41768f6824
3 changed files with 20 additions and 10 deletions

View File

@@ -28,8 +28,14 @@ class SG_EXPORT Switch : public Group
virtual void traverse(NodeVisitor& nv);
void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; }
bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
virtual bool addChild( Node *child );
virtual bool addChild( Node *child, bool value );
virtual bool removeChild( Node *child );
void setValue(unsigned int pos,bool value);
@@ -73,7 +79,8 @@ class SG_EXPORT Switch : public Group
virtual ~Switch() {}
// this is effectively a bit mask.
ValueList _values;
bool _newChildDefaultValue;
ValueList _values;
};
}

View File

@@ -12,8 +12,6 @@ bool AnimationPath::getInterpolatedControlPoint(double time,ControlPoint& contro
{
if (_timeControlPointMap.empty()) return false;
switch(_loopMode)
{
case(SWING):

View File

@@ -4,16 +4,14 @@
using namespace osg;
/**
* Switch constructor. The default setting of _value is
* ALL_CHILDREN_OFF.
*/
Switch::Switch()
Switch::Switch():
_newChildDefaultValue(true)
{
}
Switch::Switch(const Switch& sw,const CopyOp& copyop):
Group(sw,copyop),
_newChildDefaultValue(sw._newChildDefaultValue),
_values(sw._values)
{
}
@@ -41,10 +39,15 @@ void Switch::traverse(NodeVisitor& nv)
}
bool Switch::addChild( Node *child )
{
return addChild(child,_newChildDefaultValue);
}
bool Switch::addChild( Node *child, bool value )
{
if (Group::addChild(child))
{
if (_children.size()>_values.size()) _values.resize(_children.size(),false);
if (_children.size()>_values.size()) _values.resize(_children.size(),value);
return true;
}
return false;
@@ -63,7 +66,7 @@ bool Switch::removeChild( Node *child )
void Switch::setValue(unsigned int pos,bool value)
{
if (pos>=_values.size()) _values.resize(pos+1,false);
if (pos>=_values.size()) _values.resize(pos+1,_newChildDefaultValue);
_values[pos]=value;
}
@@ -100,6 +103,7 @@ void Switch::setValue(int value)
break;
case(ALL_CHILDREN_OFF):
{
_newChildDefaultValue = false;
for(ValueList::iterator itr=_values.begin();
itr!=_values.end();
++itr)
@@ -110,6 +114,7 @@ void Switch::setValue(int value)
}
case(ALL_CHILDREN_ON):
{
_newChildDefaultValue = true;
for(ValueList::iterator itr=_values.begin();
itr!=_values.end();
++itr)