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>
67 int top, bottom, left, right;
71 // View mode definitions
73 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
75 // DAY, NIGHT and brightness levels need to be visible where dialogs and
76 // controls can be used to set intensity and appropriate color. This will
78 // Hud general constants
95 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
100 #define UPPER_CENTER 3
101 #define UPPER_RIGHT 4
102 #define CENTER_RIGHT 5
103 #define LOWER_RIGHT 6
104 #define LOWER_CENTER 7
106 #define CENTER_LEFT 9
107 #define SOLID_LINES 10
108 #define DASHED_LINES 11
109 #define DASHED_NEG_LINES 12
112 #define HORIZON_FIXED 1
113 #define HORIZON_MOVING 2
114 #define LABEL_COUNTER 1
115 #define LABEL_WARNING 2
117 #define HUDS_AUTOTICKS 0x0001
118 #define HUDS_VERT 0x0002
119 #define HUDS_HORZ 0x0000
120 #define HUDS_TOP 0x0004
121 #define HUDS_BOTTOM 0x0008
122 #define HUDS_LEFT HUDS_TOP
123 #define HUDS_RIGHT HUDS_BOTTOM
124 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
125 #define HUDS_NOTICKS 0x0010
126 #define HUDS_ARITHTIC 0x0020
127 #define HUDS_DECITICS 0x0040
128 #define HUDS_NOTEXT 0x0080
131 // #define HUD_VERTICAL 1
132 // #define HUD_HORIZONTAL 2
133 // #define HUD_FREEFLOAT 3
135 // Ladder orientation modes
136 // #define HUD_LEFT 1
137 // #define HUD_RIGHT 2
139 // #define HUD_BOTTOM 2
140 // #define HUD_V_LEFT 1
141 // #define HUD_V_RIGHT 2
142 // #define HUD_H_TOP 1
143 // #define HUD_H_BOTTOM 2
148 // #define HUD_NOLIM 2
149 // #define HUD_CIRC 3
151 // #define HUD_INSTR_LADDER 1
152 // #define HUD_INSTR_CLADDER 2
153 // #define HUD_INSTR_HORIZON 3
154 // #define HUD_INSTR_LABEL 4
157 extern float get_throttleval ( void );
158 extern float get_aileronval ( void );
159 extern float get_elevatorval ( void );
160 extern float get_elev_trimval( void );
161 extern float get_rudderval ( void );
162 extern float get_speed ( void );
163 extern float get_aoa ( void );
164 extern float get_roll ( void );
165 extern float get_pitch ( void );
166 extern float get_heading ( void );
167 extern float get_view_direction( void );
168 extern float get_altitude ( void );
169 extern float get_agl ( void );
170 extern float get_sideslip ( void );
171 extern float get_frame_rate ( void );
172 extern float get_latitude ( void );
173 extern float get_lat_min ( void );
174 extern float get_longitude ( void );
175 extern float get_long_min ( void );
176 extern float get_fov ( void );
177 extern float get_vfc_ratio ( void );
178 extern float get_vfc_tris_drawn ( void );
179 extern float get_vfc_tris_culled ( void );
180 extern float get_climb_rate ( void );
181 extern char *coord_format_lat(float);
182 extern char *coord_format_lon(float);
183 //extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
185 extern char *get_formated_gmt_time( void );
187 enum hudinstype{ HUDno_instr,
199 typedef struct gltagRGBTRIPLE { // rgbt
207 GLfloat x0, y0, x1, y1;
210 fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
211 : x0(a), y0(b), x1(c), y1(d) {}
213 fgLineSeg2D( const fgLineSeg2D & image )
214 : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
216 fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
217 x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
229 #define USE_HUD_TextList
230 extern float HUD_TextSize;
231 extern fntRenderer *HUDtext;
232 extern float HUD_matrix[16];
239 fgText( char *c = NULL, float x = 0, float y =0 )
240 : x(x), y(y) {strncpy(msg,c,32-1);}
242 fgText( float x = 0, float y = 0, char *c = NULL )
243 : x(x), y(y) {strncpy(msg,c,32-1);}
245 fgText( const fgText & image )
246 : x(image.x), y(image.y) {strcpy(msg,image.msg);}
248 fgText& operator = ( const fgText & image ) {
249 strcpy(msg,image.msg); x = image.x; y = image.y;
253 ~fgText() {msg[0]='\0';}
255 int getStringWidth ( char *str )
257 if ( HUDtext && str )
260 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
261 return FloatToInt( r - l );
266 int StringWidth (void )
268 if ( HUDtext && strlen( msg ))
271 guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
272 return FloatToInt( r - l );
277 void Draw(fntRenderer *fnt)
279 fnt->start2f( x, y );
285 puDrawString ( guiFnt, msg, FloatToInt(x), FloatToInt(y) );
290 vector < fgLineSeg2D > List;
292 fgLineList( void ) {}
293 ~fgLineList( void ) {}
294 void add( fgLineSeg2D seg ) { List.push_back(seg); }
295 void erase( void ) { List.erase( List.begin(), List.end() ); }
297 vector < fgLineSeg2D > :: iterator curSeg;
298 vector < fgLineSeg2D > :: iterator lastSeg;
299 curSeg = List.begin();
300 lastSeg = List.end();
302 for ( ; curSeg != lastSeg; curSeg++ ) {
311 vector< fgText > List;
313 fgTextList ( void ) { Font = 0; }
314 ~fgTextList( void ) {}
316 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
317 void add( fgText String ) { List.push_back(String); }
318 void erase( void ) { List.erase( List.begin(), List.end() ); }
321 vector < fgText > :: iterator curString;
322 vector < fgText > :: iterator lastString;
323 if( Font == 0 ) return;
324 curString = List.begin();
325 lastString = List.end();
326 glPushAttrib( GL_COLOR_BUFFER_BIT );
327 glEnable ( GL_ALPHA_TEST ) ;
328 glEnable ( GL_BLEND ) ;
329 glAlphaFunc ( GL_GREATER, 0.1 ) ;
330 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
333 for( ; curString != lastString; curString++ ) {
334 curString->Draw(Font);
338 glDisable ( GL_TEXTURE_2D ) ;
344 inline void Text( fgTextList &List, float x, float y, char *s)
346 List.add( fgText( x, y, s) );
349 inline void Text( fgTextList &List, fgText &me)
354 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
356 List.add(fgLineSeg2D(x1,y1,x2,y2));
360 // Declare our externals
361 extern fgTextList HUD_TextList;
362 extern fgLineList HUD_LineList;
363 extern fgLineList HUD_StippleLineList;
366 class instr_item { // An Abstract Base Class (ABC)
368 static UINT instances; // More than 64K instruments? Nah!
369 static int brightness;
370 static glRGBTRIPLE color;
373 RECT scrn_pos; // Framing - affects scale dimensions
374 // and orientation. Vert vs Horz, etc.
375 FLTFNPTR load_value_fn;
376 float disp_factor; // Multiply by to get numbers shown on scale.
380 UINT scr_span; // Working values for draw;
388 FLTFNPTR data_source,
391 bool working = true);
393 instr_item( const instr_item & image );
395 instr_item & operator = ( const instr_item & rhs );
396 virtual ~instr_item ();
398 int get_brightness ( void ) { return brightness;}
399 RECT get_location ( void ) { return scrn_pos; }
400 bool is_broken ( void ) { return broken; }
401 bool enabled ( void ) { return is_enabled;}
402 bool data_available ( void ) { return !!load_value_fn; }
403 float get_value ( void ) { return load_value_fn(); }
404 float data_scaling ( void ) { return disp_factor; }
405 UINT get_span ( void ) { return scr_span; }
406 POINT get_centroid ( void ) { return mid_span; }
407 UINT get_options ( void ) { return opts; }
409 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
410 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
411 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
412 UINT huds_both (UINT options) { return( (options & HUDS_BOTH) == HUDS_BOTH ); }
413 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
414 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
415 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
416 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
418 virtual void display_enable( bool working ) { is_enabled = !! working;}
420 virtual void update( void );
421 virtual void break_display ( bool bad );
422 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
423 void SetPosition ( int x, int y, UINT width, UINT height );
424 UINT get_Handle( void );
425 virtual void draw( void ) = 0; // Required method in derived classes
427 void drawOneLine( float x1, float y1, float x2, float y2)
429 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
431 void drawOneStippleLine( float x1, float y1, float x2, float y2)
433 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
435 void TextString( char *msg, float x, float y )
437 HUD_TextList.add(fgText(msg, x, y));
439 int getStringWidth ( char *str )
441 if ( HUDtext && str )
444 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
445 return FloatToInt( r - l );
452 typedef instr_item *HIptr;
453 //typedef deque < instr_item * > hud_deque_type;
454 //typedef hud_deque_type::iterator hud_deque_iterator;
455 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
457 extern deque< instr_item *> HUD_deque;
458 extern int HUD_style;
459 //extern hud_deque_type HUD_deque;
461 // instr_item This class has no other purpose than to maintain
462 // a linked list of instrument and derived class
466 class instr_label : public instr_item {
470 const char *post_str;
474 char format_buffer[80];
481 FLTFNPTR data_source,
482 const char *label_format,
483 const char *pre_label_string = 0,
484 const char *post_label_string = 0,
485 float scale_data = 1.0,
486 UINT options = HUDS_TOP,
487 fgLabelJust justification = CENTER_JUST,
488 int font_size = SMALL,
489 int blinking = NOBLINK,
490 bool working = true);
494 instr_label( const instr_label & image);
495 instr_label & operator = (const instr_label & rhs );
496 virtual void draw( void ); // Required method in base class
499 typedef instr_label * pInstlabel;
502 class lat_label : public instr_item {
506 const char *post_str;
510 char format_buffer[80];
517 FLTFNPTR data_source,
518 const char *label_format,
519 const char *pre_label_string = 0,
520 const char *post_label_string = 0,
521 float scale_data = 1.0,
522 UINT options = HUDS_TOP,
523 fgLabelJust justification = CENTER_JUST,
524 int font_size = SMALL,
525 int blinking = NOBLINK,
526 bool working = true);
530 lat_label( const lat_label & image);
531 lat_label & operator = (const lat_label & rhs );
532 virtual void draw( void ); // Required method in base class
535 typedef lat_label * pLatlabel;
537 class lon_label : public instr_item {
541 const char *post_str;
545 char format_buffer[80];
552 FLTFNPTR data_source,
553 const char *label_format,
554 const char *pre_label_string = 0,
555 const char *post_label_string = 0,
556 float scale_data = 1.0,
557 UINT options = HUDS_TOP,
558 fgLabelJust justification = CENTER_JUST,
559 int font_size = SMALL,
560 int blinking = NOBLINK,
561 bool working = true);
565 lon_label( const lon_label & image);
566 lon_label & operator = (const lon_label & rhs );
567 virtual void draw( void ); // Required method in base class
570 typedef lon_label * pLonlabel;
573 // instr_scale This class is an abstract base class for both moving
574 // scale and moving needle (fixed scale) indicators. It
575 // does not draw itself, but is not instanciable.
578 class instr_scale : public instr_item {
580 float range_shown; // Width Units.
581 float Maximum_value; // ceiling.
582 float Minimum_value; // Representation floor.
583 float scale_factor; // factor => screen units/range values.
584 UINT Maj_div; // major division marker units
585 UINT Min_div; // minor division marker units
586 UINT Modulo; // Roll over point
587 int signif_digits; // digits to show to the right.
597 float max_value = 100.0,
598 float min_value = 0.0,
599 float disp_scaling = 1.0,
600 UINT major_divs = 10,
604 bool working = true);
606 virtual ~instr_scale();
607 instr_scale( const instr_scale & image);
608 instr_scale & operator = (const instr_scale & rhs);
610 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
611 UINT div_min ( void ) { return Min_div;}
612 UINT div_max ( void ) { return Maj_div;}
613 float min_val ( void ) { return Minimum_value;}
614 float max_val ( void ) { return Maximum_value;}
615 UINT modulo ( void ) { return Modulo; }
616 float factor ( void ) { return scale_factor;}
617 float range_to_show( void ) { return range_shown;}
620 // hud_card_ This class displays the indicated quantity on
621 // a scale that moves past the pointer. It may be
622 // horizontal or vertical, read above(left) or below(right) of the base
625 class hud_card : public instr_scale {
628 float half_width_units;
637 float maxValue = 100.0,
638 float minValue = 0.0,
639 float disp_scaling = 1.0,
640 UINT major_divs = 10,
642 UINT modulator = 100,
644 float value_span = 100.0,
645 bool working = true);
648 hud_card( const hud_card & image);
649 hud_card & operator = (const hud_card & rhs );
650 // virtual void display_enable( bool setting );
651 virtual void draw( void ); // Required method in base class
654 typedef hud_card * pCardScale;
656 class guage_instr : public instr_scale {
664 float disp_scaling = 1.0,
665 float maxValue = 100,
667 UINT major_divs = 50,
671 bool working = true);
674 guage_instr( const guage_instr & image);
675 guage_instr & operator = (const guage_instr & rhs );
676 virtual void draw( void ); // Required method in base class
679 typedef guage_instr * pGuageInst;
681 // dual_instr_item This class was created to form the base class
682 // for both panel and HUD Turn Bank Indicators.
684 class dual_instr_item : public instr_item {
686 FLTFNPTR alt_data_source;
689 dual_instr_item ( int x,
693 FLTFNPTR chn1_source,
694 FLTFNPTR chn2_source,
696 UINT options = HUDS_TOP);
698 virtual ~dual_instr_item() {};
699 dual_instr_item( const dual_instr_item & image);
700 dual_instr_item & operator = (const dual_instr_item & rhs );
702 float current_ch1( void ) { return (float)alt_data_source();}
703 float current_ch2( void ) { return (float)get_value();}
704 virtual void draw ( void ) { }
707 class fgTBI_instr : public dual_instr_item {
718 FLTFNPTR chn1_source = get_roll,
719 FLTFNPTR chn2_source = get_sideslip,
720 float maxBankAngle = 45.0,
721 float maxSlipAngle = 5.0,
723 bool working = true);
725 fgTBI_instr( const fgTBI_instr & image);
726 fgTBI_instr & operator = (const fgTBI_instr & rhs );
730 UINT bank_limit( void ) { return BankLimit;}
731 UINT slew_limit( void ) { return SlewLimit;}
733 virtual void draw( void ); // Required method in base class
736 typedef fgTBI_instr * pTBI;
738 class HudLadder : public dual_instr_item {
751 fgLineList StippleLineList;
758 FLTFNPTR ptch_source = get_roll,
759 FLTFNPTR roll_source = get_pitch,
760 float span_units = 45.0,
761 float division_units = 10.0,
762 float minor_division = 0.0,
763 UINT screen_hole = 70,
765 bool working = true );
769 HudLadder( const HudLadder & image );
770 HudLadder & operator = ( const HudLadder & rhs );
771 virtual void draw( void );
773 void Text( float x, float y, char *s)
775 TextList.add( fgText( x, y, s) );
778 void Line( float x1, float y1, float x2, float y2)
780 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
783 void StippleLine( float x1, float y1, float x2, float y2)
785 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
790 //using namespace std;
791 //deque <instr_item> * Hdeque_ptr;
793 extern void HUD_brightkey( bool incr_bright );
794 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
795 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
796 extern void fgUpdateHUD( void );
798 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
799 extern void drawOneLine ( RECT &rect);
800 extern void textString ( int x,
803 void *font = GLUT_BITMAP_8_BY_13);
804 extern void strokeString( int x,
807 void *font = GLUT_STROKE_ROMAN,
809 //extern void strokeString(float xx,
812 // void *font = GLUT_STROKE_ROMAN)
815 bool AddHUDInstrument( instr_item *pBlackBox );
816 void DrawHUD ( void );
817 bool DamageInstrument( INSTR_HANDLE unit );
818 bool RepairInstrument( INSTR_HANDLE unit );
821 void fgUpdateHUD ( Hptr hud );
822 void fgUpdateHUD2( Hptr hud ); // Future use?
823 void fgHUDSetTimeMode( Hptr hud, int time_of_day );