]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD.cxx
Merge commit 'refs/merge-requests/1551' of git://gitorious.org/fg/flightgear into...
[flightgear.git] / src / Instrumentation / HUD / HUD.cxx
index 4a42d47effad774b917b76c0ad9bb14d47b2c351..d37f28a3d4813a83d142f6814f9cc3b57a514554 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <Main/globals.hxx>
 #include <Main/viewmgr.hxx>
+#include <Main/viewer.hxx>
 
 #include "HUD.hxx"
 
@@ -46,6 +47,7 @@ static float clamp(float f)
 
 
 HUD::HUD() :
+    _path(fgGetNode("/sim/hud/path[1]", "Huds/default.xml")),
     _current(fgGetNode("/sim/hud/current-color", true)),
     _visibility(fgGetNode("/sim/hud/visibility[1]", true)),
     _3DenabledN(fgGetNode("/sim/hud/enable3d[1]", true)),
@@ -72,10 +74,12 @@ HUD::HUD() :
     _font(0),
     _font_size(0.0),
     _style(0),
+    _listener_active(false),
     _clip_box(0)
 {
     SG_LOG(SG_COCKPIT, SG_INFO, "Initializing HUD Instrument");
 
+    _path->addChangeListener(this);
     _visibility->addChangeListener(this);
     _3DenabledN->addChangeListener(this);
     _antialiasing->addChangeListener(this);
@@ -95,6 +99,7 @@ HUD::HUD() :
 
 HUD::~HUD()
 {
+    _path->removeChangeListener(this);
     _visibility->removeChangeListener(this);
     _3DenabledN->removeChangeListener(this);
     _antialiasing->removeChangeListener(this);
@@ -123,18 +128,22 @@ HUD::~HUD()
 
 void HUD::init()
 {
+    const char* fontName = 0;
     _font_cache = globals->get_fontcache();
+    if (!_font) {
+        fontName = fgGetString("/sim/hud/font/name", "Helvetica.txf");
+        _font = _font_cache->getTexFont(fontName);
+    }
     if (!_font)
-        _font = _font_cache->getTexFont(fgGetString("/sim/hud/font/name", "Helvetica.txf"));
-    if (!_font)
-        throw sg_throwable(string("/sim/hud/font/name is not a texture font"));
+        throw sg_io_exception("/sim/hud/font/name is not a texture font",
+                              sg_location(fontName));
 
     _font_size = fgGetFloat("/sim/hud/font/size", 8);
     _font_renderer->setFont(_font);
     _font_renderer->setPointSize(_font_size);
     _text_list.setFont(_font_renderer);
 
-    load(fgGetString("/sim/hud/path[1]", "Huds/default.xml"));
+    _path->fireValueChanged();
 }
 
 
@@ -411,6 +420,12 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
 
 void HUD::valueChanged(SGPropertyNode *node)
 {
+    if (_listener_active)
+        return;
+    _listener_active = true;
+    if (!strcmp(node->getName(), "path"))
+        load(fgGetString("/sim/hud/path[1]", "Huds/default.xml"));
+
     if (!strcmp(node->getName(), "current-color")) {
         int i = node->getIntValue();
         if (i < 0)
@@ -450,6 +465,7 @@ void HUD::valueChanged(SGPropertyNode *node)
     _cl = clamp(_alpha_clamp->getFloatValue());
 
     _units = strcmp(_unitsN->getStringValue(), "feet") ? METER : FEET;
+    _listener_active = false;
 }
 
 
@@ -462,10 +478,8 @@ void HUD::setColor() const
 }
 
 
-
-
 void HUD::textAlign(fntRenderer *rend, const char *s, int align,
-        float *x, float *y, float *l, float *r, float *t, float *b)
+        float *x, float *y, float *l, float *r, float *b, float *t)
 {
     fntFont *font = rend->getFont();
     float gap = font->getGap();