1 /**************************************************************************
2 * hud.hxx -- hud defines and prototypes (initial draft)
4 * Written by Michele America, started September 1997.
6 * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
31 # error This library requires C++
47 # include <values.h> // for MAXINT
50 #include <fg_typedefs.h>
51 #include <fg_constants.h>
52 #include <Aircraft/aircraft.h>
53 #include <Flight/flight.h>
54 #include <Controls/controls.h>
57 #include <deque> // STL
58 #ifdef NEEDNAMESPACESTD
68 int top, bottom, left, right;
72 // View mode definitions
74 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
76 // DAY, NIGHT and brightness levels need to be visible where dialogs and
77 // controls can be used to set intensity and appropriate color. This will
79 // Hud general constants
96 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
101 #define UPPER_CENTER 3
102 #define UPPER_RIGHT 4
103 #define CENTER_RIGHT 5
104 #define LOWER_RIGHT 6
105 #define LOWER_CENTER 7
107 #define CENTER_LEFT 9
108 #define SOLID_LINES 10
109 #define DASHED_LINES 11
110 #define DASHED_NEG_LINES 12
113 #define HORIZON_FIXED 1
114 #define HORIZON_MOVING 2
115 #define LABEL_COUNTER 1
116 #define LABEL_WARNING 2
118 #define HUDS_AUTOTICKS 0x0001
119 #define HUDS_VERT 0x0002
\r
120 #define HUDS_HORZ 0x0000
\r
121 #define HUDS_TOP 0x0004
\r
122 #define HUDS_BOTTOM 0x0008
\r
123 #define HUDS_LEFT HUDS_TOP
\r
124 #define HUDS_RIGHT HUDS_BOTTOM
\r
125 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
\r
126 #define HUDS_NOTICKS 0x0010
\r
127 #define HUDS_ARITHTIC 0x0020
\r
128 #define HUDS_DECITICS 0x0040
\r
129 #define HUDS_NOTEXT 0x0080
\r
132 // #define HUD_VERTICAL 1
133 // #define HUD_HORIZONTAL 2
134 // #define HUD_FREEFLOAT 3
136 // Ladder orientation modes
137 // #define HUD_LEFT 1
138 // #define HUD_RIGHT 2
140 // #define HUD_BOTTOM 2
141 // #define HUD_V_LEFT 1
142 // #define HUD_V_RIGHT 2
143 // #define HUD_H_TOP 1
144 // #define HUD_H_BOTTOM 2
149 // #define HUD_NOLIM 2
150 // #define HUD_CIRC 3
152 // #define HUD_INSTR_LADDER 1
153 // #define HUD_INSTR_CLADDER 2
154 // #define HUD_INSTR_HORIZON 3
155 // #define HUD_INSTR_LABEL 4
157 extern double get_throttleval ( void );
158 extern double get_aileronval ( void );
159 extern double get_elevatorval ( void );
160 extern double get_elev_trimval( void );
161 extern double get_rudderval ( void );
162 extern double get_speed ( void );
163 extern double get_aoa ( void );
164 extern double get_roll ( void );
165 extern double get_pitch ( void );
166 extern double get_heading ( void );
167 extern double get_altitude ( void );
168 extern double get_sideslip ( void );
169 extern double get_frame_rate ( void );
170 extern double get_latitude ( void );
171 extern double get_lat_min ( void );
172 extern double get_longitude ( void );
173 extern double get_long_min ( void );
174 extern double get_fov ( void );
175 extern double get_vfc_ratio ( void );
177 enum hudinstype{ HUDno_instr,
189 typedef struct gltagRGBTRIPLE { // rgbt
195 class instr_item { // An Abstract Base Class (ABC)
197 static UINT instances; // More than 64K instruments? Nah!
198 static int brightness;
199 static glRGBTRIPLE color;
202 RECT scrn_pos; // Framing - affects scale dimensions
203 // and orientation. Vert vs Horz, etc.
204 DBLFNPTR load_value_fn;
205 double disp_factor; // Multiply by to get numbers shown on scale.
209 UINT scr_span; // Working values for draw;
217 DBLFNPTR data_source,
220 bool working = true);
222 instr_item( const instr_item & image );
224 instr_item & operator = ( const instr_item & rhs );
225 virtual ~instr_item ();
227 int get_brightness ( void ) { return brightness;}
228 RECT get_location ( void ) { return scrn_pos; }
229 bool is_broken ( void ) { return broken; }
230 bool enabled ( void ) { return is_enabled;}
231 bool data_available ( void ) { return !!load_value_fn; }
232 double get_value ( void ) { return load_value_fn(); }
233 double data_scaling ( void ) { return disp_factor; }
234 UINT get_span ( void ) { return scr_span; }
235 POINT get_centroid ( void ) { return mid_span; }
236 UINT get_options ( void ) { return opts; }
238 virtual void display_enable( bool working ) { is_enabled = !! working;}
241 virtual void update( void );
242 virtual void break_display ( bool bad );
243 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
244 void SetPosition ( int x, int y, UINT width, UINT height );
245 UINT get_Handle( void );
246 virtual void draw( void ) = 0; // Required method in derived classes
249 typedef instr_item *HIptr;
250 extern deque< instr_item *> HUD_deque;
252 // instr_item This class has no other purpose than to maintain
253 // a linked list of instrument and derived class
257 class instr_label : public instr_item {
261 const char *post_str;
271 DBLFNPTR data_source,
272 const char *label_format,
273 const char *pre_label_string = 0,
274 const char *post_label_string = 0,
275 double scale_data = 1.0,
276 UINT options = HUDS_TOP,
277 fgLabelJust justification = CENTER_JUST,
278 int font_size = SMALL,
279 int blinking = NOBLINK,
280 bool working = true);
284 instr_label( const instr_label & image);
285 instr_label & operator = (const instr_label & rhs );
286 virtual void draw( void ); // Required method in base class
289 typedef instr_label * pInstlabel;
292 // instr_scale This class is an abstract base class for both moving
293 // scale and moving needle (fixed scale) indicators. It
294 // does not draw itself, but is not instanciable.
297 class instr_scale : public instr_item {
299 double range_shown; // Width Units.
300 double Maximum_value; // ceiling.
301 double Minimum_value; // Representation floor.
302 double scale_factor; // factor => screen units/range values.
303 UINT Maj_div; // major division marker units
304 UINT Min_div; // minor division marker units
305 UINT Modulo; // Roll over point
306 int signif_digits; // digits to show to the right.
316 double max_value = 100.0,
317 double min_value = 0.0,
318 double disp_scaling = 1.0,
319 UINT major_divs = 10,
323 bool working = true);
325 virtual ~instr_scale();
326 instr_scale( const instr_scale & image);
327 instr_scale & operator = (const instr_scale & rhs);
329 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
330 UINT div_min ( void ) { return Min_div;}
331 UINT div_max ( void ) { return Maj_div;}
332 double min_val ( void ) { return Minimum_value;}
333 double max_val ( void ) { return Maximum_value;}
334 UINT modulo ( void ) { return Modulo; }
335 double factor ( void ) { return scale_factor;}
336 double range_to_show( void ) { return range_shown;}
339 // hud_card_ This class displays the indicated quantity on
340 // a scale that moves past the pointer. It may be
341 // horizontal or vertical, read above(left) or below(right) of the base
344 class hud_card : public instr_scale {
347 double half_width_units;
356 double maxValue = 100.0,
357 double minValue = 0.0,
358 double disp_scaling = 1.0,
359 UINT major_divs = 10,
361 UINT modulator = 100,
363 double value_span = 100.0,
364 bool working = true);
367 hud_card( const hud_card & image);
368 hud_card & operator = (const hud_card & rhs );
369 // virtual void display_enable( bool setting );
370 virtual void draw( void ); // Required method in base class
373 typedef hud_card * pCardScale;
375 class guage_instr : public instr_scale {
385 double disp_scaling = 1.0,
386 double maxValue = 100,
388 UINT major_divs = 50,
392 bool working = true);
395 guage_instr( const guage_instr & image);
396 guage_instr & operator = (const guage_instr & rhs );
397 virtual void draw( void ); // Required method in base class
400 typedef guage_instr * pGuageInst;
402 // dual_instr_item This class was created to form the base class
403 // for both panel and HUD Turn Bank Indicators.
405 class dual_instr_item : public instr_item {
407 DBLFNPTR alt_data_source;
410 dual_instr_item ( int x,
414 DBLFNPTR chn1_source,
415 DBLFNPTR chn2_source,
417 UINT options = HUDS_TOP);
419 virtual ~dual_instr_item() {};
420 dual_instr_item( const dual_instr_item & image);
421 dual_instr_item & operator = (const dual_instr_item & rhs );
423 double current_ch1( void ) { return alt_data_source();}
424 double current_ch2( void ) { return get_value();}
425 virtual void draw ( void ) { }
428 class fgTBI_instr : public dual_instr_item {
439 DBLFNPTR chn1_source = get_roll,
440 DBLFNPTR chn2_source = get_sideslip,
441 double maxBankAngle = 45.0,
442 double maxSlipAngle = 5.0,
443 UINT gap_width = 5.0,
444 bool working = true);
446 fgTBI_instr( const fgTBI_instr & image);
447 fgTBI_instr & operator = (const fgTBI_instr & rhs );
451 UINT bank_limit( void ) { return BankLimit;}
452 UINT slew_limit( void ) { return SlewLimit;}
454 virtual void draw( void ); // Required method in base class
457 typedef fgTBI_instr * pTBI;
459 class HudLadder : public dual_instr_item {
475 DBLFNPTR ptch_source = get_roll,
476 DBLFNPTR roll_source = get_pitch,
477 double span_units = 45.0,
478 double division_units = 10.0,
479 double minor_division = 0.0,
480 UINT screen_hole = 70,
482 bool working = true );
486 HudLadder( const HudLadder & image );
487 HudLadder & operator = ( const HudLadder & rhs );
488 virtual void draw( void );
492 //using namespace std;
493 //deque <instr_item> * Hdeque_ptr;
495 extern void HUD_brightkey( bool incr_bright );
496 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
497 extern void fgUpdateHUD( void );
499 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
500 extern void drawOneLine ( RECT &rect);
501 extern void textString ( int x,
504 void *font = GLUT_BITMAP_8_BY_13);
505 extern void strokeString( int x,
508 void *font = GLUT_STROKE_ROMAN,
511 bool AddHUDInstrument( instr_item *pBlackBox );
512 void DrawHUD ( void );
513 bool DamageInstrument( INSTR_HANDLE unit );
514 bool RepairInstrument( INSTR_HANDLE unit );
517 void fgUpdateHUD ( Hptr hud );
518 void fgUpdateHUD2( Hptr hud ); // Future use?
519 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
525 /* Revision 1.9 1998/07/13 21:00:48 curt
526 /* Integrated Charlies latest HUD updates.
527 /* Wrote access functions for current fgOPTIONS.
529 * Revision 1.8 1998/07/03 13:16:29 curt
530 * Added Charlie Hotchkiss's HUD updates and improvementes.
532 * Revision 1.6 1998/06/03 00:43:28 curt
533 * No .h when including stl stuff.
535 * Revision 1.5 1998/05/17 16:58:13 curt
536 * Added a View Frustum Culling ratio display to the hud.
538 * Revision 1.4 1998/05/16 13:04:15 curt
539 * New updates from Charlie Hotchkiss.
541 * Revision 1.3 1998/05/13 18:27:55 curt
542 * Added an fov to hud display.
544 * Revision 1.2 1998/05/11 18:13:12 curt
545 * Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
547 * Revision 1.15 1998/02/23 19:07:57 curt
548 * Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
549 * calculation code between sun display, and other FG sections that use this
550 * for things like lighting.
552 * Revision 1.14 1998/02/21 14:53:14 curt
553 * Added Charlie's HUD changes.
555 * Revision 1.13 1998/02/20 00:16:22 curt
558 * Revision 1.12 1998/02/19 13:05:52 curt
559 * Incorporated some HUD tweaks from Michelle America.
560 * Tweaked the sky's sunset/rise colors.
561 * Other misc. tweaks.
563 * Revision 1.11 1998/02/16 13:38:42 curt
564 * Integrated changes from Charlie Hotchkiss.
566 * Revision 1.11 1998/02/16 13:38:42 curt
567 * Integrated changes from Charlie Hotchkiss.
569 * Revision 1.10 1998/02/12 21:59:42 curt
570 * Incorporated code changes contributed by Charlie Hotchkiss
571 * <chotchkiss@namg.us.anritsu.com>
573 * Revision 1.8 1998/02/07 15:29:35 curt
574 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
575 * <chotchkiss@namg.us.anritsu.com>
577 * Revision 1.7 1998/02/03 23:20:15 curt
578 * Lots of little tweaks to fix various consistency problems discovered by
579 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
580 * passed arguments along to the real printf(). Also incorporated HUD changes
581 * by Michele America.
583 * Revision 1.6 1998/01/22 02:59:30 curt
584 * Changed #ifdef FILE_H to #ifdef _FILE_H
586 * Revision 1.5 1998/01/19 19:27:01 curt
587 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
588 * This should simplify things tremendously.
590 * Revision 1.4 1998/01/19 18:40:21 curt
591 * Tons of little changes to clean up the code and to remove fatal errors
592 * when building with the c++ compiler.
594 * Revision 1.3 1997/12/30 16:36:41 curt
595 * Merged in Durk's changes ...
597 * Revision 1.2 1997/12/10 22:37:40 curt
598 * Prepended "fg" on the name of all global structures that didn't have it yet.
599 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
601 * Revision 1.1 1997/08/29 18:03:22 curt