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(); }
66 std::vector<LineSegment>::const_iterator it, end = _list.end();
67 for (it = _list.begin(); it != end; ++it)
73 std::vector<LineSegment> _list;
80 HUDText(fntRenderer *f, float x, float y, const char *s, int align = 0, int digits = 0);
87 static const int BUFSIZE = 64;
95 TextList() { _font = 0; }
97 void setFont(fntRenderer *Renderer) { _font = Renderer; }
98 void add(float x, float y, const char *s, int align = 0, int digit = 0) {
99 _list.push_back(HUDText(_font, x, y, s, align, digit));
101 void erase() { _list.erase(_list.begin(), _list.end()); }
102 void align(const char *s, int align, float *x, float *y,
103 float *l, float *r, float *b, float *t) const;
108 std::vector<HUDText> _list;
113 class HUD : public SGSubsystem, public SGPropertyChangeListener {
122 // called from Main/renderer.cxx to draw 2D and 3D HUD
123 void draw(osg::State&);
125 // listener callback to read various HUD related properties
126 void valueChanged(SGPropertyNode *);
127 // set current glColor
128 void setColor() const;
129 inline bool isVisible() const { return _visible; }
130 inline bool isAntialiased() const { return _antialiased; }
131 inline bool isTransparent() const { return _transparent; }
132 inline bool is3D() const { return _3Denabled; }
133 inline float alphaClamp() const { return _cl; }
134 inline double timer() const { return _timer; }
135 static void textAlign(fntRenderer *rend, const char *s, int align, float *x, float *y,
136 float *l, float *r, float *b, float *t);
138 enum Units { FEET, METER };
139 Units getUnits() const { return _units; }
142 HORIZONTAL = 0x0000, // keep that at zero?
152 // for alignment (with LEFT, RIGHT, TOP, BOTTOM)
155 CENTER = (HCENTER|VCENTER),
160 int load(const char *, float x = 320.0f, float y = 240.0f,
161 int level = 0, const std::string& indent = "");
167 void draw2D(GLfloat, GLfloat, GLfloat, GLfloat);
169 void currentColorChanged();
178 class TurnBankIndicator;
183 std::deque<Item *> _items;
184 std::deque<Item *> _ladders;
186 SGPropertyNode_ptr _currentPath;
187 SGPropertyNode_ptr _currentColor;
188 SGPropertyNode_ptr _visibility;
189 SGPropertyNode_ptr _3DenabledN;
190 SGPropertyNode_ptr _antialiasing;
191 SGPropertyNode_ptr _transparency;
192 SGPropertyNode_ptr _red, _green, _blue, _alpha;
193 SGPropertyNode_ptr _alpha_clamp;
194 SGPropertyNode_ptr _brightness;
200 float _r, _g, _b, _a, _cl;
202 SGPropertyNode_ptr _scr_widthN, _scr_heightN;
203 int _scr_width, _scr_height;
204 SGPropertyNode_ptr _unitsN;
208 fntRenderer *_font_renderer;
209 FGFontCache *_font_cache;
213 bool _listener_active;
218 LineList _stipple_line_list;