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.
22 #include <simgear/math/SGLimits.hxx>
23 #include <simgear/props/condition.hxx>
27 HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
29 _name(n->getStringValue("name", "[unnamed]")),
32 _digits(n->getIntValue("digits"))
34 const SGPropertyNode *node = n->getNode("condition");
36 _condition = sgReadCondition(globals->get_props(), node);
38 _scrn_pos.left = n->getIntValue("x") + x;
39 _scrn_pos.top = n->getIntValue("y") + y;
40 _scrn_pos.right = n->getIntValue("width");
41 _scrn_pos.bottom = n->getIntValue("height");
43 vector<SGPropertyNode_ptr> opt = n->getChildren("option");
44 for (unsigned int i = 0; i < opt.size(); i++) {
45 const char *o = opt[i]->getStringValue();
46 if (!strcmp(o, "autoticks"))
47 _options |= AUTOTICKS;
48 else if (!strcmp(o, "vertical"))
50 else if (!strcmp(o, "horizontal"))
52 else if (!strcmp(o, "top"))
54 else if (!strcmp(o, "left"))
56 else if (!strcmp(o, "bottom"))
58 else if (!strcmp(o, "right"))
60 else if (!strcmp(o, "both"))
61 _options |= (LEFT|RIGHT);
62 else if (!strcmp(o, "noticks"))
64 else if (!strcmp(o, "arithtic"))
66 else if (!strcmp(o, "decitics"))
68 else if (!strcmp(o, "notext"))
71 SG_LOG(SG_INPUT, SG_WARN, "HUD: unsupported option: " << o);
74 // Set up convenience values for centroid of the box and
75 // the span values according to orientation
77 if (_options & VERT) {
78 _scr_span = _scrn_pos.bottom;
80 _scr_span = _scrn_pos.right;
83 _mid_span.x = _scrn_pos.left + _scrn_pos.right / 2.0;
84 _mid_span.y = _scrn_pos.top + _scrn_pos.bottom / 2.0;
88 bool HUD::Item::isEnabled()
93 return _condition->test();