]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud.hxx
Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
[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.h>       // 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
148 enum  hudinstype{ HUDno_instr,
149               HUDscale,
150               HUDlabel,
151               HUDladder,
152               HUDcirc_ladder,
153               HUDhorizon,
154               HUDguage,
155               HUDdual_inst,
156               HUDmoving_scale,
157               HUDtbi
158               };
159
160 enum ReadOriented{ ReadRIGHT, ReadLEFT, ReadTOP, ReadBOTTOM };
161
162 class instr_item {  // An Abstract Base Class (ABC)
163   private:
164     static UINT      instances;     // More than 64K instruments? Nah!
165     UINT             handle;
166     RECT             scrn_pos;      // Framing - affects scale dimensions
167                                     // and orientation. Vert vs Horz, etc.
168     DBLFNPTR         load_value_fn;
169     ReadOriented     oriented;
170     bool             is_enabled;
171     bool             broken;
172     int              brightness;
173     UINT             scr_span;      // Working values for draw;
174     POINT            mid_span;      //
175
176   public:
177     instr_item( RECT           scrn_pos,
178                 DBLFNPTR       data_source,
179                 ReadOriented   orient,
180                 bool           working      = true);
181
182     instr_item( const instr_item & image );
183
184     instr_item & operator = ( const instr_item & rhs );
185     virtual ~instr_item ();
186
187     int          get_brightness  ( void ) { return brightness;}
188     RECT         get_location    ( void ) { return scrn_pos;  }
189     bool         is_broken       ( void ) { return broken;    }
190     bool         enabled         ( void ) { return is_enabled;}
191     double       get_value       ( void ) { return load_value_fn();}
192     UINT         get_span        ( void ) { return scr_span;  }
193     POINT        get_centroid    ( void ) { return mid_span;  }
194     ReadOriented get_orientation ( void ) { return oriented;  }
195
196     virtual void display_enable( bool working ) { is_enabled = !! working;}
197
198
199     virtual void update( void );
200     virtual void break_display ( bool bad );
201     virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
202     UINT    get_Handle( void );
203     virtual void draw( void ) = 0;   // Required method in derived classes
204 };
205
206 typedef instr_item *HIptr;
207 extern deque< instr_item *> HUD_deque;
208
209 // instr_item           This class has no other purpose than to maintain
210 //                      a linked list of instrument and derived class
211 // object pointers.
212
213
214 class instr_label : public instr_item {
215   private:
216     const char *pformat;
217     const char *pre_str;
218     const char *post_str;
219     fgLabelJust justify;
220     int         fontSize;
221     int         blink;
222
223   public:
224     instr_label( RECT         the_box,
225                  DBLFNPTR     data_source,
226                  const char  *label_format,
227                  const char  *pre_label_string    = 0,
228                  const char  *post_label_string   = 0,
229                  ReadOriented orientation         = ReadTOP,
230                  fgLabelJust  justification       = CENTER_JUST,
231                  int          font_size           = SMALL,
232                  int          blinking            = NOBLINK,
233                  bool         working             = true);
234
235     ~instr_label();
236
237     instr_label( const instr_label & image);
238     instr_label & operator = (const instr_label & rhs );
239
240     virtual void draw( void );       // Required method in base class
241 };
242
243 typedef instr_label * pInstlabel;
244
245 //
246 // instr_scale           This class is an abstract base class for both moving
247 //                       scale and moving needle (fixed scale) indicators. It
248 // does not draw itself, but is not instanciable.
249 //
250
251 class instr_scale : public instr_item {
252   private:
253     int    range_shown;   // Width Units.
254     int    Maximum_value; //                ceiling.
255     int    Minimum_value; // Representation floor.
256     UINT   Maj_div;       // major division marker units
257     UINT   Min_div;       // minor division marker units
258     UINT   Modulo;        // Roll over point
259     double scale_factor;  // factor => screen units/range values.
260
261   public:
262     instr_scale( RECT         the_box,
263                  DBLFNPTR     load_fn,
264                  ReadOriented orient,
265                  int          show_range,
266                  int          max_value,
267                  int          min_value    =   0,
268                  UINT         major_divs   =  10,
269                  UINT         minor_divs   =   5,
270                  UINT         rollover     =   0,
271                  bool         working      = true);
272
273     virtual ~instr_scale();
274     instr_scale( const instr_scale & image);
275     instr_scale & operator = (const instr_scale & rhs);
276
277     virtual void draw   ( void ) {}; // No-op here. Defined in derived classes.
278     UINT   div_min      ( void ) { return Min_div;}
279     UINT   div_max      ( void ) { return Maj_div;}
280     int    min_val      ( void ) { return Minimum_value;}
281     int    max_val      ( void ) { return Maximum_value;}
282     UINT   modulo       ( void ) { return Modulo; }
283     double factor       ( void ) { return scale_factor;}
284     double range_to_show( void ) { return range_shown;}
285 };
286
287 // moving_scale_instr      This class displays the indicated quantity on
288 //                         a scale that moves past the pointer. It may be
289 // horizontal or vertical, read above(left) or below(right) of the base
290 // line.
291
292 class moving_scale : public instr_scale {
293   private:
294     double val_span;
295     double half_width_units;
296
297   public:
298     moving_scale( RECT         box,
299                   DBLFNPTR     load_fn,
300                   ReadOriented readway,
301                   int          maxValue,
302                   int          minValue,
303                   UINT         major_divs,
304                   UINT         minor_divs,
305                   UINT         modulator,
306                   double       value_span,
307                   bool         working = true);
308
309     ~moving_scale();
310     moving_scale( const moving_scale & image);
311     moving_scale & operator = (const moving_scale & rhs );
312 //    virtual void display_enable( bool setting );
313     virtual void draw( void );       // Required method in base class
314 };
315
316 typedef moving_scale * pMoveScale;
317
318 class guage_instr : public instr_scale {
319   private:
320
321   public:
322     guage_instr( RECT         box,
323                  DBLFNPTR     load_fn,
324                  ReadOriented readway,
325                  int          maxValue,
326                  int          minValue,
327                  UINT         major_divs,
328                  UINT         minor_divs,
329                  UINT         modulus,
330                  bool         working = true);
331
332     ~guage_instr();
333     guage_instr( const guage_instr & image);
334     guage_instr & operator = (const guage_instr & rhs );
335     virtual void draw( void );       // Required method in base class
336 };
337
338 typedef guage_instr * pGuageInst;
339 //
340 // dual_instr_item         This class was created to form the base class
341 //                         for both panel and HUD Turn Bank Indicators.
342
343 class dual_instr_item : public instr_item {
344   private:
345     DBLFNPTR alt_data_source;
346
347   public:
348     dual_instr_item ( RECT         the_box,
349                       DBLFNPTR     chn1_source,
350                       DBLFNPTR     chn2_source,
351                       bool         working     = true,
352                       ReadOriented readway  = ReadTOP);
353
354     virtual ~dual_instr_item() {};
355     dual_instr_item( const dual_instr_item & image);
356     dual_instr_item & operator = (const dual_instr_item & rhs );
357
358     double current_ch1( void ) { return alt_data_source();}
359     double current_ch2( void ) { return get_value();}
360     virtual void draw ( void ) { }
361 };
362
363 class fgTBI_instr : public dual_instr_item {
364   private:
365     UINT BankLimit;
366     UINT SlewLimit;
367     UINT scr_hole;
368
369   public:
370     fgTBI_instr( RECT      the_box,
371                  DBLFNPTR  chn1_source  = get_roll,
372                  DBLFNPTR  chn2_source  = get_sideslip,
373                  UINT      maxBankAngle = 45,
374                  UINT      maxSlipAngle =  5,
375                  UINT      gap_width    =  5,
376                  bool      working      =  true);
377
378     fgTBI_instr( const fgTBI_instr & image);
379     fgTBI_instr & operator = (const fgTBI_instr & rhs );
380
381     ~fgTBI_instr();
382
383     UINT bank_limit( void ) { return BankLimit;}
384     UINT slew_limit( void ) { return SlewLimit;}
385
386     virtual void draw( void );       // Required method in base class
387 };
388
389 typedef fgTBI_instr * pTBI;
390
391 class HudLadder : public dual_instr_item {
392   private:
393     UINT   width_units;
394     int    div_units;
395     UINT   minor_div;
396     UINT   label_pos;
397     UINT   scr_hole;
398     int    vmax;
399     int    vmin;
400     double factor;
401
402   public:
403     HudLadder( RECT      the_box,
404                DBLFNPTR  ptch_source    = get_roll,
405                DBLFNPTR  roll_source    = get_pitch,
406                UINT      span_units     = 45,
407                int       division_units = 10,
408                UINT      minor_division = 0,
409                UINT      screen_hole    = 70,
410                UINT      lbl_pos        = 0,
411                bool      working        = true );
412
413     ~HudLadder();
414
415     HudLadder( const HudLadder & image );
416     HudLadder & operator = ( const HudLadder & rhs );
417     virtual void draw( void );
418 };
419
420
421 //using namespace std;
422 //deque <instr_item>  * Hdeque_ptr;
423
424 extern int  fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
425 extern void fgUpdateHUD( void );
426
427 /*
428 bool AddHUDInstrument( instr_item *pBlackBox );
429 void DrawHUD ( void );
430 bool DamageInstrument( INSTR_HANDLE unit );
431 bool RepairInstrument( INSTR_HANDLE unit );
432
433
434 void fgUpdateHUD ( Hptr hud );
435 void fgUpdateHUD2( Hptr hud ); // Future use?
436 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
437 */
438
439 #endif // _HUD_H
440
441 /* $Log$
442 /* Revision 1.2  1998/05/11 18:13:12  curt
443 /* Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
444 /*
445  * Revision 1.15  1998/02/23 19:07:57  curt
446  * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
447  * calculation code between sun display, and other FG sections that use this
448  * for things like lighting.
449  *
450  * Revision 1.14  1998/02/21 14:53:14  curt
451  * Added Charlie's HUD changes.
452  *
453  * Revision 1.13  1998/02/20 00:16:22  curt
454  * Thursday's tweaks.
455  *
456  * Revision 1.12  1998/02/19 13:05:52  curt
457  * Incorporated some HUD tweaks from Michelle America.
458  * Tweaked the sky's sunset/rise colors.
459  * Other misc. tweaks.
460  *
461  * Revision 1.11  1998/02/16 13:38:42  curt
462  * Integrated changes from Charlie Hotchkiss.
463  *
464  * Revision 1.11  1998/02/16 13:38:42  curt
465  * Integrated changes from Charlie Hotchkiss.
466  *
467  * Revision 1.10  1998/02/12 21:59:42  curt
468  * Incorporated code changes contributed by Charlie Hotchkiss
469  * <chotchkiss@namg.us.anritsu.com>
470  *
471  * Revision 1.8  1998/02/07 15:29:35  curt
472  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
473  * <chotchkiss@namg.us.anritsu.com>
474  *
475  * Revision 1.7  1998/02/03 23:20:15  curt
476  * Lots of little tweaks to fix various consistency problems discovered by
477  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
478  * passed arguments along to the real printf().  Also incorporated HUD changes
479  * by Michele America.
480  *
481  * Revision 1.6  1998/01/22 02:59:30  curt
482  * Changed #ifdef FILE_H to #ifdef _FILE_H
483  *
484  * Revision 1.5  1998/01/19 19:27:01  curt
485  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
486  * This should simplify things tremendously.
487  *
488  * Revision 1.4  1998/01/19 18:40:21  curt
489  * Tons of little changes to clean up the code and to remove fatal errors
490  * when building with the c++ compiler.
491  *
492  * Revision 1.3  1997/12/30 16:36:41  curt
493  * Merged in Durk's changes ...
494  *
495  * Revision 1.2  1997/12/10 22:37:40  curt
496  * Prepended "fg" on the name of all global structures that didn't have it yet.
497  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
498  *
499  * Revision 1.1  1997/08/29 18:03:22  curt
500  * Initial revision.
501  *
502  */