// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <simgear/math/SGLimits.hxx>
#include <simgear/props/condition.hxx>
#include "HUD.hxx"
if (node)
_condition = sgReadCondition(globals->get_props(), node);
- _scrn_pos.left = n->getIntValue("x") + x;
- _scrn_pos.top = n->getIntValue("y") + y;
- _scrn_pos.right = n->getIntValue("width");
- _scrn_pos.bottom = n->getIntValue("height");
+ _x = n->getIntValue("x") + x;
+ _y = n->getIntValue("y") + y;
+ _w = n->getIntValue("width");
+ _h = n->getIntValue("height");
vector<SGPropertyNode_ptr> opt = n->getChildren("option");
for (unsigned int i = 0; i < opt.size(); i++) {
// the span values according to orientation
if (_options & VERT) {
- _scr_span = _scrn_pos.bottom;
+ _scr_span = _h;
} else {
- _scr_span = _scrn_pos.right;
+ _scr_span = _w;
}
- _mid_span.x = _scrn_pos.left + _scrn_pos.right / 2.0;
- _mid_span.y = _scrn_pos.top + _scrn_pos.bottom / 2.0;
+ _mid_span.x = _x + _w / 2.0;
+ _mid_span.y = _y + _h / 2.0;
}
bool HUD::Item::isEnabled()
{
- if (!_condition)
- return true;
+ return _condition ? _condition->test() : true;
+}
+
+
+void HUD::Item::draw_line(float x1, float y1, float x2, float y2)
+{
+ _hud->_line_list.add(LineSegment(x1, y1, x2, y2));
+}
+
+
+void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
+{
+ _hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2));
+}
+
+
+void HUD::Item::draw_text(float x, float y, char *msg, int digit)
+{
+ _hud->_text_list.add(HUDText(x, y, msg, digit));
+}
- return _condition->test();
+
+void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
+{
+ glBegin(GL_LINE_LOOP);
+ for (int i = 0; i < 25; i++) {
+ float alpha = i * 2.0 * SG_PI / 10.0;
+ float x = r * cos(alpha);
+ float y = r * sin(alpha);
+ glVertex2f(x + xoffs, y + yoffs);
+ }
+ 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);
+}
+
+
+float HUD::Item::text_width(char *str) const
+{
+ assert(_hud->_font_renderer);
+ float r, l;
+ _hud->_font->getBBox(str, _hud->_font_size, 0, &l, &r, 0, 0);
+ return r - l;
}