]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD.cxx
Merge branch 'curt/replay'
[flightgear.git] / src / Instrumentation / HUD / HUD.cxx
index cab15dee6604ce093ac172bd7118a592bfcf7f9f..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();
 }
 
 
@@ -293,6 +302,8 @@ void HUD::common_draw()
         if ((*it)->isEnabled())
             (*it)->draw();
 
+    _clip_box->unset();
+
     if (isAntialiased()) {
         glDisable(GL_ALPHA_TEST);
         glDisable(GL_LINE_SMOOTH);
@@ -409,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)
@@ -448,6 +465,7 @@ void HUD::valueChanged(SGPropertyNode *node)
     _cl = clamp(_alpha_clamp->getFloatValue());
 
     _units = strcmp(_unitsN->getStringValue(), "feet") ? METER : FEET;
+    _listener_active = false;
 }
 
 
@@ -460,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();
@@ -636,3 +652,13 @@ void ClipBox::set()
     glEnable(GL_CLIP_PLANE3);
 }
 
+
+void ClipBox::unset()
+{
+    if (_active) {
+        glDisable(GL_CLIP_PLANE0);
+        glDisable(GL_CLIP_PLANE1);
+        glDisable(GL_CLIP_PLANE2);
+        glDisable(GL_CLIP_PLANE3);
+    }
+}