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, "autoticks"))
51 _options |= AUTOTICKS;
52 else if (!strcmp(o, "vertical"))
54 else if (!strcmp(o, "horizontal"))
56 else if (!strcmp(o, "top"))
58 else if (!strcmp(o, "left"))
60 else if (!strcmp(o, "bottom"))
62 else if (!strcmp(o, "right"))
64 else if (!strcmp(o, "both"))
65 _options |= (LEFT|RIGHT);
66 else if (!strcmp(o, "noticks"))
68 else if (!strcmp(o, "arithtic"))
70 else if (!strcmp(o, "decitics"))
72 else if (!strcmp(o, "notext"))
75 SG_LOG(SG_INPUT, SG_WARN, "HUD: unsupported option: " << o);
78 // Set up convenience values for centroid of the box and
79 // the span values according to orientation
81 if (_options & VERT) {
87 _center_x = _x + _w / 2.0;
88 _center_y = _y + _h / 2.0;
92 bool HUD::Item::isEnabled()
94 return _condition ? _condition->test() : true;
98 void HUD::Item::draw_line(float x1, float y1, float x2, float y2)
100 _hud->_line_list.add(LineSegment(x1, y1, x2, y2));
104 void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
106 _hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2));
110 void HUD::Item::draw_text(float x, float y, char *msg, int digit)
112 _hud->_text_list.add(HUDText(x, y, msg, digit));
116 void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
118 glBegin(GL_LINE_LOOP);
119 float step = SG_PI / r;
120 for (float alpha = 0; alpha < SG_PI * 2.0; alpha += step) {
121 float x = r * cos(alpha);
122 float y = r * sin(alpha);
123 glVertex2f(x + xoffs, y + yoffs);
129 void HUD::Item::draw_bullet(float x, float y, float size)
131 glEnable(GL_POINT_SMOOTH);
139 glDisable(GL_POINT_SMOOTH);
143 float HUD::Item::text_width(char *str) const
145 assert(_hud->_font_renderer);
147 _hud->_font->getBBox(str, _hud->_font_size, 0, &l, &r, 0, 0);