#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 <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)),
{
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;
- delete _clip_box;
+ SGPropertyNode* hud = fgGetNode("/sim/hud");
+ hud->removeChangeListener(this);
- 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();
}
_font_renderer->setPointSize(_font_size);
_text_list.setFont(_font_renderer);
- _path->fireValueChanged();
+ currentColorChanged();
+ _currentPath->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();
+ _currentPath->fireValueChanged();
+}
void HUD::update(double dt)
{
void HUD::draw3D()
{
+ using namespace osg;
FGViewer* view = globals->get_current_view();
// Standard fgfs projection, with essentially meaningless clip
// planes (we'll map the whole HUD plane to z=-1)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
- glLoadIdentity();
- gluPerspective(view->get_v_fov(), 1.0 / view->get_aspect_ratio(), 0.1, 10);
+ Matrixf proj
+ = Matrixf::perspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
+ 0.1, 10);
+ glLoadMatrix(proj.ptr());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
- glLoadIdentity();
// Standard fgfs view direction computation
- float lookat[3];
+ Vec3f lookat;
lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
if (fabs(lookat[1]) > 9999)
lookat[1] = 9999; // FPU sanity
- gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
+ Matrixf mv = Matrixf::lookAt(Vec3f(0.0, 0.0, 0.0), lookat,
+ Vec3f(0.0, 1.0, 0.0));
+ glLoadMatrix(mv.ptr());
// Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
// This is the default fgfs field of view, which the HUD files are
void HUD::draw2D(GLfloat x_start, GLfloat y_start, GLfloat x_end, GLfloat y_end)
{
+ using namespace osg;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
- glLoadIdentity();
- gluOrtho2D(x_start, x_end, y_start, y_end);
+ Matrixf proj = Matrixf::ortho2D(x_start, x_end, y_start, y_end);
+ glLoadMatrix(proj.ptr());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
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);
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"));
-
- 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));
+ if (!strcmp(node->getName(), "current-path")) {
+ 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);
}
+
+ load(path.c_str());
}
+
+ if (!strcmp(node->getName(), "current-color")) {
+ currentColorChanged();
+ }
+
_scr_width = _scr_widthN->getIntValue();
_scr_height = _scr_heightN->getIntValue();
_listener_active = false;
}
+void HUD::currentColorChanged()
+{
+ SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
+ int index = _currentColor->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
{