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.
28 # error This library requires C++
44 # include <values.h> // for MAXINT
47 #include <vector> // STL vector
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>
56 #include <Math/mat3.h>
60 FG_USING_NAMESPACE(std);
69 int top, bottom, left, right;
73 // View mode definitions
75 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
77 // DAY, NIGHT and brightness levels need to be visible where dialogs and
78 // controls can be used to set intensity and appropriate color. This will
80 // Hud general constants
97 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
102 #define UPPER_CENTER 3
103 #define UPPER_RIGHT 4
104 #define CENTER_RIGHT 5
105 #define LOWER_RIGHT 6
106 #define LOWER_CENTER 7
108 #define CENTER_LEFT 9
109 #define SOLID_LINES 10
110 #define DASHED_LINES 11
111 #define DASHED_NEG_LINES 12
114 #define HORIZON_FIXED 1
115 #define HORIZON_MOVING 2
116 #define LABEL_COUNTER 1
117 #define LABEL_WARNING 2
119 #define HUDS_AUTOTICKS 0x0001
120 #define HUDS_VERT 0x0002
121 #define HUDS_HORZ 0x0000
122 #define HUDS_TOP 0x0004
123 #define HUDS_BOTTOM 0x0008
124 #define HUDS_LEFT HUDS_TOP
125 #define HUDS_RIGHT HUDS_BOTTOM
126 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
127 #define HUDS_NOTICKS 0x0010
128 #define HUDS_ARITHTIC 0x0020
129 #define HUDS_DECITICS 0x0040
130 #define HUDS_NOTEXT 0x0080
133 // #define HUD_VERTICAL 1
134 // #define HUD_HORIZONTAL 2
135 // #define HUD_FREEFLOAT 3
137 // Ladder orientation modes
138 // #define HUD_LEFT 1
139 // #define HUD_RIGHT 2
141 // #define HUD_BOTTOM 2
142 // #define HUD_V_LEFT 1
143 // #define HUD_V_RIGHT 2
144 // #define HUD_H_TOP 1
145 // #define HUD_H_BOTTOM 2
150 // #define HUD_NOLIM 2
151 // #define HUD_CIRC 3
153 // #define HUD_INSTR_LADDER 1
154 // #define HUD_INSTR_CLADDER 2
155 // #define HUD_INSTR_HORIZON 3
156 // #define HUD_INSTR_LABEL 4
159 extern float get_throttleval ( void );
160 extern float get_aileronval ( void );
161 extern float get_elevatorval ( void );
162 extern float get_elev_trimval( void );
163 extern float get_rudderval ( void );
164 extern float get_speed ( void );
165 extern float get_aoa ( void );
166 extern float get_roll ( void );
167 extern float get_pitch ( void );
168 extern float get_heading ( void );
169 extern float get_view_direction( void );
170 extern float get_altitude ( void );
171 extern float get_agl ( void );
172 extern float get_sideslip ( void );
173 extern float get_frame_rate ( void );
174 extern float get_latitude ( void );
175 extern float get_lat_min ( void );
176 extern float get_longitude ( void );
177 extern float get_long_min ( void );
178 extern float get_fov ( void );
179 extern float get_vfc_ratio ( void );
180 extern float get_vfc_tris_drawn ( void );
181 extern float get_vfc_tris_culled ( void );
182 extern float get_climb_rate ( void );
183 extern char *coord_format_lat(float);
184 extern char *coord_format_lon(float);
185 //extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
187 extern char *get_formated_gmt_time( void );
189 enum hudinstype{ HUDno_instr,
201 typedef struct gltagRGBTRIPLE { // rgbt
209 GLfloat x0, y0, x1, y1;
212 fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
213 : x0(a), y0(b), x1(c), y1(d) {}
215 fgLineSeg2D( const fgLineSeg2D & image )
216 : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
218 fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
219 x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
231 #define USE_HUD_TextList
232 extern float HUD_TextSize;
233 extern fntRenderer *HUDtext;
234 extern float HUD_matrix[16];
241 fgText( float x = 0, float y = 0, char *c = NULL )
242 : x(x), y(y) {strncpy(msg,c,64-1);}
244 fgText( const fgText & image )
245 : x(image.x), y(image.y) {strcpy(msg,image.msg);}
247 fgText& operator = ( const fgText & image ) {
248 strcpy(msg,image.msg); x = image.x; y = image.y;
252 ~fgText() {msg[0]='\0';}
254 int getStringWidth ( char *str )
256 if ( HUDtext && str )
259 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
260 return FloatToInt( r - l );
265 int StringWidth (void )
267 if ( HUDtext && strlen( msg ))
270 guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
271 return FloatToInt( r - l );
276 void Draw(fntRenderer *fnt)
278 fnt->start2f( x, y );
284 puDrawString ( guiFnt, msg, FloatToInt(x), FloatToInt(y) );
289 vector < fgLineSeg2D > List;
291 fgLineList( void ) {}
292 ~fgLineList( void ) {}
293 void add( fgLineSeg2D seg ) { List.push_back(seg); }
294 void erase( void ) { List.erase( List.begin(), List.end() ); }
296 vector < fgLineSeg2D > :: iterator curSeg;
297 vector < fgLineSeg2D > :: iterator lastSeg;
298 curSeg = List.begin();
299 lastSeg = List.end();
301 for ( ; curSeg != lastSeg; curSeg++ ) {
310 vector< fgText > List;
312 fgTextList ( void ) { Font = 0; }
313 ~fgTextList( void ) {}
315 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
316 void add( fgText String ) { List.push_back(String); }
317 void erase( void ) { List.erase( List.begin(), List.end() ); }
320 vector < fgText > :: iterator curString;
321 vector < fgText > :: iterator lastString;
322 if( Font == 0 ) return;
323 curString = List.begin();
324 lastString = List.end();
325 glPushAttrib( GL_COLOR_BUFFER_BIT );
326 glEnable ( GL_ALPHA_TEST ) ;
327 glEnable ( GL_BLEND ) ;
328 glAlphaFunc ( GL_GREATER, 0.1 ) ;
329 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
332 for( ; curString != lastString; curString++ ) {
333 curString->Draw(Font);
337 glDisable ( GL_TEXTURE_2D ) ;
343 inline void Text( fgTextList &List, float x, float y, char *s)
345 List.add( fgText( x, y, s) );
348 inline void Text( fgTextList &List, fgText &me)
353 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
355 List.add(fgLineSeg2D(x1,y1,x2,y2));
359 // Declare our externals
360 extern fgTextList HUD_TextList;
361 extern fgLineList HUD_LineList;
362 extern fgLineList HUD_StippleLineList;
365 class instr_item { // An Abstract Base Class (ABC)
367 static UINT instances; // More than 64K instruments? Nah!
368 static int brightness;
369 static glRGBTRIPLE color;
372 RECT scrn_pos; // Framing - affects scale dimensions
373 // and orientation. Vert vs Horz, etc.
374 FLTFNPTR load_value_fn;
375 float disp_factor; // Multiply by to get numbers shown on scale.
379 UINT scr_span; // Working values for draw;
387 FLTFNPTR data_source,
390 bool working = true);
392 instr_item( const instr_item & image );
394 instr_item & operator = ( const instr_item & rhs );
395 virtual ~instr_item ();
397 int get_brightness ( void ) { return brightness;}
398 RECT get_location ( void ) { return scrn_pos; }
399 bool is_broken ( void ) { return broken; }
400 bool enabled ( void ) { return is_enabled;}
401 bool data_available ( void ) { return !!load_value_fn; }
402 float get_value ( void ) { return load_value_fn(); }
403 float data_scaling ( void ) { return disp_factor; }
404 UINT get_span ( void ) { return scr_span; }
405 POINT get_centroid ( void ) { return mid_span; }
406 UINT get_options ( void ) { return opts; }
408 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
409 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
410 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
411 UINT huds_both (UINT options) { return( (options & HUDS_BOTH) == HUDS_BOTH ); }
412 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
413 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
414 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
415 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
417 virtual void display_enable( bool working ) { is_enabled = !! working;}
419 virtual void update( void );
420 virtual void break_display ( bool bad );
421 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
422 void SetPosition ( int x, int y, UINT width, UINT height );
423 UINT get_Handle( void );
424 virtual void draw( void ) = 0; // Required method in derived classes
426 void drawOneLine( float x1, float y1, float x2, float y2)
428 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
430 void drawOneStippleLine( float x1, float y1, float x2, float y2)
432 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
434 void TextString( char *msg, float x, float y )
436 HUD_TextList.add(fgText(x, y, msg));
438 int getStringWidth ( char *str )
440 if ( HUDtext && str )
443 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
444 return FloatToInt( r - l );
451 typedef instr_item *HIptr;
452 //typedef deque < instr_item * > hud_deque_type;
453 //typedef hud_deque_type::iterator hud_deque_iterator;
454 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
456 extern deque< instr_item *> HUD_deque;
457 extern int HUD_style;
458 //extern hud_deque_type HUD_deque;
460 // instr_item This class has no other purpose than to maintain
461 // a linked list of instrument and derived class
465 class instr_label : public instr_item {
469 const char *post_str;
473 char format_buffer[80];
480 FLTFNPTR data_source,
481 const char *label_format,
482 const char *pre_label_string = 0,
483 const char *post_label_string = 0,
484 float scale_data = 1.0,
485 UINT options = HUDS_TOP,
486 fgLabelJust justification = CENTER_JUST,
487 int font_size = SMALL,
488 int blinking = NOBLINK,
489 bool working = true);
493 instr_label( const instr_label & image);
494 instr_label & operator = (const instr_label & rhs );
495 virtual void draw( void ); // Required method in base class
498 typedef instr_label * pInstlabel;
501 class lat_label : public instr_item {
505 const char *post_str;
509 char format_buffer[80];
516 FLTFNPTR data_source,
517 const char *label_format,
518 const char *pre_label_string = 0,
519 const char *post_label_string = 0,
520 float scale_data = 1.0,
521 UINT options = HUDS_TOP,
522 fgLabelJust justification = CENTER_JUST,
523 int font_size = SMALL,
524 int blinking = NOBLINK,
525 bool working = true);
529 lat_label( const lat_label & image);
530 lat_label & operator = (const lat_label & rhs );
531 virtual void draw( void ); // Required method in base class
534 typedef lat_label * pLatlabel;
536 class lon_label : public instr_item {
540 const char *post_str;
544 char format_buffer[80];
551 FLTFNPTR data_source,
552 const char *label_format,
553 const char *pre_label_string = 0,
554 const char *post_label_string = 0,
555 float scale_data = 1.0,
556 UINT options = HUDS_TOP,
557 fgLabelJust justification = CENTER_JUST,
558 int font_size = SMALL,
559 int blinking = NOBLINK,
560 bool working = true);
564 lon_label( const lon_label & image);
565 lon_label & operator = (const lon_label & rhs );
566 virtual void draw( void ); // Required method in base class
569 typedef lon_label * pLonlabel;
572 // instr_scale This class is an abstract base class for both moving
573 // scale and moving needle (fixed scale) indicators. It
574 // does not draw itself, but is not instanciable.
577 class instr_scale : public instr_item {
579 float range_shown; // Width Units.
580 float Maximum_value; // ceiling.
581 float Minimum_value; // Representation floor.
582 float scale_factor; // factor => screen units/range values.
583 UINT Maj_div; // major division marker units
584 UINT Min_div; // minor division marker units
585 UINT Modulo; // Roll over point
586 int signif_digits; // digits to show to the right.
596 float max_value = 100.0,
597 float min_value = 0.0,
598 float disp_scaling = 1.0,
599 UINT major_divs = 10,
603 bool working = true);
605 virtual ~instr_scale();
606 instr_scale( const instr_scale & image);
607 instr_scale & operator = (const instr_scale & rhs);
609 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
610 UINT div_min ( void ) { return Min_div;}
611 UINT div_max ( void ) { return Maj_div;}
612 float min_val ( void ) { return Minimum_value;}
613 float max_val ( void ) { return Maximum_value;}
614 UINT modulo ( void ) { return Modulo; }
615 float factor ( void ) { return scale_factor;}
616 float range_to_show( void ) { return range_shown;}
619 // hud_card_ This class displays the indicated quantity on
620 // a scale that moves past the pointer. It may be
621 // horizontal or vertical, read above(left) or below(right) of the base
624 class hud_card : public instr_scale {
627 float half_width_units;
636 float maxValue = 100.0,
637 float minValue = 0.0,
638 float disp_scaling = 1.0,
639 UINT major_divs = 10,
641 UINT modulator = 100,
643 float value_span = 100.0,
644 bool working = true);
647 hud_card( const hud_card & image);
648 hud_card & operator = (const hud_card & rhs );
649 // virtual void display_enable( bool setting );
650 virtual void draw( void ); // Required method in base class
653 typedef hud_card * pCardScale;
655 class guage_instr : public instr_scale {
663 float disp_scaling = 1.0,
664 float maxValue = 100,
666 UINT major_divs = 50,
670 bool working = true);
673 guage_instr( const guage_instr & image);
674 guage_instr & operator = (const guage_instr & rhs );
675 virtual void draw( void ); // Required method in base class
678 typedef guage_instr * pGuageInst;
680 // dual_instr_item This class was created to form the base class
681 // for both panel and HUD Turn Bank Indicators.
683 class dual_instr_item : public instr_item {
685 FLTFNPTR alt_data_source;
688 dual_instr_item ( int x,
692 FLTFNPTR chn1_source,
693 FLTFNPTR chn2_source,
695 UINT options = HUDS_TOP);
697 virtual ~dual_instr_item() {};
698 dual_instr_item( const dual_instr_item & image);
699 dual_instr_item & operator = (const dual_instr_item & rhs );
701 float current_ch1( void ) { return (float)alt_data_source();}
702 float current_ch2( void ) { return (float)get_value();}
703 virtual void draw ( void ) { }
706 class fgTBI_instr : public dual_instr_item {
717 FLTFNPTR chn1_source = get_roll,
718 FLTFNPTR chn2_source = get_sideslip,
719 float maxBankAngle = 45.0,
720 float maxSlipAngle = 5.0,
722 bool working = true);
724 fgTBI_instr( const fgTBI_instr & image);
725 fgTBI_instr & operator = (const fgTBI_instr & rhs );
729 UINT bank_limit( void ) { return BankLimit;}
730 UINT slew_limit( void ) { return SlewLimit;}
732 virtual void draw( void ); // Required method in base class
735 typedef fgTBI_instr * pTBI;
737 class HudLadder : public dual_instr_item {
750 fgLineList StippleLineList;
757 FLTFNPTR ptch_source = get_roll,
758 FLTFNPTR roll_source = get_pitch,
759 float span_units = 45.0,
760 float division_units = 10.0,
761 float minor_division = 0.0,
762 UINT screen_hole = 70,
764 bool working = true );
768 HudLadder( const HudLadder & image );
769 HudLadder & operator = ( const HudLadder & rhs );
770 virtual void draw( void );
772 void Text( float x, float y, char *s)
774 TextList.add( fgText( x, y, s) );
777 void Line( float x1, float y1, float x2, float y2)
779 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
782 void StippleLine( float x1, float y1, float x2, float y2)
784 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
789 //using namespace std;
790 //deque <instr_item> * Hdeque_ptr;
792 extern void HUD_brightkey( bool incr_bright );
793 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
794 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
795 extern void fgUpdateHUD( void );
797 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
798 extern void drawOneLine ( RECT &rect);
799 extern void textString ( int x,
802 void *font = GLUT_BITMAP_8_BY_13);
803 extern void strokeString( int x,
806 void *font = GLUT_STROKE_ROMAN,
808 //extern void strokeString(float xx,
811 // void *font = GLUT_STROKE_ROMAN)
814 bool AddHUDInstrument( instr_item *pBlackBox );
815 void DrawHUD ( void );
816 bool DamageInstrument( INSTR_HANDLE unit );
817 bool RepairInstrument( INSTR_HANDLE unit );
820 void fgUpdateHUD ( Hptr hud );
821 void fgUpdateHUD2( Hptr hud ); // Future use?
822 void fgHUDSetTimeMode( Hptr hud, int time_of_day );