1 // HUD_instrument.cxx -- HUD Common Instrument Base
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
6 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <simgear/math/SGLimits.hxx>
27 #include <simgear/props/condition.hxx>
31 HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
33 _name(n->getStringValue("name", "[unnamed]")),
36 _digits(n->getIntValue("digits"))
38 const SGPropertyNode *node = n->getNode("condition");
40 _condition = sgReadCondition(globals->get_props(), node);
42 _x = n->getIntValue("x") + x;
43 _y = n->getIntValue("y") + y;
44 _w = n->getIntValue("width");
45 _h = n->getIntValue("height");
47 vector<SGPropertyNode_ptr> opt = n->getChildren("option");
48 for (unsigned int i = 0; i < opt.size(); i++) {
49 const char *o = opt[i]->getStringValue();
50 if (!strcmp(o, "vertical"))
52 else if (!strcmp(o, "horizontal"))
53 _options |= HORIZONTAL;
54 else if (!strcmp(o, "top"))
56 else if (!strcmp(o, "left"))
58 else if (!strcmp(o, "bottom"))
60 else if (!strcmp(o, "right"))
62 else if (!strcmp(o, "both"))
63 _options |= (LEFT|RIGHT);
64 else if (!strcmp(o, "noticks"))
66 else if (!strcmp(o, "notext"))
69 SG_LOG(SG_INPUT, SG_WARN, "HUD: unsupported option: " << o);
72 // Set up convenience values for centroid of the box and
73 // the span values according to orientation
75 if (_options & VERTICAL) {
81 _center_x = _x + _w / 2.0;
82 _center_y = _y + _h / 2.0;
86 bool HUD::Item::isEnabled()
88 return _condition ? _condition->test() : true;
92 void HUD::Item::draw_line(float x1, float y1, float x2, float y2)
94 _hud->_line_list.add(LineSegment(x1, y1, x2, y2));
98 void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
100 _hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2));
104 void HUD::Item::draw_text(float x, float y, char *msg, int align, int digit)
106 _hud->_text_list.add(x, y, msg, align, digit);
110 void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
112 glBegin(GL_LINE_LOOP);
113 float step = SG_PI / r;
114 for (float alpha = 0; alpha < SG_PI * 2.0; alpha += step) {
115 float x = r * cos(alpha);
116 float y = r * sin(alpha);
117 glVertex2f(x + xoffs, y + yoffs);
123 void HUD::Item::draw_bullet(float x, float y, float size)
125 glEnable(GL_POINT_SMOOTH);
133 glDisable(GL_POINT_SMOOTH);
137 // make sure the format matches '[ -+#]?\d*(\.\d*)?(l?[df]|s)'
139 HUD::Item::Format HUD::Item::check_format(const char *f) const
154 if (*f == ' ' || *f == '+' || *f == '-' || *f == '#')
156 while (*f && isdigit(*f))
160 while (*f && isdigit(*f))
167 fmt = l ? LONG : INT;
169 fmt = l ? DOUBLE : FLOAT;
170 else if (*f == 's') {