1 // hud.hxx -- hud defines and prototypes (initial draft)
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 // (Log is kept at end of this file)
29 # error This library requires C++
45 # include <values.h> // for MAXINT
48 #include <deque> // STL double ended queue
50 #include <fg_typedefs.h>
51 #include <fg_constants.h>
52 #include <Aircraft/aircraft.hxx>
53 #include <FDM/flight.hxx>
54 #include <Controls/controls.hxx>
64 int top, bottom, left, right;
68 // View mode definitions
70 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
72 // DAY, NIGHT and brightness levels need to be visible where dialogs and
73 // controls can be used to set intensity and appropriate color. This will
75 // Hud general constants
92 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
97 #define UPPER_CENTER 3
99 #define CENTER_RIGHT 5
100 #define LOWER_RIGHT 6
101 #define LOWER_CENTER 7
103 #define CENTER_LEFT 9
104 #define SOLID_LINES 10
105 #define DASHED_LINES 11
106 #define DASHED_NEG_LINES 12
109 #define HORIZON_FIXED 1
110 #define HORIZON_MOVING 2
111 #define LABEL_COUNTER 1
112 #define LABEL_WARNING 2
114 #define HUDS_AUTOTICKS 0x0001
115 #define HUDS_VERT 0x0002
116 #define HUDS_HORZ 0x0000
117 #define HUDS_TOP 0x0004
118 #define HUDS_BOTTOM 0x0008
119 #define HUDS_LEFT HUDS_TOP
120 #define HUDS_RIGHT HUDS_BOTTOM
121 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
122 #define HUDS_NOTICKS 0x0010
123 #define HUDS_ARITHTIC 0x0020
124 #define HUDS_DECITICS 0x0040
125 #define HUDS_NOTEXT 0x0080
128 // #define HUD_VERTICAL 1
129 // #define HUD_HORIZONTAL 2
130 // #define HUD_FREEFLOAT 3
132 // Ladder orientation modes
133 // #define HUD_LEFT 1
134 // #define HUD_RIGHT 2
136 // #define HUD_BOTTOM 2
137 // #define HUD_V_LEFT 1
138 // #define HUD_V_RIGHT 2
139 // #define HUD_H_TOP 1
140 // #define HUD_H_BOTTOM 2
145 // #define HUD_NOLIM 2
146 // #define HUD_CIRC 3
148 // #define HUD_INSTR_LADDER 1
149 // #define HUD_INSTR_CLADDER 2
150 // #define HUD_INSTR_HORIZON 3
151 // #define HUD_INSTR_LABEL 4
153 extern double get_throttleval ( void );
154 extern double get_aileronval ( void );
155 extern double get_elevatorval ( void );
156 extern double get_elev_trimval( void );
157 extern double get_rudderval ( void );
158 extern double get_speed ( void );
159 extern double get_aoa ( void );
160 extern double get_roll ( void );
161 extern double get_pitch ( void );
162 extern double get_heading ( void );
163 extern double get_altitude ( void );
164 extern double get_agl ( void );
165 extern double get_sideslip ( void );
166 extern double get_frame_rate ( void );
167 extern double get_latitude ( void );
168 extern double get_lat_min ( void );
169 extern double get_longitude ( void );
170 extern double get_long_min ( void );
171 extern double get_fov ( void );
172 extern double get_vfc_ratio ( void );
173 extern double get_vfc_tris_drawn ( void );
174 extern double get_climb_rate ( void );
176 enum hudinstype{ HUDno_instr,
188 typedef struct gltagRGBTRIPLE { // rgbt
194 class instr_item { // An Abstract Base Class (ABC)
196 static UINT instances; // More than 64K instruments? Nah!
197 static int brightness;
198 static glRGBTRIPLE color;
201 RECT scrn_pos; // Framing - affects scale dimensions
202 // and orientation. Vert vs Horz, etc.
203 DBLFNPTR load_value_fn;
204 double disp_factor; // Multiply by to get numbers shown on scale.
208 UINT scr_span; // Working values for draw;
216 DBLFNPTR data_source,
219 bool working = true);
221 instr_item( const instr_item & image );
223 instr_item & operator = ( const instr_item & rhs );
224 virtual ~instr_item ();
226 int get_brightness ( void ) { return brightness;}
227 RECT get_location ( void ) { return scrn_pos; }
228 bool is_broken ( void ) { return broken; }
229 bool enabled ( void ) { return is_enabled;}
230 bool data_available ( void ) { return !!load_value_fn; }
231 double get_value ( void ) { return load_value_fn(); }
232 double data_scaling ( void ) { return disp_factor; }
233 UINT get_span ( void ) { return scr_span; }
234 POINT get_centroid ( void ) { return mid_span; }
235 UINT get_options ( void ) { return opts; }
237 virtual void display_enable( bool working ) { is_enabled = !! working;}
240 virtual void update( void );
241 virtual void break_display ( bool bad );
242 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
243 void SetPosition ( int x, int y, UINT width, UINT height );
244 UINT get_Handle( void );
245 virtual void draw( void ) = 0; // Required method in derived classes
248 typedef deque< instr_item * > HudContainerType;
249 typedef HudContainerType::iterator HudIterator;
251 typedef instr_item *HIptr;
252 extern HudContainerType HUD_deque;
254 // instr_item This class has no other purpose than to maintain
255 // a linked list of instrument and derived class
259 class instr_label : public instr_item {
263 const char *post_str;
273 DBLFNPTR data_source,
274 const char *label_format,
275 const char *pre_label_string = 0,
276 const char *post_label_string = 0,
277 double scale_data = 1.0,
278 UINT options = HUDS_TOP,
279 fgLabelJust justification = CENTER_JUST,
280 int font_size = SMALL,
281 int blinking = NOBLINK,
282 bool working = true);
286 instr_label( const instr_label & image);
287 instr_label & operator = (const instr_label & rhs );
288 virtual void draw( void ); // Required method in base class
291 typedef instr_label * pInstlabel;
294 // instr_scale This class is an abstract base class for both moving
295 // scale and moving needle (fixed scale) indicators. It
296 // does not draw itself, but is not instanciable.
299 class instr_scale : public instr_item {
301 double range_shown; // Width Units.
302 double Maximum_value; // ceiling.
303 double Minimum_value; // Representation floor.
304 double scale_factor; // factor => screen units/range values.
305 UINT Maj_div; // major division marker units
306 UINT Min_div; // minor division marker units
307 UINT Modulo; // Roll over point
308 int signif_digits; // digits to show to the right.
318 double max_value = 100.0,
319 double min_value = 0.0,
320 double disp_scaling = 1.0,
321 UINT major_divs = 10,
325 bool working = true);
327 virtual ~instr_scale();
328 instr_scale( const instr_scale & image);
329 instr_scale & operator = (const instr_scale & rhs);
331 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
332 UINT div_min ( void ) { return Min_div;}
333 UINT div_max ( void ) { return Maj_div;}
334 double min_val ( void ) { return Minimum_value;}
335 double max_val ( void ) { return Maximum_value;}
336 UINT modulo ( void ) { return Modulo; }
337 double factor ( void ) { return scale_factor;}
338 double range_to_show( void ) { return range_shown;}
341 // hud_card_ This class displays the indicated quantity on
342 // a scale that moves past the pointer. It may be
343 // horizontal or vertical, read above(left) or below(right) of the base
346 class hud_card : public instr_scale {
349 double half_width_units;
358 double maxValue = 100.0,
359 double minValue = 0.0,
360 double disp_scaling = 1.0,
361 UINT major_divs = 10,
363 UINT modulator = 100,
365 double value_span = 100.0,
366 bool working = true);
369 hud_card( const hud_card & image);
370 hud_card & operator = (const hud_card & rhs );
371 // virtual void display_enable( bool setting );
372 virtual void draw( void ); // Required method in base class
375 typedef hud_card * pCardScale;
377 class guage_instr : public instr_scale {
387 double disp_scaling = 1.0,
388 double maxValue = 100,
390 UINT major_divs = 50,
394 bool working = true);
397 guage_instr( const guage_instr & image);
398 guage_instr & operator = (const guage_instr & rhs );
399 virtual void draw( void ); // Required method in base class
402 typedef guage_instr * pGuageInst;
404 // dual_instr_item This class was created to form the base class
405 // for both panel and HUD Turn Bank Indicators.
407 class dual_instr_item : public instr_item {
409 DBLFNPTR alt_data_source;
412 dual_instr_item ( int x,
416 DBLFNPTR chn1_source,
417 DBLFNPTR chn2_source,
419 UINT options = HUDS_TOP);
421 virtual ~dual_instr_item() {};
422 dual_instr_item( const dual_instr_item & image);
423 dual_instr_item & operator = (const dual_instr_item & rhs );
425 double current_ch1( void ) { return alt_data_source();}
426 double current_ch2( void ) { return get_value();}
427 virtual void draw ( void ) { }
430 class fgTBI_instr : public dual_instr_item {
441 DBLFNPTR chn1_source = get_roll,
442 DBLFNPTR chn2_source = get_sideslip,
443 double maxBankAngle = 45.0,
444 double maxSlipAngle = 5.0,
445 UINT gap_width = 5.0,
446 bool working = true);
448 fgTBI_instr( const fgTBI_instr & image);
449 fgTBI_instr & operator = (const fgTBI_instr & rhs );
453 UINT bank_limit( void ) { return BankLimit;}
454 UINT slew_limit( void ) { return SlewLimit;}
456 virtual void draw( void ); // Required method in base class
459 typedef fgTBI_instr * pTBI;
461 class HudLadder : public dual_instr_item {
477 DBLFNPTR ptch_source = get_roll,
478 DBLFNPTR roll_source = get_pitch,
479 double span_units = 45.0,
480 double division_units = 10.0,
481 double minor_division = 0.0,
482 UINT screen_hole = 70,
484 bool working = true );
488 HudLadder( const HudLadder & image );
489 HudLadder & operator = ( const HudLadder & rhs );
490 virtual void draw( void );
494 //using namespace std;
495 //deque <instr_item> * Hdeque_ptr;
497 extern void HUD_brightkey( bool incr_bright );
498 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
499 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
500 extern void fgUpdateHUD( void );
502 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
503 extern void drawOneLine ( RECT &rect);
504 extern void textString ( int x,
507 void *font = GLUT_BITMAP_8_BY_13);
508 extern void strokeString( int x,
511 void *font = GLUT_STROKE_ROMAN,
514 bool AddHUDInstrument( instr_item *pBlackBox );
515 void DrawHUD ( void );
516 bool DamageInstrument( INSTR_HANDLE unit );
517 bool RepairInstrument( INSTR_HANDLE unit );
520 void fgUpdateHUD ( Hptr hud );
521 void fgUpdateHUD2( Hptr hud ); // Future use?
522 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
528 // Revision 1.19 1999/03/02 01:02:38 curt
529 // Tweaks for building with native SGI compilers.
531 // Revision 1.18 1999/02/26 22:08:45 curt
532 // Added initial support for native SGI compilers.
534 // Revision 1.17 1999/02/01 21:33:28 curt
535 // Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
536 // Jon accepted my offer to do this and thought it was a good idea.
538 // Revision 1.16 1998/10/17 01:33:59 curt
541 // Revision 1.15 1998/10/16 23:27:27 curt
544 // Revision 1.14 1998/09/29 14:56:33 curt
545 // c++-ified comments.
547 // Revision 1.13 1998/09/29 02:01:09 curt
548 // Added a "rate of climb" indicator.
550 // Revision 1.12 1998/08/24 20:05:17 curt
551 // Added a second minimalistic HUD.
552 // Added code to display the number of triangles rendered.
554 // Revision 1.11 1998/07/24 21:36:55 curt
555 // Ran dos2unix to get rid of extraneous ^M's. Tweaked parameter in
556 // ImageGetRawData() to match usage.
558 // Revision 1.10 1998/07/13 21:28:02 curt
559 // Converted the aoa scale to a radio altimeter.
561 // Revision 1.9 1998/07/13 21:00:48 curt
562 // Integrated Charlies latest HUD updates.
563 // Wrote access functions for current fgOPTIONS.
565 // Revision 1.8 1998/07/03 13:16:29 curt
566 // Added Charlie Hotchkiss's HUD updates and improvementes.
568 // Revision 1.6 1998/06/03 00:43:28 curt
569 // No .h when including stl stuff.
571 // Revision 1.5 1998/05/17 16:58:13 curt
572 // Added a View Frustum Culling ratio display to the hud.
574 // Revision 1.4 1998/05/16 13:04:15 curt
575 // New updates from Charlie Hotchkiss.
577 // Revision 1.3 1998/05/13 18:27:55 curt
578 // Added an fov to hud display.
580 // Revision 1.2 1998/05/11 18:13:12 curt
581 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
583 // Revision 1.15 1998/02/23 19:07:57 curt
584 // Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
585 // calculation code between sun display, and other FG sections that use this
586 // for things like lighting.
588 // Revision 1.14 1998/02/21 14:53:14 curt
589 // Added Charlie's HUD changes.
591 // Revision 1.13 1998/02/20 00:16:22 curt
592 // Thursday's tweaks.
594 // Revision 1.12 1998/02/19 13:05:52 curt
595 // Incorporated some HUD tweaks from Michelle America.
596 // Tweaked the sky's sunset/rise colors.
597 // Other misc. tweaks.
599 // Revision 1.11 1998/02/16 13:38:42 curt
600 // Integrated changes from Charlie Hotchkiss.
602 // Revision 1.11 1998/02/16 13:38:42 curt
603 // Integrated changes from Charlie Hotchkiss.
605 // Revision 1.10 1998/02/12 21:59:42 curt
606 // Incorporated code changes contributed by Charlie Hotchkiss
607 // <chotchkiss@namg.us.anritsu.com>
609 // Revision 1.8 1998/02/07 15:29:35 curt
610 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
611 // <chotchkiss@namg.us.anritsu.com>
613 // Revision 1.7 1998/02/03 23:20:15 curt
614 // Lots of little tweaks to fix various consistency problems discovered by
615 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
616 // passed arguments along to the real printf(). Also incorporated HUD changes
617 // by Michele America.
619 // Revision 1.6 1998/01/22 02:59:30 curt
620 // Changed #ifdef FILE_H to #ifdef _FILE_H
622 // Revision 1.5 1998/01/19 19:27:01 curt
623 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
624 // This should simplify things tremendously.
626 // Revision 1.4 1998/01/19 18:40:21 curt
627 // Tons of little changes to clean up the code and to remove fatal errors
628 // when building with the c++ compiler.
630 // Revision 1.3 1997/12/30 16:36:41 curt
631 // Merged in Durk's changes ...
633 // Revision 1.2 1997/12/10 22:37:40 curt
634 // Prepended "fg" on the name of all global structures that didn't have it yet.
635 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
637 // Revision 1.1 1997/08/29 18:03:22 curt