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