]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_instrument.cxx
new HUD (work in progress)
[flightgear.git] / src / Instrumentation / HUD / HUD_instrument.cxx
1 // HUD_instrument.cxx -- HUD Common Instrument Base
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
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.
12 //
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.
17 //
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.
21
22 #include <simgear/math/SGLimits.hxx>
23 #include <simgear/props/condition.hxx>
24 #include "HUD.hxx"
25
26
27 HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
28     _hud(hud),
29     _name(n->getStringValue("name", "[unnamed]")),
30     _options(0),
31     _condition(0),
32     _digits(n->getIntValue("digits"))
33 {
34     const SGPropertyNode *node = n->getNode("condition");
35     if (node)
36         _condition = sgReadCondition(globals->get_props(), node);
37
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");
42
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"))
49             _options |= VERT;
50         else if (!strcmp(o, "horizontal"))
51             _options |= HORZ;
52         else if (!strcmp(o, "top"))
53             _options |= TOP;
54         else if (!strcmp(o, "left"))
55             _options |= LEFT;
56         else if (!strcmp(o, "bottom"))
57             _options |= BOTTOM;
58         else if (!strcmp(o, "right"))
59             _options |= RIGHT;
60         else if (!strcmp(o, "both"))
61             _options |= (LEFT|RIGHT);
62         else if (!strcmp(o, "noticks"))
63             _options |= NOTICKS;
64         else if (!strcmp(o, "arithtic"))
65             _options |= ARITHTIC;
66         else if (!strcmp(o, "decitics"))
67             _options |= DECITICS;
68         else if (!strcmp(o, "notext"))
69             _options |= NOTEXT;
70         else
71             SG_LOG(SG_INPUT, SG_WARN, "HUD: unsupported option: " << o);
72     }
73
74     // Set up convenience values for centroid of the box and
75     // the span values according to orientation
76
77     if (_options & VERT) {
78         _scr_span = _scrn_pos.bottom;
79     } else {
80         _scr_span = _scrn_pos.right;
81     }
82
83     _mid_span.x = _scrn_pos.left + _scrn_pos.right / 2.0;
84     _mid_span.y = _scrn_pos.top + _scrn_pos.bottom / 2.0;
85 }
86
87
88 bool HUD::Item::isEnabled()
89 {
90     if (!_condition)
91         return true;
92
93     return _condition->test();
94 }
95
96