]> git.mxchange.org Git - flightgear.git/commitdiff
Major change:
authordavid <david>
Sun, 9 Mar 2003 03:34:29 +0000 (03:34 +0000)
committerdavid <david>
Sun, 9 Mar 2003 03:34:29 +0000 (03:34 +0000)
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.

src/Cockpit/panel.cxx
src/Cockpit/panel.hxx
src/Cockpit/panel_io.cxx

index b492c0bf402eb7e2b1aa29c8d24cd4d6783280a5..6889751302d63506dfafc14098a33ffe86dbd857 100644 (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,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;
+      }
     }
   }
 }
index af1c073ae3d2ad3d5a7fcc2bdf7ad5ca0598a09e..80f80c6d0d246af3147ffcbd063e31e60c5739e6 100644 (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;
 };
 
 
index ef83c6b1ab2f8cc583b280b6970f5a0cd722526c..f6b114645575d2ba478f306c779a889e7c009fcd 100644 (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.