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