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( float x = 0, float y = 0, char *c = NULL )
240 : x(x), y(y) {strncpy(msg,c,32-1);}
242 fgText( const fgText & image )
243 : x(image.x), y(image.y) {strcpy(msg,image.msg);}
245 fgText& operator = ( const fgText & image ) {
246 strcpy(msg,image.msg); x = image.x; y = image.y;
250 ~fgText() {msg[0]='\0';}
252 int getStringWidth ( char *str )
254 if ( HUDtext && str )
257 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
258 return FloatToInt( r - l );
263 int StringWidth (void )
265 if ( HUDtext && strlen( msg ))
268 guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
269 return FloatToInt( r - l );
274 void Draw(fntRenderer *fnt)
276 fnt->start2f( x, y );
282 puDrawString ( guiFnt, msg, FloatToInt(x), FloatToInt(y) );
287 vector < fgLineSeg2D > List;
289 fgLineList( void ) {}
290 ~fgLineList( void ) {}
291 void add( fgLineSeg2D seg ) { List.push_back(seg); }
292 void erase( void ) { List.erase( List.begin(), List.end() ); }
294 vector < fgLineSeg2D > :: iterator curSeg;
295 vector < fgLineSeg2D > :: iterator lastSeg;
296 curSeg = List.begin();
297 lastSeg = List.end();
299 for ( ; curSeg != lastSeg; curSeg++ ) {
308 vector< fgText > List;
310 fgTextList ( void ) { Font = 0; }
311 ~fgTextList( void ) {}
313 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
314 void add( fgText String ) { List.push_back(String); }
315 void erase( void ) { List.erase( List.begin(), List.end() ); }
318 vector < fgText > :: iterator curString;
319 vector < fgText > :: iterator lastString;
320 if( Font == 0 ) return;
321 curString = List.begin();
322 lastString = List.end();
323 glPushAttrib( GL_COLOR_BUFFER_BIT );
324 glEnable ( GL_ALPHA_TEST ) ;
325 glEnable ( GL_BLEND ) ;
326 glAlphaFunc ( GL_GREATER, 0.1 ) ;
327 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
330 for( ; curString != lastString; curString++ ) {
331 curString->Draw(Font);
335 glDisable ( GL_TEXTURE_2D ) ;
341 inline void Text( fgTextList &List, float x, float y, char *s)
343 List.add( fgText( x, y, s) );
346 inline void Text( fgTextList &List, fgText &me)
351 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
353 List.add(fgLineSeg2D(x1,y1,x2,y2));
357 // Declare our externals
358 extern fgTextList HUD_TextList;
359 extern fgLineList HUD_LineList;
360 extern fgLineList HUD_StippleLineList;
363 class instr_item { // An Abstract Base Class (ABC)
365 static UINT instances; // More than 64K instruments? Nah!
366 static int brightness;
367 static glRGBTRIPLE color;
370 RECT scrn_pos; // Framing - affects scale dimensions
371 // and orientation. Vert vs Horz, etc.
372 FLTFNPTR load_value_fn;
373 float disp_factor; // Multiply by to get numbers shown on scale.
377 UINT scr_span; // Working values for draw;
385 FLTFNPTR data_source,
388 bool working = true);
390 instr_item( const instr_item & image );
392 instr_item & operator = ( const instr_item & rhs );
393 virtual ~instr_item ();
395 int get_brightness ( void ) { return brightness;}
396 RECT get_location ( void ) { return scrn_pos; }
397 bool is_broken ( void ) { return broken; }
398 bool enabled ( void ) { return is_enabled;}
399 bool data_available ( void ) { return !!load_value_fn; }
400 float get_value ( void ) { return load_value_fn(); }
401 float data_scaling ( void ) { return disp_factor; }
402 UINT get_span ( void ) { return scr_span; }
403 POINT get_centroid ( void ) { return mid_span; }
404 UINT get_options ( void ) { return opts; }
406 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
407 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
408 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
409 UINT huds_both (UINT options) { return( (options & HUDS_BOTH) == HUDS_BOTH ); }
410 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
411 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
412 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
413 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
415 virtual void display_enable( bool working ) { is_enabled = !! working;}
417 virtual void update( void );
418 virtual void break_display ( bool bad );
419 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
420 void SetPosition ( int x, int y, UINT width, UINT height );
421 UINT get_Handle( void );
422 virtual void draw( void ) = 0; // Required method in derived classes
424 void drawOneLine( float x1, float y1, float x2, float y2)
426 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
428 void drawOneStippleLine( float x1, float y1, float x2, float y2)
430 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
432 void TextString( char *msg, float x, float y )
434 HUD_TextList.add(fgText(x, y, msg));
436 int getStringWidth ( char *str )
438 if ( HUDtext && str )
441 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
442 return FloatToInt( r - l );
449 typedef instr_item *HIptr;
450 //typedef deque < instr_item * > hud_deque_type;
451 //typedef hud_deque_type::iterator hud_deque_iterator;
452 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
454 extern deque< instr_item *> HUD_deque;
455 extern int HUD_style;
456 //extern hud_deque_type HUD_deque;
458 // instr_item This class has no other purpose than to maintain
459 // a linked list of instrument and derived class
463 class instr_label : public instr_item {
467 const char *post_str;
471 char format_buffer[80];
478 FLTFNPTR data_source,
479 const char *label_format,
480 const char *pre_label_string = 0,
481 const char *post_label_string = 0,
482 float scale_data = 1.0,
483 UINT options = HUDS_TOP,
484 fgLabelJust justification = CENTER_JUST,
485 int font_size = SMALL,
486 int blinking = NOBLINK,
487 bool working = true);
491 instr_label( const instr_label & image);
492 instr_label & operator = (const instr_label & rhs );
493 virtual void draw( void ); // Required method in base class
496 typedef instr_label * pInstlabel;
499 class lat_label : public instr_item {
503 const char *post_str;
507 char format_buffer[80];
514 FLTFNPTR data_source,
515 const char *label_format,
516 const char *pre_label_string = 0,
517 const char *post_label_string = 0,
518 float scale_data = 1.0,
519 UINT options = HUDS_TOP,
520 fgLabelJust justification = CENTER_JUST,
521 int font_size = SMALL,
522 int blinking = NOBLINK,
523 bool working = true);
527 lat_label( const lat_label & image);
528 lat_label & operator = (const lat_label & rhs );
529 virtual void draw( void ); // Required method in base class
532 typedef lat_label * pLatlabel;
534 class lon_label : public instr_item {
538 const char *post_str;
542 char format_buffer[80];
549 FLTFNPTR data_source,
550 const char *label_format,
551 const char *pre_label_string = 0,
552 const char *post_label_string = 0,
553 float scale_data = 1.0,
554 UINT options = HUDS_TOP,
555 fgLabelJust justification = CENTER_JUST,
556 int font_size = SMALL,
557 int blinking = NOBLINK,
558 bool working = true);
562 lon_label( const lon_label & image);
563 lon_label & operator = (const lon_label & rhs );
564 virtual void draw( void ); // Required method in base class
567 typedef lon_label * pLonlabel;
570 // instr_scale This class is an abstract base class for both moving
571 // scale and moving needle (fixed scale) indicators. It
572 // does not draw itself, but is not instanciable.
575 class instr_scale : public instr_item {
577 float range_shown; // Width Units.
578 float Maximum_value; // ceiling.
579 float Minimum_value; // Representation floor.
580 float scale_factor; // factor => screen units/range values.
581 UINT Maj_div; // major division marker units
582 UINT Min_div; // minor division marker units
583 UINT Modulo; // Roll over point
584 int signif_digits; // digits to show to the right.
594 float max_value = 100.0,
595 float min_value = 0.0,
596 float disp_scaling = 1.0,
597 UINT major_divs = 10,
601 bool working = true);
603 virtual ~instr_scale();
604 instr_scale( const instr_scale & image);
605 instr_scale & operator = (const instr_scale & rhs);
607 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
608 UINT div_min ( void ) { return Min_div;}
609 UINT div_max ( void ) { return Maj_div;}
610 float min_val ( void ) { return Minimum_value;}
611 float max_val ( void ) { return Maximum_value;}
612 UINT modulo ( void ) { return Modulo; }
613 float factor ( void ) { return scale_factor;}
614 float range_to_show( void ) { return range_shown;}
617 // hud_card_ This class displays the indicated quantity on
618 // a scale that moves past the pointer. It may be
619 // horizontal or vertical, read above(left) or below(right) of the base
622 class hud_card : public instr_scale {
625 float half_width_units;
634 float maxValue = 100.0,
635 float minValue = 0.0,
636 float disp_scaling = 1.0,
637 UINT major_divs = 10,
639 UINT modulator = 100,
641 float value_span = 100.0,
642 bool working = true);
645 hud_card( const hud_card & image);
646 hud_card & operator = (const hud_card & rhs );
647 // virtual void display_enable( bool setting );
648 virtual void draw( void ); // Required method in base class
651 typedef hud_card * pCardScale;
653 class guage_instr : public instr_scale {
661 float disp_scaling = 1.0,
662 float maxValue = 100,
664 UINT major_divs = 50,
668 bool working = true);
671 guage_instr( const guage_instr & image);
672 guage_instr & operator = (const guage_instr & rhs );
673 virtual void draw( void ); // Required method in base class
676 typedef guage_instr * pGuageInst;
678 // dual_instr_item This class was created to form the base class
679 // for both panel and HUD Turn Bank Indicators.
681 class dual_instr_item : public instr_item {
683 FLTFNPTR alt_data_source;
686 dual_instr_item ( int x,
690 FLTFNPTR chn1_source,
691 FLTFNPTR chn2_source,
693 UINT options = HUDS_TOP);
695 virtual ~dual_instr_item() {};
696 dual_instr_item( const dual_instr_item & image);
697 dual_instr_item & operator = (const dual_instr_item & rhs );
699 float current_ch1( void ) { return (float)alt_data_source();}
700 float current_ch2( void ) { return (float)get_value();}
701 virtual void draw ( void ) { }
704 class fgTBI_instr : public dual_instr_item {
715 FLTFNPTR chn1_source = get_roll,
716 FLTFNPTR chn2_source = get_sideslip,
717 float maxBankAngle = 45.0,
718 float maxSlipAngle = 5.0,
720 bool working = true);
722 fgTBI_instr( const fgTBI_instr & image);
723 fgTBI_instr & operator = (const fgTBI_instr & rhs );
727 UINT bank_limit( void ) { return BankLimit;}
728 UINT slew_limit( void ) { return SlewLimit;}
730 virtual void draw( void ); // Required method in base class
733 typedef fgTBI_instr * pTBI;
735 class HudLadder : public dual_instr_item {
748 fgLineList StippleLineList;
755 FLTFNPTR ptch_source = get_roll,
756 FLTFNPTR roll_source = get_pitch,
757 float span_units = 45.0,
758 float division_units = 10.0,
759 float minor_division = 0.0,
760 UINT screen_hole = 70,
762 bool working = true );
766 HudLadder( const HudLadder & image );
767 HudLadder & operator = ( const HudLadder & rhs );
768 virtual void draw( void );
770 void Text( float x, float y, char *s)
772 TextList.add( fgText( x, y, s) );
775 void Line( float x1, float y1, float x2, float y2)
777 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
780 void StippleLine( float x1, float y1, float x2, float y2)
782 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
787 //using namespace std;
788 //deque <instr_item> * Hdeque_ptr;
790 extern void HUD_brightkey( bool incr_bright );
791 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
792 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
793 extern void fgUpdateHUD( void );
795 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
796 extern void drawOneLine ( RECT &rect);
797 extern void textString ( int x,
800 void *font = GLUT_BITMAP_8_BY_13);
801 extern void strokeString( int x,
804 void *font = GLUT_STROKE_ROMAN,
806 //extern void strokeString(float xx,
809 // void *font = GLUT_STROKE_ROMAN)
812 bool AddHUDInstrument( instr_item *pBlackBox );
813 void DrawHUD ( void );
814 bool DamageInstrument( INSTR_HANDLE unit );
815 bool RepairInstrument( INSTR_HANDLE unit );
818 void fgUpdateHUD ( Hptr hud );
819 void fgUpdateHUD2( Hptr hud ); // Future use?
820 void fgHUDSetTimeMode( Hptr hud, int time_of_day );