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);
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
120 #define HUDS_HORZ 0x0000
121 #define HUDS_TOP 0x0004
122 #define HUDS_BOTTOM 0x0008
123 #define HUDS_LEFT HUDS_TOP
124 #define HUDS_RIGHT HUDS_BOTTOM
125 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
126 #define HUDS_NOTICKS 0x0010
127 #define HUDS_ARITHTIC 0x0020
128 #define HUDS_DECITICS 0x0040
129 #define HUDS_NOTEXT 0x0080
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
158 extern float get_throttleval ( void );
159 extern float get_aileronval ( void );
160 extern float get_elevatorval ( void );
161 extern float get_elev_trimval( void );
162 extern float get_rudderval ( void );
163 extern float get_speed ( void );
164 extern float get_aoa ( void );
165 extern float get_roll ( void );
166 extern float get_pitch ( void );
167 extern float get_heading ( void );
168 extern float get_view_direction( void );
169 extern float get_altitude ( void );
170 extern float get_agl ( void );
171 extern float get_sideslip ( void );
172 extern float get_frame_rate ( void );
173 extern float get_latitude ( void );
174 extern float get_lat_min ( void );
175 extern float get_longitude ( void );
176 extern float get_long_min ( void );
177 extern float get_fov ( void );
178 extern float get_vfc_ratio ( void );
179 extern float get_vfc_tris_drawn ( void );
180 extern float get_vfc_tris_culled ( void );
181 extern float get_climb_rate ( void );
182 extern char *coord_format_lat(float);
183 extern char *coord_format_lon(float);
184 //extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
186 extern char *get_formated_gmt_time( void );
188 enum hudinstype{ HUDno_instr,
200 typedef struct gltagRGBTRIPLE { // rgbt
208 GLfloat x0, y0, x1, y1;
211 fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
212 : x0(a), y0(b), x1(c), y1(d) {}
214 fgLineSeg2D( const fgLineSeg2D & image )
215 : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
217 fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
218 x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
230 #define USE_HUD_TextList
231 extern float HUD_TextSize;
232 extern fntRenderer *HUDtext;
233 extern float HUD_matrix[16];
240 fgText( float x = 0, float y = 0, char *c = NULL )
241 : x(x), y(y) {strncpy(msg,c,32-1);}
243 fgText( const fgText & image )
244 : x(image.x), y(image.y) {strcpy(msg,image.msg);}
246 fgText& operator = ( const fgText & image ) {
247 strcpy(msg,image.msg); x = image.x; y = image.y;
251 ~fgText() {msg[0]='\0';}
253 int getStringWidth ( char *str )
255 if ( HUDtext && str )
258 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
259 return FloatToInt( r - l );
264 int StringWidth (void )
266 if ( HUDtext && strlen( msg ))
269 guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
270 return FloatToInt( r - l );
275 void Draw(fntRenderer *fnt)
277 fnt->start2f( x, y );
283 puDrawString ( guiFnt, msg, FloatToInt(x), FloatToInt(y) );
288 vector < fgLineSeg2D > List;
290 fgLineList( void ) {}
291 ~fgLineList( void ) {}
292 void add( fgLineSeg2D seg ) { List.push_back(seg); }
293 void erase( void ) { List.erase( List.begin(), List.end() ); }
295 vector < fgLineSeg2D > :: iterator curSeg;
296 vector < fgLineSeg2D > :: iterator lastSeg;
297 curSeg = List.begin();
298 lastSeg = List.end();
300 for ( ; curSeg != lastSeg; curSeg++ ) {
309 vector< fgText > List;
311 fgTextList ( void ) { Font = 0; }
312 ~fgTextList( void ) {}
314 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
315 void add( fgText String ) { List.push_back(String); }
316 void erase( void ) { List.erase( List.begin(), List.end() ); }
319 vector < fgText > :: iterator curString;
320 vector < fgText > :: iterator lastString;
321 if( Font == 0 ) return;
322 curString = List.begin();
323 lastString = List.end();
324 glPushAttrib( GL_COLOR_BUFFER_BIT );
325 glEnable ( GL_ALPHA_TEST ) ;
326 glEnable ( GL_BLEND ) ;
327 glAlphaFunc ( GL_GREATER, 0.1 ) ;
328 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
331 for( ; curString != lastString; curString++ ) {
332 curString->Draw(Font);
336 glDisable ( GL_TEXTURE_2D ) ;
342 inline void Text( fgTextList &List, float x, float y, char *s)
344 List.add( fgText( x, y, s) );
347 inline void Text( fgTextList &List, fgText &me)
352 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
354 List.add(fgLineSeg2D(x1,y1,x2,y2));
358 // Declare our externals
359 extern fgTextList HUD_TextList;
360 extern fgLineList HUD_LineList;
361 extern fgLineList HUD_StippleLineList;
364 class instr_item { // An Abstract Base Class (ABC)
366 static UINT instances; // More than 64K instruments? Nah!
367 static int brightness;
368 static glRGBTRIPLE color;
371 RECT scrn_pos; // Framing - affects scale dimensions
372 // and orientation. Vert vs Horz, etc.
373 FLTFNPTR load_value_fn;
374 float disp_factor; // Multiply by to get numbers shown on scale.
378 UINT scr_span; // Working values for draw;
386 FLTFNPTR data_source,
389 bool working = true);
391 instr_item( const instr_item & image );
393 instr_item & operator = ( const instr_item & rhs );
394 virtual ~instr_item ();
396 int get_brightness ( void ) { return brightness;}
397 RECT get_location ( void ) { return scrn_pos; }
398 bool is_broken ( void ) { return broken; }
399 bool enabled ( void ) { return is_enabled;}
400 bool data_available ( void ) { return !!load_value_fn; }
401 float get_value ( void ) { return load_value_fn(); }
402 float data_scaling ( void ) { return disp_factor; }
403 UINT get_span ( void ) { return scr_span; }
404 POINT get_centroid ( void ) { return mid_span; }
405 UINT get_options ( void ) { return opts; }
407 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
408 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
409 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
410 UINT huds_both (UINT options) { return( (options & HUDS_BOTH) == HUDS_BOTH ); }
411 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
412 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
413 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
414 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
416 virtual void display_enable( bool working ) { is_enabled = !! working;}
418 virtual void update( void );
419 virtual void break_display ( bool bad );
420 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
421 void SetPosition ( int x, int y, UINT width, UINT height );
422 UINT get_Handle( void );
423 virtual void draw( void ) = 0; // Required method in derived classes
425 void drawOneLine( float x1, float y1, float x2, float y2)
427 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
429 void drawOneStippleLine( float x1, float y1, float x2, float y2)
431 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
433 void TextString( char *msg, float x, float y )
435 HUD_TextList.add(fgText(x, y, msg));
437 int getStringWidth ( char *str )
439 if ( HUDtext && str )
442 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
443 return FloatToInt( r - l );
450 typedef instr_item *HIptr;
451 //typedef deque < instr_item * > hud_deque_type;
452 //typedef hud_deque_type::iterator hud_deque_iterator;
453 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
455 extern deque< instr_item *> HUD_deque;
456 extern int HUD_style;
457 //extern hud_deque_type HUD_deque;
459 // instr_item This class has no other purpose than to maintain
460 // a linked list of instrument and derived class
464 class instr_label : public instr_item {
468 const char *post_str;
472 char format_buffer[80];
479 FLTFNPTR data_source,
480 const char *label_format,
481 const char *pre_label_string = 0,
482 const char *post_label_string = 0,
483 float scale_data = 1.0,
484 UINT options = HUDS_TOP,
485 fgLabelJust justification = CENTER_JUST,
486 int font_size = SMALL,
487 int blinking = NOBLINK,
488 bool working = true);
492 instr_label( const instr_label & image);
493 instr_label & operator = (const instr_label & rhs );
494 virtual void draw( void ); // Required method in base class
497 typedef instr_label * pInstlabel;
500 class lat_label : public instr_item {
504 const char *post_str;
508 char format_buffer[80];
515 FLTFNPTR data_source,
516 const char *label_format,
517 const char *pre_label_string = 0,
518 const char *post_label_string = 0,
519 float scale_data = 1.0,
520 UINT options = HUDS_TOP,
521 fgLabelJust justification = CENTER_JUST,
522 int font_size = SMALL,
523 int blinking = NOBLINK,
524 bool working = true);
528 lat_label( const lat_label & image);
529 lat_label & operator = (const lat_label & rhs );
530 virtual void draw( void ); // Required method in base class
533 typedef lat_label * pLatlabel;
535 class lon_label : public instr_item {
539 const char *post_str;
543 char format_buffer[80];
550 FLTFNPTR data_source,
551 const char *label_format,
552 const char *pre_label_string = 0,
553 const char *post_label_string = 0,
554 float scale_data = 1.0,
555 UINT options = HUDS_TOP,
556 fgLabelJust justification = CENTER_JUST,
557 int font_size = SMALL,
558 int blinking = NOBLINK,
559 bool working = true);
563 lon_label( const lon_label & image);
564 lon_label & operator = (const lon_label & rhs );
565 virtual void draw( void ); // Required method in base class
568 typedef lon_label * pLonlabel;
571 // instr_scale This class is an abstract base class for both moving
572 // scale and moving needle (fixed scale) indicators. It
573 // does not draw itself, but is not instanciable.
576 class instr_scale : public instr_item {
578 float range_shown; // Width Units.
579 float Maximum_value; // ceiling.
580 float Minimum_value; // Representation floor.
581 float scale_factor; // factor => screen units/range values.
582 UINT Maj_div; // major division marker units
583 UINT Min_div; // minor division marker units
584 UINT Modulo; // Roll over point
585 int signif_digits; // digits to show to the right.
595 float max_value = 100.0,
596 float min_value = 0.0,
597 float disp_scaling = 1.0,
598 UINT major_divs = 10,
602 bool working = true);
604 virtual ~instr_scale();
605 instr_scale( const instr_scale & image);
606 instr_scale & operator = (const instr_scale & rhs);
608 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
609 UINT div_min ( void ) { return Min_div;}
610 UINT div_max ( void ) { return Maj_div;}
611 float min_val ( void ) { return Minimum_value;}
612 float max_val ( void ) { return Maximum_value;}
613 UINT modulo ( void ) { return Modulo; }
614 float factor ( void ) { return scale_factor;}
615 float range_to_show( void ) { return range_shown;}
618 // hud_card_ This class displays the indicated quantity on
619 // a scale that moves past the pointer. It may be
620 // horizontal or vertical, read above(left) or below(right) of the base
623 class hud_card : public instr_scale {
626 float half_width_units;
635 float maxValue = 100.0,
636 float minValue = 0.0,
637 float disp_scaling = 1.0,
638 UINT major_divs = 10,
640 UINT modulator = 100,
642 float value_span = 100.0,
643 bool working = true);
646 hud_card( const hud_card & image);
647 hud_card & operator = (const hud_card & rhs );
648 // virtual void display_enable( bool setting );
649 virtual void draw( void ); // Required method in base class
652 typedef hud_card * pCardScale;
654 class guage_instr : public instr_scale {
662 float disp_scaling = 1.0,
663 float maxValue = 100,
665 UINT major_divs = 50,
669 bool working = true);
672 guage_instr( const guage_instr & image);
673 guage_instr & operator = (const guage_instr & rhs );
674 virtual void draw( void ); // Required method in base class
677 typedef guage_instr * pGuageInst;
679 // dual_instr_item This class was created to form the base class
680 // for both panel and HUD Turn Bank Indicators.
682 class dual_instr_item : public instr_item {
684 FLTFNPTR alt_data_source;
687 dual_instr_item ( int x,
691 FLTFNPTR chn1_source,
692 FLTFNPTR chn2_source,
694 UINT options = HUDS_TOP);
696 virtual ~dual_instr_item() {};
697 dual_instr_item( const dual_instr_item & image);
698 dual_instr_item & operator = (const dual_instr_item & rhs );
700 float current_ch1( void ) { return (float)alt_data_source();}
701 float current_ch2( void ) { return (float)get_value();}
702 virtual void draw ( void ) { }
705 class fgTBI_instr : public dual_instr_item {
716 FLTFNPTR chn1_source = get_roll,
717 FLTFNPTR chn2_source = get_sideslip,
718 float maxBankAngle = 45.0,
719 float maxSlipAngle = 5.0,
721 bool working = true);
723 fgTBI_instr( const fgTBI_instr & image);
724 fgTBI_instr & operator = (const fgTBI_instr & rhs );
728 UINT bank_limit( void ) { return BankLimit;}
729 UINT slew_limit( void ) { return SlewLimit;}
731 virtual void draw( void ); // Required method in base class
734 typedef fgTBI_instr * pTBI;
736 class HudLadder : public dual_instr_item {
749 fgLineList StippleLineList;
756 FLTFNPTR ptch_source = get_roll,
757 FLTFNPTR roll_source = get_pitch,
758 float span_units = 45.0,
759 float division_units = 10.0,
760 float minor_division = 0.0,
761 UINT screen_hole = 70,
763 bool working = true );
767 HudLadder( const HudLadder & image );
768 HudLadder & operator = ( const HudLadder & rhs );
769 virtual void draw( void );
771 void Text( float x, float y, char *s)
773 TextList.add( fgText( x, y, s) );
776 void Line( float x1, float y1, float x2, float y2)
778 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
781 void StippleLine( float x1, float y1, float x2, float y2)
783 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
788 //using namespace std;
789 //deque <instr_item> * Hdeque_ptr;
791 extern void HUD_brightkey( bool incr_bright );
792 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
793 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
794 extern void fgUpdateHUD( void );
796 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
797 extern void drawOneLine ( RECT &rect);
798 extern void textString ( int x,
801 void *font = GLUT_BITMAP_8_BY_13);
802 extern void strokeString( int x,
805 void *font = GLUT_STROKE_ROMAN,
807 //extern void strokeString(float xx,
810 // void *font = GLUT_STROKE_ROMAN)
813 bool AddHUDInstrument( instr_item *pBlackBox );
814 void DrawHUD ( void );
815 bool DamageInstrument( INSTR_HANDLE unit );
816 bool RepairInstrument( INSTR_HANDLE unit );
819 void fgUpdateHUD ( Hptr hud );
820 void fgUpdateHUD2( Hptr hud ); // Future use?
821 void fgHUDSetTimeMode( Hptr hud, int time_of_day );