#include <simgear/constants.h>
#include <simgear/misc/sg_path.hxx>
+#include <simgear/props/props_io.hxx>
#include <osg/GLU>
+#include <plib/fnt.h>
+
#include <Main/globals.hxx>
-#include <Main/viewmgr.hxx>
-#include <Main/viewer.hxx>
+#include <Viewer/viewmgr.hxx>
+#include <Viewer/viewer.hxx>
+#include <GUI/FGFontCache.hxx>
#include "HUD.hxx"
+using std::endl;
+using std::ifstream;
static float clamp(float f)
{
HUD::HUD() :
- _path(fgGetNode("/sim/hud/path[1]", "Huds/default.xml")),
- _current(fgGetNode("/sim/hud/current-color", true)),
+ _currentPath(fgGetNode("/sim/hud/current-path", true)),
+ _currentColor(fgGetNode("/sim/hud/current-color", true)),
_visibility(fgGetNode("/sim/hud/visibility[1]", true)),
_3DenabledN(fgGetNode("/sim/hud/enable3d[1]", true)),
_antialiasing(fgGetNode("/sim/hud/color/antialiased", true)),
_alpha_clamp(fgGetNode("/sim/hud/color/alpha-clamp", true)),
_brightness(fgGetNode("/sim/hud/color/brightness", true)),
_visible(false),
+ _loaded(false),
_antialiased(false),
_transparent(false),
_a(0.67), // FIXME better names
{
SG_LOG(SG_COCKPIT, SG_INFO, "Initializing HUD Instrument");
- _path->addChangeListener(this);
- _visibility->addChangeListener(this);
- _3DenabledN->addChangeListener(this);
- _antialiasing->addChangeListener(this);
- _transparency->addChangeListener(this);
- _red->addChangeListener(this);
- _green->addChangeListener(this);
- _blue->addChangeListener(this);
- _alpha->addChangeListener(this);
- _alpha_clamp->addChangeListener(this);
- _brightness->addChangeListener(this);
- _current->addChangeListener(this);
- _scr_widthN->addChangeListener(this);
- _scr_heightN->addChangeListener(this);
- _unitsN->addChangeListener(this, true);
+ SGPropertyNode* hud = fgGetNode("/sim/hud");
+ hud->addChangeListener(this);
}
HUD::~HUD()
{
- _path->removeChangeListener(this);
- _visibility->removeChangeListener(this);
- _3DenabledN->removeChangeListener(this);
- _antialiasing->removeChangeListener(this);
- _transparency->removeChangeListener(this);
- _red->removeChangeListener(this);
- _green->removeChangeListener(this);
- _blue->removeChangeListener(this);
- _alpha->removeChangeListener(this);
- _alpha_clamp->removeChangeListener(this);
- _brightness->removeChangeListener(this);
- _current->removeChangeListener(this);
- _scr_widthN->removeChangeListener(this);
- _scr_heightN->removeChangeListener(this);
- _unitsN->removeChangeListener(this);
- delete _font_renderer;
-
+ SGPropertyNode* hud = fgGetNode("/sim/hud");
+ hud->removeChangeListener(this);
+
deinit();
}
_font_renderer->setFont(_font);
_font_renderer->setPointSize(_font_size);
_text_list.setFont(_font_renderer);
-
+ _loaded = false;
+
currentColorChanged();
-
- _path->fireValueChanged();
+ _currentPath->fireValueChanged();
}
void HUD::deinit()
delete _clip_box;
_clip_box = NULL;
+
+ _loaded = false;
}
void HUD::reinit()
{
deinit();
- _path->fireValueChanged();
+ _currentPath->fireValueChanged();
}
void HUD::update(double dt)
const int MAXNEST = 10;
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);
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;
}
if (_listener_active)
return;
_listener_active = true;
- if (!strcmp(node->getName(), "path"))
- load(fgGetString("/sim/hud/path[1]", "Huds/default.xml"));
-
+
+ bool loadNow = false;
+ _visible = _visibility->getBoolValue();
+ if (_visible && !_loaded) {
+ loadNow = true;
+ }
+
+ if (!strcmp(node->getName(), "current-path") && _visible) {
+ loadNow = true;
+ }
+
+ if (loadNow) {
+ int pathIndex = _currentPath->getIntValue();
+ SGPropertyNode* pathNode = fgGetNode("/sim/hud/path", pathIndex);
+ std::string path("Huds/default.xml");
+ if (pathNode && pathNode->hasValue()) {
+ path = pathNode->getStringValue();
+ SG_LOG(SG_INSTR, SG_INFO, "will load Hud from " << path);
+ }
+
+ _loaded = true;
+ load(path.c_str());
+ }
+
if (!strcmp(node->getName(), "current-color")) {
currentColorChanged();
}
_scr_width = _scr_widthN->getIntValue();
_scr_height = _scr_heightN->getIntValue();
- _visible = _visibility->getBoolValue();
+
_3Denabled = _3DenabledN->getBoolValue();
_transparent = _transparency->getBoolValue();
_antialiased = _antialiasing->getBoolValue();
void HUD::currentColorChanged()
{
SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
- int index = _current->getIntValue();
+ int index = _currentColor->getIntValue();
if (index < 0) {
index = 0;
}