Debian Codegraph @

src/Instrumentation/HUD/HUD.hxx

raw symbols SCIP
1 // HUD.hxx -- Head Up Display
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 #ifndef _HUD_HXX
23 #define _HUD_HXX
24
25 #include <simgear/compiler.h>
26
27 #include <vector>
28 #include <deque>
29
30 #include <osg/State>
31
32 #include <simgear/math/SGLimits.hxx>
33 #include <simgear/constants.h>
34 #include <simgear/structure/subsystem_mgr.hxx>
35 #include <simgear/props/props.hxx>
36
37 class FGFontCache;
38 class fntRenderer;
39 class fntTexFont;
40 class FGViewer;
41 class ClipBox;
42
43 class LineSegment
44 {
45 public:
46 LineSegment(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
47 : _x0(x0), _y0(y0), _x1(x1), _y1(y1) {}
48
49 void draw() const {
50 glVertex2f(_x0, _y0);
51 glVertex2f(_x1, _y1);
52 }
53
54 private:
55 GLfloat _x0, _y0, _x1, _y1;
56 };
57
58
59
60 class LineList
61 {
62 public:
63 void add(const LineSegment& seg) { _list.push_back(seg); }
64 void erase() { _list.erase(_list.begin(), _list.end()); }
65 inline unsigned int size() const { return _list.size(); }
66 inline bool empty() const { return _list.empty(); }
67 void draw() {
68 glBegin(GL_LINES);
69 std::vector<LineSegment>::const_iterator it, end = _list.end();
70 for (it = _list.begin(); it != end; ++it)
71 it->draw();
72 glEnd();
73 }
74
75 private:
76 std::vector<LineSegment> _list;
77 };
78
79
80
81 class HUDText
82 {
83 public:
84 HUDText(fntRenderer *f, float x, float y, const char *s, int align = 0, int digits = 0);
85 void draw();
86
87 private:
88 fntRenderer *_fnt;
89 float _x, _y;
90 int _digits;
91 static const int BUFSIZE = 64;
92 char _msg[BUFSIZE];
93 };
94
95
96
97 class TextList
98 {
99 public:
100 TextList() { _font = 0; }
101
102 void setFont(fntRenderer *Renderer) { _font = Renderer; }
103 void add(float x, float y, const char *s, int align = 0, int digit = 0) {
104 _list.push_back(HUDText(_font, x, y, s, align, digit));
105 }
106 void erase() { _list.erase(_list.begin(), _list.end()); }
107 void align(const char *s, int align, float *x, float *y,
108 float *l, float *r, float *b, float *t) const;
109 void draw();
110
111 private:
112 fntRenderer *_font;
113 std::vector<HUDText> _list;
114 };
115
116
117
118 class HUD : public SGSubsystem,
119 public SGPropertyChangeListener
120 {
121 public:
122 HUD();
123 ~HUD();
124
125 // Subsystem API.
126 void init() override;
127 void reinit() override;
128 void update(double) override;
129
130 // Subsystem identification.
131 static const char* staticSubsystemClassId() { return "hud"; }
132
133 // called from Main/renderer.cxx to draw 2D and 3D HUD
134 void draw(osg::State&);
135
136 // listener callback to read various HUD related properties
137 void valueChanged(SGPropertyNode *);
138 // set current glColor
139 void setColor() const;
140 inline bool isVisible() const { return _visible; }
141 inline bool isAntialiased() const { return _antialiased; }
142 inline bool isTransparent() const { return _transparent; }
143 inline bool is3D() const { return _3Denabled; }
144 inline float alphaClamp() const { return _cl; }
145 inline double timer() const { return _timer; }
146 static void textAlign(fntRenderer *rend, const char *s, int align, float *x, float *y,
147 float *l, float *r, float *b, float *t);
148
149 enum Units { FEET, METER };
150 Units getUnits() const { return _units; }
151
152 enum {
153 HORIZONTAL = 0x0000, // keep that at zero?
154 VERTICAL = 0x0001,
155 TOP = 0x0002,
156 BOTTOM = 0x0004,
157 LEFT = 0x0008,
158 RIGHT = 0x0010,
159 NOTICKS = 0x0020,
160 NOTEXT = 0x0040,
161 BOTH = (LEFT|RIGHT),
162
163 // for alignment (with LEFT, RIGHT, TOP, BOTTOM)
164 HCENTER = 0x0080,
165 VCENTER = 0x0100,
166 CENTER = (HCENTER|VCENTER),
167 };
168
169 protected:
170 void common_draw();
171 int load(const char *, float x = 320.0f, float y = 240.0f,
172 int level = 0, const std::string& indent = "");
173
174 private:
175 void deinit();
176
177 void draw3D();
178 void draw2D(GLfloat, GLfloat, GLfloat, GLfloat);
179
180 void currentColorChanged();
181
182 class Input;
183 class Item;
184 class Label;
185 class Scale;
186 class Gauge;
187 class Tape;
188 class Dial;
189 class TurnBankIndicator;
190 class Ladder;
191 class Runway;
192 class AimingReticle;
193
194 std::deque<Item *> _items;
195 std::deque<Item *> _ladders;
196
197 SGPropertyNode_ptr _currentPath;
198 SGPropertyNode_ptr _currentColor;
199 SGPropertyNode_ptr _visibility;
200 SGPropertyNode_ptr _3DenabledN;
201 SGPropertyNode_ptr _antialiasing;
202 SGPropertyNode_ptr _transparency;
203 SGPropertyNode_ptr _red, _green, _blue, _alpha;
204 SGPropertyNode_ptr _alpha_clamp;
205 SGPropertyNode_ptr _brightness;
206 bool _visible;
207 bool _loaded;
208 bool _3Denabled;
209 bool _antialiased;
210 bool _transparent;
211 float _r, _g, _b, _a, _cl;
212
213 SGPropertyNode_ptr _scr_widthN, _scr_heightN;
214 int _scr_width, _scr_height;
215 SGPropertyNode_ptr _unitsN;
216 Units _units;
217 double _timer;
218
219 fntRenderer *_font_renderer;
220 FGFontCache *_font_cache;
221 fntTexFont *_font;
222 float _font_size;
223 int _style;
224 bool _listener_active;
225
226 ClipBox *_clip_box;
227 TextList _text_list;
228 LineList _line_list;
229 LineList _stipple_line_list;
230 };
231
232 #endif // _HUD_HXX