]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD.hxx
Cleanup part2. Forgotton file.
[flightgear.git] / src / Instrumentation / HUD / HUD.hxx
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 public:
45     LineSegment(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1)
46         : _x0(x0), _y0(y0), _x1(x1), _y1(y1) {}
47
48     void draw() const {
49         glVertex2f(_x0, _y0);
50         glVertex2f(_x1, _y1);
51     }
52
53 private:
54     GLfloat _x0, _y0, _x1, _y1;
55 };
56
57
58
59 class LineList {
60 public:
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(); }
65     void draw() {
66         glBegin(GL_LINES);
67         std::vector<LineSegment>::const_iterator it, end = _list.end();
68         for (it = _list.begin(); it != end; ++it)
69             it->draw();
70         glEnd();
71     }
72
73 private:
74   std::vector<LineSegment> _list;
75 };
76
77
78
79 class HUDText {
80 public:
81     HUDText(fntRenderer *f, float x, float y, const char *s, int align = 0, int digits = 0);
82     void draw();
83
84 private:
85     fntRenderer *_fnt;
86     float _x, _y;
87     int _digits;
88     static const int BUFSIZE = 64;
89     char _msg[BUFSIZE];
90 };
91
92
93
94 class TextList {
95 public:
96     TextList() { _font = 0; }
97
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));
101     }
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;
105     void draw();
106
107 private:
108     fntRenderer *_font;
109     std::vector<HUDText> _list;
110 };
111
112
113
114 class HUD : public SGSubsystem, public SGPropertyChangeListener {
115 public:
116     HUD();
117     ~HUD();
118     void init();
119     void update(double);
120
121   void reinit();
122
123     // called from Main/renderer.cxx to draw 2D and 3D HUD
124     void draw(osg::State&);
125
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);
138
139     enum Units { FEET, METER };
140     Units getUnits() const { return _units; }
141
142     enum {
143         HORIZONTAL = 0x0000,  // keep that at zero?
144         VERTICAL   = 0x0001,
145         TOP        = 0x0002,
146         BOTTOM     = 0x0004,
147         LEFT       = 0x0008,
148         RIGHT      = 0x0010,
149         NOTICKS    = 0x0020,
150         NOTEXT     = 0x0040,
151         BOTH       = (LEFT|RIGHT),
152
153         // for alignment (with LEFT, RIGHT, TOP, BOTTOM)
154         HCENTER    = 0x0080,
155         VCENTER    = 0x0100,
156         CENTER     = (HCENTER|VCENTER),
157     };
158
159 protected:
160     void common_draw();
161     int load(const char *, float x = 320.0f, float y = 240.0f,
162             int level = 0, const std::string& indent = "");
163
164 private:
165     void deinit();
166     
167     void draw3D();
168     void draw2D(GLfloat, GLfloat, GLfloat, GLfloat);
169
170     void currentColorChanged();
171     
172     class Input;
173     class Item;
174     class Label;
175     class Scale;
176     class Gauge;
177     class Tape;
178     class Dial;
179     class TurnBankIndicator;
180     class Ladder;
181     class Runway;
182     class AimingReticle;
183
184     std::deque<Item *> _items;
185     std::deque<Item *> _ladders;
186
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;
196     bool _visible;
197     bool _loaded;
198     bool _3Denabled;
199     bool _antialiased;
200     bool _transparent;
201     float _r, _g, _b, _a, _cl;
202
203     SGPropertyNode_ptr _scr_widthN, _scr_heightN;
204     int _scr_width, _scr_height;
205     SGPropertyNode_ptr _unitsN;
206     Units _units;
207     double _timer;
208
209     fntRenderer *_font_renderer;
210     FGFontCache *_font_cache;
211     fntTexFont *_font;
212     float _font_size;
213     int _style;
214     bool _listener_active;
215
216     ClipBox *_clip_box;
217     TextList _text_list;
218     LineList _line_list;
219     LineList _stipple_line_list;
220 };
221
222 #endif // _HUD_HXX