1
0
Fork 0

Major change:

The "switch" layer type now takes any number of child layers, and will
use the first child that has a condition that evaluates to 'true' (no
condition is automatically true).  Previously, it could take only two
children, controlled by a boolean property.
This commit is contained in:
david 2003-03-09 03:34:29 +00:00
parent d94bd7526c
commit 191bb21888
3 changed files with 22 additions and 38 deletions

View file

@ -904,6 +904,7 @@ void
FGGroupLayer::draw ()
{
if (test()) {
transform();
int nLayers = _layers.size();
for (int i = 0; i < nLayers; i++)
_layers[i]->draw();
@ -1134,28 +1135,22 @@ FGTextLayer::Chunk::getValue () const
// Implementation of FGSwitchLayer.
////////////////////////////////////////////////////////////////////////
FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
FGInstrumentLayer * layer1,
FGInstrumentLayer * layer2)
: FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
FGSwitchLayer::FGSwitchLayer ()
: FGGroupLayer()
{
}
FGSwitchLayer::~FGSwitchLayer ()
{
delete _layer1;
delete _layer2;
}
void
FGSwitchLayer::draw ()
{
if (test()) {
transform();
if (_node->getBoolValue()) {
_layer1->draw();
} else {
_layer2->draw();
int nLayers = _layers.size();
for (int i = 0; i < nLayers; i++) {
if (_layers[i]->test()) {
_layers[i]->draw();
return;
}
}
}
}

View file

@ -442,7 +442,7 @@ public:
virtual void draw ();
// transfer pointer ownership
virtual void addLayer (FGInstrumentLayer * layer);
private:
protected:
vector<FGInstrumentLayer *> _layers;
};
@ -536,25 +536,18 @@ private:
/**
* A layer that switches between two other layers.
* A group layer that switches among its children.
*
* The usefulness of this layer is questionable now that all layers
* can have conditions, and it may be deprecated soon.
* The first layer that passes its condition will be drawn, and
* any following layers will be ignored.
*/
class FGSwitchLayer : public FGInstrumentLayer
class FGSwitchLayer : public FGGroupLayer
{
public:
// Transfer pointers!!
FGSwitchLayer (int w, int h, const SGPropertyNode * node,
FGInstrumentLayer * layer1,
FGInstrumentLayer * layer2);
virtual ~FGSwitchLayer ();
FGSwitchLayer ();
virtual void draw ();
private:
const SGPropertyNode * _node;
FGInstrumentLayer * _layer1, * _layer2;
};

View file

@ -436,11 +436,8 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
layer = new FGGroupLayer();
for (int i = 0; i < node->nChildren(); i++) {
const SGPropertyNode * child = node->getChild(i);
cerr << "Trying child " << child->getName() << endl;
if (!strcmp(child->getName(), "layer")) {
cerr << "succeeded!" << endl;
if (!strcmp(child->getName(), "layer"))
((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
}
}
}
@ -483,13 +480,12 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
// A switch instrument layer.
else if (type == "switch") {
SGPropertyNode * target =
fgGetNode(node->getStringValue("property"), true);
FGInstrumentLayer * layer1 =
readLayer(node->getNode("layer[0]"), w_scale, h_scale);
FGInstrumentLayer * layer2 =
readLayer(node->getNode("layer[1]"), w_scale, h_scale);
layer = new FGSwitchLayer(w, h, target, layer1, layer2);
layer = new FGSwitchLayer();
for (int i = 0; i < node->nChildren(); i++) {
const SGPropertyNode * child = node->getChild(i);
if (!strcmp(child->getName(), "layer"))
((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
}
}
// A built-in instrument layer.