From: david Date: Sun, 9 Mar 2003 03:34:29 +0000 (+0000) Subject: Major change: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=191bb2188835c7fd046b8eb0090a6f529973f1b8;p=flightgear.git 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. --- diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index b492c0bf4..688975130 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -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,17 +1135,9 @@ 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 () +FGSwitchLayer::FGSwitchLayer () + : FGGroupLayer() { - delete _layer1; - delete _layer2; } void @@ -1152,10 +1145,12 @@ 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; + } } } } diff --git a/src/Cockpit/panel.hxx b/src/Cockpit/panel.hxx index af1c073ae..80f80c6d0 100644 --- a/src/Cockpit/panel.hxx +++ b/src/Cockpit/panel.hxx @@ -442,7 +442,7 @@ public: virtual void draw (); // transfer pointer ownership virtual void addLayer (FGInstrumentLayer * layer); -private: +protected: vector _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; }; diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index ef83c6b1a..f6b114645 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -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.