]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud.hxx
No .h when including stl stuff.
[flightgear.git] / Cockpit / hud.hxx
1 /**************************************************************************
2  * hud.hxx -- hud defines and prototypes (initial draft)
3  *
4  * Written by Michele America, started September 1997.
5  *
6  * Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifndef _HUD_HXX
28 #define _HUD_HXX
29
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35
36 #include <config.h>
37
38
39 #include <fg_typedefs.h>
40 #include <fg_constants.h>
41 #include <Aircraft/aircraft.h>
42 #include <Flight/flight.h>
43 #include <Controls/controls.h>
44
45 //using namespace std;
46
47 #include <deque>         // STL
48
49
50 #ifndef WIN32
51
52   typedef struct {
53       int x, y;
54   } POINT;
55
56   typedef struct {
57       int top, bottom, left, right;
58   } RECT;
59
60 #endif
61
62
63 // View mode definitions
64
65 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
66
67 // DAY, NIGHT and brightness levels need to be visible where dialogs and
68 // controls can be used to set intensity and appropriate color. This will
69 // be moved.
70 // Hud general constants
71 #define DAY                1
72 #define NIGHT              2
73 #define BRT_DARK           3
74 #define BRT_MEDIUM         4
75 #define BRT_LIGHT          5
76 #define SIZE_SMALL         6
77 #define SIZE_LARGE         7
78
79 // Label constants
80 #define SMALL              1
81 #define LARGE              2
82
83 #define BLINK              3
84 #define NOBLINK            4
85
86 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
87
88 // Ladder constants
89 #define NONE               1
90 #define UPPER_LEFT         2
91 #define UPPER_CENTER       3
92 #define UPPER_RIGHT        4
93 #define CENTER_RIGHT       5
94 #define LOWER_RIGHT        6
95 #define LOWER_CENTER       7
96 #define LOWER_LEFT         8
97 #define CENTER_LEFT        9
98 #define SOLID_LINES       10
99 #define DASHED_LINES      11
100 #define DASHED_NEG_LINES  12
101
102
103 #define HORIZON_FIXED   1
104 #define HORIZON_MOVING  2
105 #define LABEL_COUNTER   1
106 #define LABEL_WARNING   2
107
108 // Ladder orientaion
109 // #define HUD_VERTICAL        1
110 // #define HUD_HORIZONTAL               2
111 // #define HUD_FREEFLOAT                3
112
113 // Ladder orientation modes
114 // #define HUD_LEFT             1
115 // #define HUD_RIGHT            2
116 // #define HUD_TOP              1
117 // #define HUD_BOTTOM           2
118 // #define HUD_V_LEFT                   1
119 // #define HUD_V_RIGHT          2
120 // #define HUD_H_TOP            1
121 // #define HUD_H_BOTTOM         2
122
123
124 // Ladder sub-types
125 // #define HUD_LIM                              1
126 // #define HUD_NOLIM                    2
127 // #define HUD_CIRC                     3
128
129 // #define HUD_INSTR_LADDER     1
130 // #define HUD_INSTR_CLADDER    2
131 // #define HUD_INSTR_HORIZON    3
132 // #define HUD_INSTR_LABEL              4
133
134 extern double get_throttleval ( void );
135 extern double get_aileronval  ( void );
136 extern double get_elevatorval ( void );
137 extern double get_elev_trimval( void );
138 extern double get_rudderval   ( void );
139 extern double get_speed       ( void );
140 extern double get_aoa         ( void );
141 extern double get_roll        ( void );
142 extern double get_pitch       ( void );
143 extern double get_heading     ( void );
144 extern double get_altitude    ( void );
145 extern double get_sideslip    ( void );
146 extern double get_frame_rate  ( void );
147 extern double get_latitude    ( void );
148 extern double get_lat_min     ( void );
149 extern double get_longitude   ( void );
150 extern double get_long_min    ( void );
151 extern double get_fov         ( void );
152 extern double get_vfc_ratio   ( void );
153
154 enum  hudinstype{ HUDno_instr,
155               HUDscale,
156               HUDlabel,
157               HUDladder,
158               HUDcirc_ladder,
159               HUDhorizon,
160               HUDguage,
161               HUDdual_inst,
162               HUDmoving_scale,
163               HUDtbi
164               };
165
166 enum ReadOriented{ ReadRIGHT, ReadLEFT, ReadTOP, ReadBOTTOM };
167
168 class instr_item {  // An Abstract Base Class (ABC)
169   private:
170     static UINT      instances;     // More than 64K instruments? Nah!
171     UINT             handle;
172     RECT             scrn_pos;      // Framing - affects scale dimensions
173                                     // and orientation. Vert vs Horz, etc.
174     DBLFNPTR         load_value_fn;
175     ReadOriented     oriented;
176     bool             is_enabled;
177     bool             broken;
178     int              brightness;
179     UINT             scr_span;      // Working values for draw;
180     POINT            mid_span;      //
181
182   public:
183     instr_item( RECT           scrn_pos,
184                 DBLFNPTR       data_source,
185                 ReadOriented   orient,
186                 bool           working      = true);
187
188     instr_item( const instr_item & image );
189
190     instr_item & operator = ( const instr_item & rhs );
191     virtual ~instr_item ();
192
193     int          get_brightness  ( void ) { return brightness;}
194     RECT         get_location    ( void ) { return scrn_pos;  }
195     bool         is_broken       ( void ) { return broken;    }
196     bool         enabled         ( void ) { return is_enabled;}
197     double       get_value       ( void ) { return load_value_fn();}
198     UINT         get_span        ( void ) { return scr_span;  }
199     POINT        get_centroid    ( void ) { return mid_span;  }
200     ReadOriented get_orientation ( void ) { return oriented;  }
201
202     virtual void display_enable( bool working ) { is_enabled = !! working;}
203
204
205     virtual void update( void );
206     virtual void break_display ( bool bad );
207     virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
208     UINT    get_Handle( void );
209     virtual void draw( void ) = 0;   // Required method in derived classes
210 };
211
212 typedef instr_item *HIptr;
213
214 extern deque< instr_item * > HUD_deque;
215
216 // instr_item           This class has no other purpose than to maintain
217 //                      a linked list of instrument and derived class
218 // object pointers.
219
220
221 class instr_label : public instr_item {
222   private:
223     const char *pformat;
224     const char *pre_str;
225     const char *post_str;
226     fgLabelJust justify;
227     int         fontSize;
228     int         blink;
229
230   public:
231     instr_label( RECT         the_box,
232                  DBLFNPTR     data_source,
233                  const char  *label_format,
234                  const char  *pre_label_string    = 0,
235                  const char  *post_label_string   = 0,
236                  ReadOriented orientation         = ReadTOP,
237                  fgLabelJust  justification       = CENTER_JUST,
238                  int          font_size           = SMALL,
239                  int          blinking            = NOBLINK,
240                  bool         working             = true);
241
242     ~instr_label();
243
244     instr_label( const instr_label & image);
245     instr_label & operator = (const instr_label & rhs );
246
247     virtual void draw( void );       // Required method in base class
248 };
249
250 typedef instr_label * pInstlabel;
251
252 //
253 // instr_scale           This class is an abstract base class for both moving
254 //                       scale and moving needle (fixed scale) indicators. It
255 // does not draw itself, but is not instanciable.
256 //
257
258 class instr_scale : public instr_item {
259   private:
260     int    range_shown;   // Width Units.
261     int    Maximum_value; //                ceiling.
262     int    Minimum_value; // Representation floor.
263     UINT   Maj_div;       // major division marker units
264     UINT   Min_div;       // minor division marker units
265     UINT   Modulo;        // Roll over point
266     double scale_factor;  // factor => screen units/range values.
267
268   public:
269     instr_scale( RECT         the_box,
270                  DBLFNPTR     load_fn,
271                  ReadOriented orient,
272                  int          show_range,
273                  int          max_value,
274                  int          min_value    =   0,
275                  UINT         major_divs   =  10,
276                  UINT         minor_divs   =   5,
277                  UINT         rollover     =   0,
278                  bool         working      = true);
279
280     virtual ~instr_scale();
281     instr_scale( const instr_scale & image);
282     instr_scale & operator = (const instr_scale & rhs);
283
284     virtual void draw   ( void ) {}; // No-op here. Defined in derived classes.
285     UINT   div_min      ( void ) { return Min_div;}
286     UINT   div_max      ( void ) { return Maj_div;}
287     int    min_val      ( void ) { return Minimum_value;}
288     int    max_val      ( void ) { return Maximum_value;}
289     UINT   modulo       ( void ) { return Modulo; }
290     double factor       ( void ) { return scale_factor;}
291     double range_to_show( void ) { return range_shown;}
292 };
293
294 // moving_scale_instr      This class displays the indicated quantity on
295 //                         a scale that moves past the pointer. It may be
296 // horizontal or vertical, read above(left) or below(right) of the base
297 // line.
298
299 class moving_scale : public instr_scale {
300   private:
301     double val_span;
302     double half_width_units;
303
304   public:
305     moving_scale( RECT         box,
306                   DBLFNPTR     load_fn,
307                   ReadOriented readway,
308                   int          maxValue,
309                   int          minValue,
310                   UINT         major_divs,
311                   UINT         minor_divs,
312                   UINT         modulator,
313                   double       value_span,
314                   bool         working = true);
315
316     ~moving_scale();
317     moving_scale( const moving_scale & image);
318     moving_scale & operator = (const moving_scale & rhs );
319 //    virtual void display_enable( bool setting );
320     virtual void draw( void );       // Required method in base class
321 };
322
323 typedef moving_scale * pMoveScale;
324
325 class guage_instr : public instr_scale {
326   private:
327
328   public:
329     guage_instr( RECT         box,
330                  DBLFNPTR     load_fn,
331                  ReadOriented readway,
332                  int          maxValue,
333                  int          minValue,
334                  UINT         major_divs,
335                  UINT         minor_divs,
336                  UINT         modulus,
337                  bool         working = true);
338
339     ~guage_instr();
340     guage_instr( const guage_instr & image);
341     guage_instr & operator = (const guage_instr & rhs );
342     virtual void draw( void );       // Required method in base class
343 };
344
345 typedef guage_instr * pGuageInst;
346 //
347 // dual_instr_item         This class was created to form the base class
348 //                         for both panel and HUD Turn Bank Indicators.
349
350 class dual_instr_item : public instr_item {
351   private:
352     DBLFNPTR alt_data_source;
353
354   public:
355     dual_instr_item ( RECT         the_box,
356                       DBLFNPTR     chn1_source,
357                       DBLFNPTR     chn2_source,
358                       bool         working     = true,
359                       ReadOriented readway  = ReadTOP);
360
361     virtual ~dual_instr_item() {};
362     dual_instr_item( const dual_instr_item & image);
363     dual_instr_item & operator = (const dual_instr_item & rhs );
364
365     double current_ch1( void ) { return alt_data_source();}
366     double current_ch2( void ) { return get_value();}
367     virtual void draw ( void ) { }
368 };
369
370 class fgTBI_instr : public dual_instr_item {
371   private:
372     UINT BankLimit;
373     UINT SlewLimit;
374     UINT scr_hole;
375
376   public:
377     fgTBI_instr( RECT      the_box,
378                  DBLFNPTR  chn1_source  = get_roll,
379                  DBLFNPTR  chn2_source  = get_sideslip,
380                  UINT      maxBankAngle = 45,
381                  UINT      maxSlipAngle =  5,
382                  UINT      gap_width    =  5,
383                  bool      working      =  true);
384
385     fgTBI_instr( const fgTBI_instr & image);
386     fgTBI_instr & operator = (const fgTBI_instr & rhs );
387
388     ~fgTBI_instr();
389
390     UINT bank_limit( void ) { return BankLimit;}
391     UINT slew_limit( void ) { return SlewLimit;}
392
393     virtual void draw( void );       // Required method in base class
394 };
395
396 typedef fgTBI_instr * pTBI;
397
398 class HudLadder : public dual_instr_item {
399   private:
400     UINT   width_units;
401     int    div_units;
402     UINT   minor_div;
403     UINT   label_pos;
404     UINT   scr_hole;
405     int    vmax;
406     int    vmin;
407     double factor;
408
409   public:
410     HudLadder( RECT      the_box,
411                DBLFNPTR  ptch_source    = get_roll,
412                DBLFNPTR  roll_source    = get_pitch,
413                UINT      span_units     = 45,
414                int       division_units = 10,
415                UINT      minor_division = 0,
416                UINT      screen_hole    = 70,
417                UINT      lbl_pos        = 0,
418                bool      working        = true );
419
420     ~HudLadder();
421
422     HudLadder( const HudLadder & image );
423     HudLadder & operator = ( const HudLadder & rhs );
424     virtual void draw( void );
425 };
426
427
428 //using namespace std;
429 //deque <instr_item>  * Hdeque_ptr;
430
431 extern int  fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
432 extern void fgUpdateHUD( void );
433
434 /*
435 bool AddHUDInstrument( instr_item *pBlackBox );
436 void DrawHUD ( void );
437 bool DamageInstrument( INSTR_HANDLE unit );
438 bool RepairInstrument( INSTR_HANDLE unit );
439
440
441 void fgUpdateHUD ( Hptr hud );
442 void fgUpdateHUD2( Hptr hud ); // Future use?
443 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
444 */
445
446 #endif // _HUD_H
447
448 /* $Log$
449 /* Revision 1.6  1998/06/03 00:43:28  curt
450 /* No .h when including stl stuff.
451 /*
452  * Revision 1.5  1998/05/17 16:58:13  curt
453  * Added a View Frustum Culling ratio display to the hud.
454  *
455  * Revision 1.4  1998/05/16 13:04:15  curt
456  * New updates from Charlie Hotchkiss.
457  *
458  * Revision 1.3  1998/05/13 18:27:55  curt
459  * Added an fov to hud display.
460  *
461  * Revision 1.2  1998/05/11 18:13:12  curt
462  * Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
463  *
464  * Revision 1.15  1998/02/23 19:07:57  curt
465  * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
466  * calculation code between sun display, and other FG sections that use this
467  * for things like lighting.
468  *
469  * Revision 1.14  1998/02/21 14:53:14  curt
470  * Added Charlie's HUD changes.
471  *
472  * Revision 1.13  1998/02/20 00:16:22  curt
473  * Thursday's tweaks.
474  *
475  * Revision 1.12  1998/02/19 13:05:52  curt
476  * Incorporated some HUD tweaks from Michelle America.
477  * Tweaked the sky's sunset/rise colors.
478  * Other misc. tweaks.
479  *
480  * Revision 1.11  1998/02/16 13:38:42  curt
481  * Integrated changes from Charlie Hotchkiss.
482  *
483  * Revision 1.11  1998/02/16 13:38:42  curt
484  * Integrated changes from Charlie Hotchkiss.
485  *
486  * Revision 1.10  1998/02/12 21:59:42  curt
487  * Incorporated code changes contributed by Charlie Hotchkiss
488  * <chotchkiss@namg.us.anritsu.com>
489  *
490  * Revision 1.8  1998/02/07 15:29:35  curt
491  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
492  * <chotchkiss@namg.us.anritsu.com>
493  *
494  * Revision 1.7  1998/02/03 23:20:15  curt
495  * Lots of little tweaks to fix various consistency problems discovered by
496  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
497  * passed arguments along to the real printf().  Also incorporated HUD changes
498  * by Michele America.
499  *
500  * Revision 1.6  1998/01/22 02:59:30  curt
501  * Changed #ifdef FILE_H to #ifdef _FILE_H
502  *
503  * Revision 1.5  1998/01/19 19:27:01  curt
504  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
505  * This should simplify things tremendously.
506  *
507  * Revision 1.4  1998/01/19 18:40:21  curt
508  * Tons of little changes to clean up the code and to remove fatal errors
509  * when building with the c++ compiler.
510  *
511  * Revision 1.3  1997/12/30 16:36:41  curt
512  * Merged in Durk's changes ...
513  *
514  * Revision 1.2  1997/12/10 22:37:40  curt
515  * Prepended "fg" on the name of all global structures that didn't have it yet.
516  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
517  *
518  * Revision 1.1  1997/08/29 18:03:22  curt
519  * Initial revision.
520  *
521  */