]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD.cxx
Goodbye automake.
[flightgear.git] / src / Instrumentation / HUD / HUD.cxx
index 4ea539db366891e00ec1876833c698d3e176d608..2f130ae9615166c4c05e2db00a3d3fc7b5920b85 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <simgear/constants.h>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/props/props_io.hxx>
 #include <osg/GLU>
 
 #include <Main/globals.hxx>
@@ -39,6 +40,8 @@
 
 #include "HUD.hxx"
 
+using std::endl;
+using std::ifstream;
 
 static float clamp(float f)
 {
@@ -115,14 +118,8 @@ HUD::~HUD()
     _scr_heightN->removeChangeListener(this);
     _unitsN->removeChangeListener(this);
     delete _font_renderer;
-    delete _clip_box;
-
-    deque<Item *>::const_iterator it, end = _items.end();
-    for (it = _items.begin(); it != end; ++it)
-        delete *it;
-    end = _ladders.end();
-    for (it = _ladders.begin(); it != end; ++it)
-        delete *it;
+    
+    deinit();
 }
 
 
@@ -143,9 +140,32 @@ void HUD::init()
     _font_renderer->setPointSize(_font_size);
     _text_list.setFont(_font_renderer);
 
+    currentColorChanged();
+    
     _path->fireValueChanged();
 }
 
+void HUD::deinit()
+{
+  deque<Item *>::const_iterator it, end = _items.end();
+    for (it = _items.begin(); it != end; ++it)
+        delete *it;
+    end = _ladders.end();
+    for (it = _ladders.begin(); it != end; ++it)
+        delete *it;
+        
+  _items.clear();
+  _ladders.clear();
+  
+  delete _clip_box;
+  _clip_box = NULL;
+}
+
+void HUD::reinit()
+{
+    deinit();
+    _path->fireValueChanged();
+}
 
 void HUD::update(double dt)
 {
@@ -328,8 +348,12 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
     const sgDebugPriority TREE = SG_INFO;
     const int MAXNEST = 10;
 
-    SGPath path(globals->get_fg_root());
-    path.append(file);
+    SGPath path(globals->resolve_maybe_aircraft_path(file));
+    if (path.isNull())
+    {
+        SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot find configuration file '" << file << "'.");
+        return 0x2;
+    }
 
     if (!level) {
         SG_LOG(SG_INPUT, TREE, endl << "load " << file);
@@ -346,7 +370,7 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
     int ret = 0;
     ifstream input(path.c_str());
     if (!input.good()) {
-        SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from " << path.str());
+        SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from '" << path.c_str() << "'");
         return 0x4;
     }
 
@@ -432,29 +456,9 @@ void HUD::valueChanged(SGPropertyNode *node)
         load(fgGetString("/sim/hud/path[1]", "Huds/default.xml"));
 
     if (!strcmp(node->getName(), "current-color")) {
-        int i = node->getIntValue();
-        if (i < 0)
-            i = 0;
-        SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
-        if ((n = n->getChild("color", i, false))) {
-            if (n->hasValue("red"))
-                _red->setFloatValue(n->getFloatValue("red", 1.0));
-            if (n->hasValue("green"))
-                _green->setFloatValue(n->getFloatValue("green", 1.0));
-            if (n->hasValue("blue"))
-                _blue->setFloatValue(n->getFloatValue("blue", 1.0));
-            if (n->hasValue("alpha"))
-                _alpha->setFloatValue(n->getFloatValue("alpha", 0.67));
-            if (n->hasValue("alpha-clamp"))
-                _alpha_clamp->setFloatValue(n->getFloatValue("alpha-clamp", 0.01));
-            if (n->hasValue("brightness"))
-                _brightness->setFloatValue(n->getFloatValue("brightness", 0.75));
-            if (n->hasValue("antialiased"))
-                _antialiasing->setBoolValue(n->getBoolValue("antialiased", false));
-            if (n->hasValue("transparent"))
-                _transparency->setBoolValue(n->getBoolValue("transparent", false));
-        }
+        currentColorChanged();
     }
+    
     _scr_width = _scr_widthN->getIntValue();
     _scr_height = _scr_heightN->getIntValue();
 
@@ -473,6 +477,36 @@ void HUD::valueChanged(SGPropertyNode *node)
     _listener_active = false;
 }
 
+void HUD::currentColorChanged()
+{
+  SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
+  int index = _current->getIntValue();
+  if (index < 0) {
+    index = 0;
+  }
+  
+  n = n->getChild("color", index, false);
+  if (!n) {
+    return;
+  }
+  
+  if (n->hasValue("red"))
+      _red->setFloatValue(n->getFloatValue("red", 1.0));
+  if (n->hasValue("green"))
+      _green->setFloatValue(n->getFloatValue("green", 1.0));
+  if (n->hasValue("blue"))
+      _blue->setFloatValue(n->getFloatValue("blue", 1.0));
+  if (n->hasValue("alpha"))
+      _alpha->setFloatValue(n->getFloatValue("alpha", 0.67));
+  if (n->hasValue("alpha-clamp"))
+      _alpha_clamp->setFloatValue(n->getFloatValue("alpha-clamp", 0.01));
+  if (n->hasValue("brightness"))
+      _brightness->setFloatValue(n->getFloatValue("brightness", 0.75));
+  if (n->hasValue("antialiased"))
+      _antialiasing->setBoolValue(n->getBoolValue("antialiased", false));
+  if (n->hasValue("transparent"))
+      _transparency->setBoolValue(n->getBoolValue("transparent", false));
+}
 
 void HUD::setColor() const
 {