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:
parent
d94bd7526c
commit
191bb21888
3 changed files with 22 additions and 38 deletions
src/Cockpit
|
@ -904,6 +904,7 @@ void
|
||||||
FGGroupLayer::draw ()
|
FGGroupLayer::draw ()
|
||||||
{
|
{
|
||||||
if (test()) {
|
if (test()) {
|
||||||
|
transform();
|
||||||
int nLayers = _layers.size();
|
int nLayers = _layers.size();
|
||||||
for (int i = 0; i < nLayers; i++)
|
for (int i = 0; i < nLayers; i++)
|
||||||
_layers[i]->draw();
|
_layers[i]->draw();
|
||||||
|
@ -1134,28 +1135,22 @@ FGTextLayer::Chunk::getValue () const
|
||||||
// Implementation of FGSwitchLayer.
|
// Implementation of FGSwitchLayer.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
|
FGSwitchLayer::FGSwitchLayer ()
|
||||||
FGInstrumentLayer * layer1,
|
: FGGroupLayer()
|
||||||
FGInstrumentLayer * layer2)
|
|
||||||
: FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FGSwitchLayer::~FGSwitchLayer ()
|
|
||||||
{
|
|
||||||
delete _layer1;
|
|
||||||
delete _layer2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FGSwitchLayer::draw ()
|
FGSwitchLayer::draw ()
|
||||||
{
|
{
|
||||||
if (test()) {
|
if (test()) {
|
||||||
transform();
|
transform();
|
||||||
if (_node->getBoolValue()) {
|
int nLayers = _layers.size();
|
||||||
_layer1->draw();
|
for (int i = 0; i < nLayers; i++) {
|
||||||
} else {
|
if (_layers[i]->test()) {
|
||||||
_layer2->draw();
|
_layers[i]->draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,7 +442,7 @@ public:
|
||||||
virtual void draw ();
|
virtual void draw ();
|
||||||
// transfer pointer ownership
|
// transfer pointer ownership
|
||||||
virtual void addLayer (FGInstrumentLayer * layer);
|
virtual void addLayer (FGInstrumentLayer * layer);
|
||||||
private:
|
protected:
|
||||||
vector<FGInstrumentLayer *> _layers;
|
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
|
* The first layer that passes its condition will be drawn, and
|
||||||
* can have conditions, and it may be deprecated soon.
|
* any following layers will be ignored.
|
||||||
*/
|
*/
|
||||||
class FGSwitchLayer : public FGInstrumentLayer
|
class FGSwitchLayer : public FGGroupLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Transfer pointers!!
|
// Transfer pointers!!
|
||||||
FGSwitchLayer (int w, int h, const SGPropertyNode * node,
|
FGSwitchLayer ();
|
||||||
FGInstrumentLayer * layer1,
|
|
||||||
FGInstrumentLayer * layer2);
|
|
||||||
virtual ~FGSwitchLayer ();
|
|
||||||
|
|
||||||
virtual void draw ();
|
virtual void draw ();
|
||||||
|
|
||||||
private:
|
|
||||||
const SGPropertyNode * _node;
|
|
||||||
FGInstrumentLayer * _layer1, * _layer2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -436,11 +436,8 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
|
||||||
layer = new FGGroupLayer();
|
layer = new FGGroupLayer();
|
||||||
for (int i = 0; i < node->nChildren(); i++) {
|
for (int i = 0; i < node->nChildren(); i++) {
|
||||||
const SGPropertyNode * child = node->getChild(i);
|
const SGPropertyNode * child = node->getChild(i);
|
||||||
cerr << "Trying child " << child->getName() << endl;
|
if (!strcmp(child->getName(), "layer"))
|
||||||
if (!strcmp(child->getName(), "layer")) {
|
|
||||||
cerr << "succeeded!" << endl;
|
|
||||||
((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
|
((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.
|
// A switch instrument layer.
|
||||||
else if (type == "switch") {
|
else if (type == "switch") {
|
||||||
SGPropertyNode * target =
|
layer = new FGSwitchLayer();
|
||||||
fgGetNode(node->getStringValue("property"), true);
|
for (int i = 0; i < node->nChildren(); i++) {
|
||||||
FGInstrumentLayer * layer1 =
|
const SGPropertyNode * child = node->getChild(i);
|
||||||
readLayer(node->getNode("layer[0]"), w_scale, h_scale);
|
if (!strcmp(child->getName(), "layer"))
|
||||||
FGInstrumentLayer * layer2 =
|
((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
|
||||||
readLayer(node->getNode("layer[1]"), w_scale, h_scale);
|
}
|
||||||
layer = new FGSwitchLayer(w, h, target, layer1, layer2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A built-in instrument layer.
|
// A built-in instrument layer.
|
||||||
|
|
Loading…
Add table
Reference in a new issue