1 // HUD.hxx -- Head Up Display
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.
25 #include <simgear/compiler.h>
32 #include <simgear/math/SGLimits.hxx>
33 #include <simgear/constants.h>
34 #include <simgear/structure/subsystem_mgr.hxx>
35 #include <simgear/props/props.hxx>
45 LineSegment(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
46 : _x0(x0), _y0(y0), _x1(x1), _y1(y1) {}
54 GLfloat _x0, _y0, _x1, _y1;
61 void add(const LineSegment& seg) { _list.push_back(seg); }
62 void erase() { _list.erase(_list.begin(), _list.end()); }
63 inline unsigned int size() const { return _list.size(); }
64 inline bool empty() const { return _list.empty(); }
67 std::vector<LineSegment>::const_iterator it, end = _list.end();
68 for (it = _list.begin(); it != end; ++it)
74 std::vector<LineSegment> _list;
81 HUDText(fntRenderer *f, float x, float y, const char *s, int align = 0, int digits = 0);
88 static const int BUFSIZE = 64;
96 TextList() { _font = 0; }
98 void setFont(fntRenderer *Renderer) { _font = Renderer; }
99 void add(float x, float y, const char *s, int align = 0, int digit = 0) {
100 _list.push_back(HUDText(_font, x, y, s, align, digit));
102 void erase() { _list.erase(_list.begin(), _list.end()); }
103 void align(const char *s, int align, float *x, float *y,
104 float *l, float *r, float *b, float *t) const;
109 std::vector<HUDText> _list;
114 class HUD : public SGSubsystem, public SGPropertyChangeListener {
123 // called from Main/renderer.cxx to draw 2D and 3D HUD
124 void draw(osg::State&);
126 // listener callback to read various HUD related properties
127 void valueChanged(SGPropertyNode *);
128 // set current glColor
129 void setColor() const;
130 inline bool isVisible() const { return _visible; }
131 inline bool isAntialiased() const { return _antialiased; }
132 inline bool isTransparent() const { return _transparent; }
133 inline bool is3D() const { return _3Denabled; }
134 inline float alphaClamp() const { return _cl; }
135 inline double timer() const { return _timer; }
136 static void textAlign(fntRenderer *rend, const char *s, int align, float *x, float *y,
137 float *l, float *r, float *b, float *t);
139 enum Units { FEET, METER };
140 Units getUnits() const { return _units; }
143 HORIZONTAL = 0x0000, // keep that at zero?
153 // for alignment (with LEFT, RIGHT, TOP, BOTTOM)
156 CENTER = (HCENTER|VCENTER),
161 int load(const char *, float x = 320.0f, float y = 240.0f,
162 int level = 0, const std::string& indent = "");
168 void draw2D(GLfloat, GLfloat, GLfloat, GLfloat);
170 void currentColorChanged();
179 class TurnBankIndicator;
184 std::deque<Item *> _items;
185 std::deque<Item *> _ladders;
187 SGPropertyNode_ptr _currentPath;
188 SGPropertyNode_ptr _currentColor;
189 SGPropertyNode_ptr _visibility;
190 SGPropertyNode_ptr _3DenabledN;
191 SGPropertyNode_ptr _antialiasing;
192 SGPropertyNode_ptr _transparency;
193 SGPropertyNode_ptr _red, _green, _blue, _alpha;
194 SGPropertyNode_ptr _alpha_clamp;
195 SGPropertyNode_ptr _brightness;
201 float _r, _g, _b, _a, _cl;
203 SGPropertyNode_ptr _scr_widthN, _scr_heightN;
204 int _scr_width, _scr_height;
205 SGPropertyNode_ptr _unitsN;
209 fntRenderer *_font_renderer;
210 FGFontCache *_font_cache;
214 bool _listener_active;
219 LineList _stipple_line_list;