]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_private.hxx
Make HUD items private to the subsystem.
[flightgear.git] / src / Instrumentation / HUD / HUD_private.hxx
1 // HUD_private.hxx -- Intenral delcerations for the HUD
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_PRIVATE_HXX
23 #define _HUD_PRIVATE_HXX
24
25 #include <simgear/compiler.h>
26 #include <simgear/props/condition.hxx>
27
28 #include <vector>
29 #include <deque>
30 #include <cassert>
31
32 #include <osg/State>
33
34 #include <simgear/math/SGLimits.hxx>
35 #include <simgear/constants.h>
36 #include <simgear/props/props.hxx>
37
38 #include <plib/sg.h> // for lingering sgdVec3 usage below
39
40 class FGFontCache;
41 class fntRenderer;
42 class fntTexFont;
43 class FGViewer;
44 class FGRunway;
45
46 class ClipBox {
47 public:
48   ClipBox(const SGPropertyNode *, float xoffset = 0, float yoffset = 0);
49   void set();
50   void unset();
51   
52 private:
53   bool _active;
54   float _xoffs, _yoffs;
55   SGConstPropertyNode_ptr _top_node;
56   SGConstPropertyNode_ptr _bot_node;
57   SGConstPropertyNode_ptr _left_node;
58   SGConstPropertyNode_ptr _right_node;
59   GLdouble _top[4];
60   GLdouble _bot[4];
61   GLdouble _left[4];
62   GLdouble _right[4];
63 };
64
65
66 class HUD::Input {
67 public:
68     Input(const SGPropertyNode *n, float factor = 1.0, float offset = 0.0,
69           float min = -SGLimitsf::max(), float max = SGLimitsf::max());
70   
71     bool getBoolValue() const {
72         assert(_property);
73         return _property->getBoolValue();
74     }
75
76     const char *getStringValue() const {
77         assert(_property);
78         return _property->getStringValue();
79     }
80
81     float getFloatValue() {
82         assert(_property);
83         float f = _property->getFloatValue() * _factor + _offset;
84         if (_damped == SGLimitsf::max())
85             _damped = f;
86         if (_coeff > 0.0f)
87             f = _damped = f * (1.0f - _coeff) + _damped * _coeff;
88         return clamp(f);
89     }
90
91     inline float isValid() const { return _valid; }
92     inline float min() const { return _min; }
93     inline float max() const { return _max; }
94     inline float factor() const { return _factor; }
95     float clamp(float v) const { return v < _min ? _min : v > _max ? _max : v; }
96
97     void set_min(float m, bool force = true) {
98         if (force || _min == -SGLimitsf::max())
99             _min = m;
100     }
101     void set_max(float m, bool force = true) {
102         if (force || _max == SGLimitsf::max())
103             _max = m;
104     }
105
106 private:
107     bool _valid;
108     SGConstPropertyNode_ptr _property;
109     float _factor;
110     float _offset;
111     float _min;
112     float _max;
113     float _coeff;
114     float _damped;
115 };
116
117
118
119 class HUD::Item {
120 public:
121     Item(HUD *parent, const SGPropertyNode *, float x = 0.0f, float y = 0.0f);
122     virtual ~Item () {}
123     virtual void draw() = 0;
124     virtual bool isEnabled();
125
126 protected:
127     enum Format {
128         INVALID,
129         NONE,
130         INT,
131         LONG,
132         FLOAT,
133         DOUBLE,
134         STRING,
135     };
136
137     Format  check_format(const char *) const;
138     inline float get_span()       const { return _scr_span; }
139     inline int   get_digits()     const { return _digits; }
140
141     inline bool option_vert()    const { return (_options & VERTICAL) == VERTICAL; }
142     inline bool option_left()    const { return (_options & LEFT) == LEFT; }
143     inline bool option_right()   const { return (_options & RIGHT) == RIGHT; }
144     inline bool option_both()    const { return (_options & BOTH) == BOTH; }
145     inline bool option_noticks() const { return (_options & NOTICKS) == NOTICKS; }
146     inline bool option_notext()  const { return (_options & NOTEXT) == NOTEXT; }
147     inline bool option_top()     const { return (_options & TOP) == TOP; }
148     inline bool option_bottom()  const { return (_options & BOTTOM) == BOTTOM; }
149
150     void draw_line(float x1, float y1, float x2, float y2);
151     void draw_stipple_line(float x1, float y1, float x2, float y2);
152     void draw_text(float x, float y, const char *msg, int align = 0, int digit = 0);
153     void draw_circle(float x1, float y1, float r) const;
154     void draw_arc(float x1, float y1, float t0, float t1, float r) const;
155     void draw_bullet(float, float, float);
156
157     HUD         *_hud;
158     std::string      _name;
159     int         _options;
160     float       _x, _y, _w, _h;
161     float       _center_x, _center_y;
162
163 private:
164     SGSharedPtr<SGCondition> _condition;
165     float       _disp_factor;   // Multiply by to get numbers shown on scale.
166     float       _scr_span;      // Working values for draw;
167     int         _digits;
168 };
169
170
171
172 class HUD::Label : public Item {
173 public:
174     Label(HUD *parent, const SGPropertyNode *, float x, float y);
175     virtual void draw();
176
177 private:
178     bool    blink();
179
180     Input   _input;
181     Format  _mode;
182     std::string  _format;
183     int     _halign;    // HUDText alignment
184     int     _blink;
185     bool    _box;
186     float   _text_y;
187     float   _pointer_width;
188     float   _pointer_length;
189
190     SGSharedPtr<SGCondition> _blink_condition;
191     double  _blink_interval;
192     double  _blink_target;  // time for next blink state change
193     bool    _blink_state;
194 };
195
196
197
198 // abstract base class for both moving scale and moving needle (fixed scale)
199 // indicators.
200 //
201 class HUD::Scale : public Item {
202 public:
203     Scale(HUD *parent, const SGPropertyNode *, float x, float y);
204     virtual void draw    ( void ) {}  // No-op here. Defined in derived classes.
205
206 protected:
207     inline float factor() const { return _display_factor; }
208     inline float range_to_show() const { return _range_shown; }
209
210     Input _input;
211     float _major_divs;      // major division marker units
212     float _minor_divs;      // minor division marker units
213     unsigned int _modulo;   // Roll over point
214
215 private:
216     float _range_shown;     // Width Units.
217     float _display_factor;  // factor => screen units/range values.
218 };
219
220
221 class HUD::Gauge : public Scale {
222 public:
223     Gauge(HUD *parent, const SGPropertyNode *, float x, float y);
224     virtual void draw();
225 };
226
227
228
229 // displays the indicated quantity on a scale that moves past the
230 // pointer. It may be horizontal or vertical.
231 //
232 class HUD::Tape : public Scale {
233 public:
234     Tape(HUD *parent, const SGPropertyNode *, float x, float y);
235     virtual void draw();
236
237 protected:
238     void draw_vertical(float);
239     void draw_horizontal(float);
240     void draw_fixed_pointer(float, float, float, float, float, float);
241     char *format_value(float);
242
243 private:
244     float  _val_span;
245     float  _half_width_units;
246     bool   _draw_tick_bottom;
247     bool   _draw_tick_top;
248     bool   _draw_tick_right;
249     bool   _draw_tick_left;
250     bool   _draw_cap_bottom;
251     bool   _draw_cap_top;
252     bool   _draw_cap_right;
253     bool   _draw_cap_left;
254     float  _marker_offset;
255     float  _label_offset;
256     float  _label_gap;
257     bool   _pointer;
258     Format _label_fmt;
259     std::string _format;
260     int    _div_ratio;          // _major_divs/_minor_divs
261     bool   _odd_type;           // whether to put numbers at 0/2/4 or 1/3/5
262
263     enum { BUFSIZE = 64 };
264     char   _buf[BUFSIZE];
265
266     enum PointerType { FIXED, MOVING } _pointer_type;
267     enum TickType { LINE, CIRCLE } _tick_type;
268     enum TickLength { VARIABLE, CONSTANT } _tick_length;
269 };
270
271
272
273 class HUD::Dial : public Scale {
274 public:
275     Dial(HUD *parent, const SGPropertyNode *, float x, float y);
276     virtual void draw();
277
278 private:
279     float  _radius;
280     int    _divisions;
281 };
282
283
284
285 class HUD::TurnBankIndicator : public Item {
286 public:
287     TurnBankIndicator(HUD *parent, const SGPropertyNode *, float x, float y);
288     virtual void draw();
289
290 private:
291     void draw_scale();
292     void draw_tee();
293     void draw_line(float, float, float, float);
294     void draw_tick(float angle, float r1, float r2, int side);
295
296     Input _bank;
297     Input _sideslip;
298
299     float _gap_width;
300     bool  _bank_scale;
301 };
302
303
304
305 class HUD::Ladder : public Item {
306 public:
307     Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
308     ~Ladder();
309     virtual void draw();
310
311 private:
312     void draw_zenith(float, float);
313     void draw_nadir(float, float);
314
315     void draw_text(float x, float y, const char *s, int align = 0) {
316         _locTextList.add(x, y, s, align, 0);
317     }
318
319     void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
320         if (stipple)
321             _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
322         else
323             _locLineList.add(LineSegment(x1, y1, x2, y2));
324     }
325
326     enum   Type { PITCH, CLIMB_DIVE } _type;
327     Input  _pitch;
328     Input  _roll;
329     float  _width_units;
330     int    _div_units;
331     float  _scr_hole;
332     float  _zero_bar_overlength;
333     bool   _dive_bar_angle;
334     float  _tick_length;
335     float  _vmax;
336     float  _vmin;
337     float  _compression;
338     bool   _dynamic_origin;
339     bool   _frl;               // fuselage reference line
340     bool   _target_spot;
341     bool   _target_markers;
342     bool   _velocity_vector;
343     bool   _drift_marker;
344     bool   _alpha_bracket;
345     bool   _energy_marker;
346     bool   _climb_dive_marker;
347     bool   _glide_slope_marker;
348     float  _glide_slope;
349     bool   _energy_worm;
350     bool   _waypoint_marker;
351     bool   _zenith;
352     bool   _nadir;
353     bool   _hat;
354
355     ClipBox *_clip_box;
356     // The Ladder has its own temporary display lists
357     TextList _locTextList;
358     LineList _locLineList;
359     LineList _locStippleLineList;
360 };
361
362
363
364 // responsible for rendering the active runway in the hud (if visible).
365 //
366 class HUD::Runway : public Item {
367 public:
368     Runway(HUD *parent, const SGPropertyNode *, float x, float y);
369     virtual void draw();
370
371 private:
372     void boundPoint(const sgdVec3& v, sgdVec3& m);
373     bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
374     bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
375     void drawArrow();
376     FGRunway* get_active_runway();
377     void get_rwy_points(sgdVec3 *points);
378     void setLineWidth();
379
380     SGPropertyNode_ptr _agl;
381     sgdVec3 _points3d[6], _points2d[6];
382     double _mm[16];
383     double _pm[16];
384     double _arrow_scale;  // scales of runway indication arrow
385     double _arrow_radius;
386     double _line_scale;   // maximum line scale
387     double _scale_dist;   // distance where to start scaling the lines
388     double _default_pitch;
389     double _default_heading;
390     GLint  _view[4];
391     FGRunway* _runway;
392     unsigned short _stipple_out;    // stipple pattern of the outline of the runway
393     unsigned short _stipple_center; // stipple pattern of the center line of the runway
394     bool   _draw_arrow;             // draw arrow when runway is not visible in HUD
395     bool   _draw_arrow_always;      // always draws arrow
396     float  _left, _right, _top, _bottom;
397 };
398
399
400 class HUD::AimingReticle : public Item {
401 public:
402     AimingReticle(HUD *parent, const SGPropertyNode *, float x, float y);
403     virtual void draw();
404
405 private:
406     SGSharedPtr<SGCondition> _active_condition;  // stadiametric (true) or standby (false)
407     SGSharedPtr<SGCondition> _tachy_condition;  // tachymetric (true) or standby (false)
408     SGSharedPtr<SGCondition> _align_condition;  // tachymetric (true) or standby (false)
409
410     Input   _diameter;               // inner/outer radius relation
411     Input  _pitch;
412     Input  _yaw;
413     Input  _speed;
414     Input  _range;
415     Input  _t0;
416     Input  _t1;
417     Input  _offset_x;
418     Input  _offset_y;
419
420     float   _bullet_size;
421     float   _inner_radius;
422     float   _compression;
423     float  _limit_x;
424     float  _limit_y;
425
426 };
427
428
429 #endif // _HUD_HXX