2006-07-04 15:32:55 +00:00
|
|
|
// HUD_instrument.cxx -- HUD Common Instrument Base
|
|
|
|
//
|
|
|
|
// Written by Michele America, started September 1997.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
|
|
|
|
// Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2006-07-05 06:22:05 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2006-07-04 15:32:55 +00:00
|
|
|
#include <simgear/math/SGLimits.hxx>
|
|
|
|
#include "HUD.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
|
|
|
|
_hud(hud),
|
|
|
|
_name(n->getStringValue("name", "[unnamed]")),
|
|
|
|
_options(0),
|
|
|
|
_condition(0),
|
|
|
|
_digits(n->getIntValue("digits"))
|
|
|
|
{
|
|
|
|
const SGPropertyNode *node = n->getNode("condition");
|
|
|
|
if (node)
|
|
|
|
_condition = sgReadCondition(globals->get_props(), node);
|
|
|
|
|
2008-07-28 17:04:24 +00:00
|
|
|
_x = n->getFloatValue("x") + x;
|
|
|
|
_y = n->getFloatValue("y") + y;
|
|
|
|
_w = n->getFloatValue("width");
|
|
|
|
_h = n->getFloatValue("height");
|
2006-07-04 15:32:55 +00:00
|
|
|
|
|
|
|
vector<SGPropertyNode_ptr> opt = n->getChildren("option");
|
|
|
|
for (unsigned int i = 0; i < opt.size(); i++) {
|
|
|
|
const char *o = opt[i]->getStringValue();
|
2006-07-29 19:45:17 +00:00
|
|
|
if (!strcmp(o, "vertical"))
|
|
|
|
_options |= VERTICAL;
|
2006-07-04 15:32:55 +00:00
|
|
|
else if (!strcmp(o, "horizontal"))
|
2006-07-29 19:45:17 +00:00
|
|
|
_options |= HORIZONTAL;
|
2006-07-04 15:32:55 +00:00
|
|
|
else if (!strcmp(o, "top"))
|
|
|
|
_options |= TOP;
|
|
|
|
else if (!strcmp(o, "left"))
|
|
|
|
_options |= LEFT;
|
|
|
|
else if (!strcmp(o, "bottom"))
|
|
|
|
_options |= BOTTOM;
|
|
|
|
else if (!strcmp(o, "right"))
|
|
|
|
_options |= RIGHT;
|
|
|
|
else if (!strcmp(o, "both"))
|
|
|
|
_options |= (LEFT|RIGHT);
|
|
|
|
else if (!strcmp(o, "noticks"))
|
|
|
|
_options |= NOTICKS;
|
|
|
|
else if (!strcmp(o, "notext"))
|
|
|
|
_options |= NOTEXT;
|
|
|
|
else
|
|
|
|
SG_LOG(SG_INPUT, SG_WARN, "HUD: unsupported option: " << o);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up convenience values for centroid of the box and
|
|
|
|
// the span values according to orientation
|
|
|
|
|
2006-07-29 19:45:17 +00:00
|
|
|
if (_options & VERTICAL) {
|
2006-07-06 14:30:18 +00:00
|
|
|
_scr_span = _h;
|
2006-07-04 15:32:55 +00:00
|
|
|
} else {
|
2006-07-06 14:30:18 +00:00
|
|
|
_scr_span = _w;
|
2006-07-04 15:32:55 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 10:09:36 +00:00
|
|
|
_center_x = _x + _w / 2.0;
|
|
|
|
_center_y = _y + _h / 2.0;
|
2006-07-04 15:32:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HUD::Item::isEnabled()
|
|
|
|
{
|
2006-07-04 21:04:22 +00:00
|
|
|
return _condition ? _condition->test() : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-05 22:55:33 +00:00
|
|
|
void HUD::Item::draw_line(float x1, float y1, float x2, float y2)
|
2006-07-04 21:04:22 +00:00
|
|
|
{
|
|
|
|
_hud->_line_list.add(LineSegment(x1, y1, x2, y2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-05 22:55:33 +00:00
|
|
|
void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
|
2006-07-04 21:04:22 +00:00
|
|
|
{
|
|
|
|
_hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-28 17:04:24 +00:00
|
|
|
void HUD::Item::draw_text(float x, float y, const char *msg, int align, int digit)
|
2006-07-04 21:04:22 +00:00
|
|
|
{
|
2006-07-31 13:10:26 +00:00
|
|
|
_hud->_text_list.add(x, y, msg, align, digit);
|
2006-07-04 21:04:22 +00:00
|
|
|
}
|
2006-07-04 15:32:55 +00:00
|
|
|
|
2006-07-04 21:04:22 +00:00
|
|
|
|
2006-07-05 22:55:33 +00:00
|
|
|
void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
|
2006-07-04 21:04:22 +00:00
|
|
|
{
|
|
|
|
glBegin(GL_LINE_LOOP);
|
2006-07-22 08:00:56 +00:00
|
|
|
float step = SG_PI / r;
|
|
|
|
for (float alpha = 0; alpha < SG_PI * 2.0; alpha += step) {
|
2006-07-05 22:55:33 +00:00
|
|
|
float x = r * cos(alpha);
|
|
|
|
float y = r * sin(alpha);
|
|
|
|
glVertex2f(x + xoffs, y + yoffs);
|
2006-07-04 21:04:22 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HUD::Item::draw_bullet(float x, float y, float size)
|
|
|
|
{
|
|
|
|
glEnable(GL_POINT_SMOOTH);
|
|
|
|
glPointSize(size);
|
|
|
|
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glVertex2f(x, y);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glPointSize(1.0);
|
|
|
|
glDisable(GL_POINT_SMOOTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 21:11:38 +00:00
|
|
|
// make sure the format matches '[ -+#]?\d*(\.\d*)?(l?[df]|s)'
|
|
|
|
//
|
|
|
|
HUD::Item::Format HUD::Item::check_format(const char *f) const
|
|
|
|
{
|
|
|
|
bool l = false;
|
|
|
|
Format fmt = STRING;
|
|
|
|
|
|
|
|
for (; *f; f++) {
|
|
|
|
if (*f == '%') {
|
|
|
|
if (f[1] == '%')
|
|
|
|
f++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*f++ != '%')
|
|
|
|
return NONE;
|
|
|
|
if (*f == ' ' || *f == '+' || *f == '-' || *f == '#')
|
|
|
|
f++;
|
|
|
|
while (*f && isdigit(*f))
|
|
|
|
f++;
|
|
|
|
if (*f == '.') {
|
|
|
|
f++;
|
|
|
|
while (*f && isdigit(*f))
|
|
|
|
f++;
|
|
|
|
}
|
|
|
|
if (*f == 'l')
|
|
|
|
l = true, f++;
|
|
|
|
|
|
|
|
if (*f == 'd')
|
|
|
|
fmt = l ? LONG : INT;
|
|
|
|
else if (*f == 'f')
|
|
|
|
fmt = l ? DOUBLE : FLOAT;
|
|
|
|
else if (*f == 's') {
|
|
|
|
if (l)
|
|
|
|
return INVALID;
|
|
|
|
fmt = STRING;
|
|
|
|
} else
|
|
|
|
return INVALID;
|
|
|
|
|
|
|
|
for (++f; *f; f++) {
|
|
|
|
if (*f == '%') {
|
|
|
|
if (f[1] == '%')
|
|
|
|
f++;
|
|
|
|
else
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|