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++
31 #include <simgear/compiler.h>
45 //#ifdef HAVE_VALUES_H
46 //# include <values.h> // for MAXINT
49 #include <vector> // STL vector
50 #include <deque> // STL double ended queue
53 #include <simgear/constants.h>
55 #include <Include/fg_typedefs.h>
56 #include <Aircraft/aircraft.hxx>
57 #include <FDM/flight.hxx>
58 #include <Controls/controls.hxx>
60 #include <Main/globals.hxx>
61 #include <Main/viewmgr.hxx>
63 #include "hud_opts.hxx"
67 SG_USING_NAMESPACE(std);
70 // some of Norman's crazy optimizations. :-)
78 int top, bottom, left, right;
82 // View mode definitions
84 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
86 // DAY, NIGHT and brightness levels need to be visible where dialogs and
87 // controls can be used to set intensity and appropriate color. This will
89 // Hud general constants
92 #define HUD_BRT_BLACK 3
93 #define HUD_BRT_DARK 4
94 #define HUD_BRT_MEDIUM 5
95 #define HUD_BRT_LIGHT 6
98 #define HUD_FONT_SMALL 1
99 #define HUD_FONT_LARGE 2
101 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
103 #define HUDS_AUTOTICKS 0x0001
104 #define HUDS_VERT 0x0002
105 #define HUDS_HORZ 0x0000
106 #define HUDS_TOP 0x0004
107 #define HUDS_BOTTOM 0x0008
108 #define HUDS_LEFT HUDS_TOP
109 #define HUDS_RIGHT HUDS_BOTTOM
110 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
111 #define HUDS_NOTICKS 0x0010
112 #define HUDS_ARITHTIC 0x0020
113 #define HUDS_DECITICS 0x0040
114 #define HUDS_NOTEXT 0x0080
117 // #define HUD_VERTICAL 1
118 // #define HUD_HORIZONTAL 2
119 // #define HUD_FREEFLOAT 3
121 // Ladder orientation modes
122 // #define HUD_LEFT 1
123 // #define HUD_RIGHT 2
125 // #define HUD_BOTTOM 2
126 // #define HUD_V_LEFT 1
127 // #define HUD_V_RIGHT 2
128 // #define HUD_H_TOP 1
129 // #define HUD_H_BOTTOM 2
134 // #define HUD_NOLIM 2
135 // #define HUD_CIRC 3
137 // #define HUD_INSTR_LADDER 1
138 // #define HUD_INSTR_CLADDER 2
139 // #define HUD_INSTR_HORIZON 3
140 // #define HUD_INSTR_LABEL 4
143 extern float get_throttleval ( void );
144 extern float get_aileronval ( void );
145 extern float get_elevatorval ( void );
146 extern float get_elev_trimval( void );
147 extern float get_rudderval ( void );
148 extern float get_speed ( void );
149 extern float get_aoa ( void );
150 extern float get_nlf ( void );
151 extern float get_roll ( void );
152 extern float get_pitch ( void );
153 extern float get_heading ( void );
154 extern float get_view_direction( void );
155 extern float get_altitude ( void );
156 extern float get_agl ( void );
157 extern float get_sideslip ( void );
158 extern float get_frame_rate ( void );
159 extern float get_latitude ( void );
160 extern float get_lat_min ( void );
161 extern float get_longitude ( void );
162 extern float get_long_min ( void );
163 extern float get_fov ( void );
164 extern float get_vfc_ratio ( void );
165 extern float get_vfc_tris_drawn ( void );
166 extern float get_vfc_tris_culled ( void );
167 extern float get_climb_rate ( void );
168 extern float get_mach( void );
169 extern char *coord_format_lat(float);
170 extern char *coord_format_lon(float);
171 //extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
173 // $$$ begin - added, VS Renganathan, 13 Oct 2K
174 // #define FIGHTER_HUD
175 extern float get_anzg (void);
176 extern float get_Vx (void);
177 extern float get_Vy (void);
178 extern float get_Vz (void);
179 extern float get_Ax (void);
180 extern float get_Ay (void);
181 extern float get_Az (void);
182 extern int get_iaux1 (void);
183 extern int get_iaux2 (void);
184 extern int get_iaux3 (void);
185 extern int get_iaux4 (void);
186 extern int get_iaux5 (void);
187 extern int get_iaux6 (void);
188 extern int get_iaux7 (void);
189 extern int get_iaux8 (void);
190 extern int get_iaux9 (void);
191 extern int get_iaux10 (void);
192 extern int get_iaux11 (void);
193 extern int get_iaux12 (void);
194 extern float get_aux1(void);
195 extern float get_aux2(void);
196 extern float get_aux3(void);
197 extern float get_aux4(void);
198 extern float get_aux5 (void);
199 extern float get_aux6 (void);
200 extern float get_aux7 (void);
201 extern float get_aux8(void);
202 extern float get_aux9(void);
203 extern float get_aux10(void);
204 extern float get_aux11(void);
205 extern float get_aux12(void);
206 extern float get_aux13(void);
207 extern float get_aux14(void);
208 extern float get_aux15(void);
209 extern float get_aux16(void);
210 extern float get_aux17(void);
211 extern float get_aux18(void);
212 // $$$ end - added, VS Renganathan, 13 Oct 2K
214 extern char *get_formated_gmt_time( void );
215 extern void fgHUDReshape(void);
217 enum hudinstype{ HUDno_instr,
229 typedef struct gltagRGBTRIPLE { // rgbt
237 GLfloat x0, y0, x1, y1;
240 fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
241 : x0(a), y0(b), x1(c), y1(d) {}
243 fgLineSeg2D( const fgLineSeg2D & image )
244 : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
246 fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
247 x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
259 #define USE_HUD_TextList
260 extern float HUD_TextSize;
261 extern fntRenderer *HUDtext;
262 extern float HUD_matrix[16];
270 fgText(float x = 0, float y = 0, char *c = NULL,int digits=0): x(x), y(y) //suma
276 fgText( const fgText & image )
277 : x(image.x), y(image.y),digit(image.digit) {strcpy(msg,image.msg);} //suma
279 fgText& operator = ( const fgText & image ) {
280 strcpy(msg,image.msg); x = image.x; y = image.y;digit=image.digit; //suma
284 ~fgText() {msg[0]='\0';}
286 int getStringWidth ( char *str )
288 if ( HUDtext && str ) {
290 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
291 return FloatToInt( r - l );
296 int StringWidth (void )
298 if ( HUDtext && strlen( msg )) {
300 guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
301 return FloatToInt( r - l );
306 // this code is changed to display Numbers with big/small digits
307 // according to MIL Standards for example Altitude above 10000 ft
308 // is shown as 10ooo. begin suma
310 void Draw(fntRenderer *fnt,int digits) {
317 //if negative value then increase the c and p values
322 while(tmp[i]!='\0') {
323 if((tmp[i]>='0') && (tmp[i]<='9'))
328 fnt->setPointSize(8);
333 fnt->start2f(x+p2,y);
336 fnt->setPointSize(12);
338 strncpy(tmp2,msg,p1);
344 fnt->setPointSize(12);
345 fnt->start2f( x, y );
349 //if digits not equal to 1
350 fnt->setPointSize(8);
351 fnt->start2f( x, y );
359 guiFnt.drawString( msg, FloatToInt(x), FloatToInt(y) );
364 vector < fgLineSeg2D > List;
366 fgLineList( void ) {}
367 ~fgLineList( void ) {}
368 void add( fgLineSeg2D seg ) { List.push_back(seg); }
369 void erase( void ) { List.erase( List.begin(), List.end() ); }
371 vector < fgLineSeg2D > :: iterator curSeg;
372 vector < fgLineSeg2D > :: iterator lastSeg;
373 curSeg = List.begin();
374 lastSeg = List.end();
376 for ( ; curSeg != lastSeg; curSeg++ ) {
381 /* void draw( void ) {
382 vector < fgLineSeg2D > :: iterator curSeg;
383 vector < fgLineSeg2D > :: iterator lastSeg;
384 curSeg = List.begin();
385 lastSeg = List.end();
387 for ( ; curSeg != lastSeg; curSeg++ ) {
396 vector< fgText > List;
398 fgTextList ( void ) { Font = 0; }
399 ~fgTextList( void ) {}
401 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
402 void add( fgText String ) { List.push_back(String); }
403 void erase( void ) { List.erase( List.begin(), List.end() ); }
406 vector < fgText > :: iterator curString;
407 vector < fgText > :: iterator lastString;
408 if( Font == 0 ) return;
409 curString = List.begin();
410 lastString = List.end();
411 glPushAttrib( GL_COLOR_BUFFER_BIT );
412 glEnable ( GL_ALPHA_TEST ) ;
413 glEnable ( GL_BLEND ) ;
414 glAlphaFunc ( GL_GREATER, 0.1 ) ;
415 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
418 for( ; curString != lastString; curString++ ) {
419 curString->Draw(Font,curString->digit); //suma
423 glDisable ( GL_TEXTURE_2D ) ;
429 inline void Text( fgTextList &List, float x, float y, char *s)
431 List.add( fgText( x, y, s) );
434 inline void Text( fgTextList &List, fgText &me)
439 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
441 List.add(fgLineSeg2D(x1,y1,x2,y2));
445 // Declare our externals
446 extern fgTextList HUD_TextList;
447 extern fgLineList HUD_LineList;
448 extern fgLineList HUD_StippleLineList;
451 class instr_item { // An Abstract Base Class (ABC)
453 static UINT instances; // More than 64K instruments? Nah!
454 static int brightness;
455 static glRGBTRIPLE color;
458 RECT scrn_pos; // Framing - affects scale dimensions
459 // and orientation. Vert vs Horz, etc.
460 FLTFNPTR load_value_fn;
461 float disp_factor; // Multiply by to get numbers shown on scale.
465 UINT scr_span; // Working values for draw;
474 FLTFNPTR data_source,
478 int digit = 0); //suma
481 instr_item( const instr_item & image );
483 instr_item & operator = ( const instr_item & rhs );
484 virtual ~instr_item ();
486 int get_brightness ( void ) { return brightness;}
487 RECT get_location ( void ) { return scrn_pos; }
488 bool is_broken ( void ) { return broken; }
489 bool enabled ( void ) { return is_enabled;}
490 bool data_available ( void ) { return !!load_value_fn; }
491 float get_value ( void ) { return load_value_fn(); }
492 float data_scaling ( void ) { return disp_factor; }
493 UINT get_span ( void ) { return scr_span; }
494 POINT get_centroid ( void ) { return mid_span; }
495 UINT get_options ( void ) { return opts; }
496 int get_digits ( void ) { return digits; } //suma
498 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
499 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
500 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
501 UINT huds_both (UINT options) {
502 return( (options & HUDS_BOTH) == HUDS_BOTH );
504 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
505 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
506 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
507 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
509 virtual void display_enable( bool working ) { is_enabled = !! working;}
511 virtual void update( void );
512 virtual void break_display ( bool bad );
513 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
514 void SetPosition ( int x, int y, UINT width, UINT height );
515 UINT get_Handle( void );
516 virtual void draw( void ) = 0; // Required method in derived classes
518 void drawOneLine( float x1, float y1, float x2, float y2)
520 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
522 void drawOneStippleLine( float x1, float y1, float x2, float y2)
524 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
526 void TextString( char *msg, float x, float y,int digit ) //suma
528 HUD_TextList.add(fgText(x, y, msg,digit)); //suma
530 int getStringWidth ( char *str )
532 if ( HUDtext && str ) {
534 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
535 return FloatToInt( r - l );
540 //code to draw ticks as small circles
541 void drawOneCircle(float x1, float y1, float r)
543 glBegin(GL_LINE_LOOP); // Use polygon to approximate a circle
544 for(int count=0; count<25; count++) {
545 float cosine = r * cos(count * 2 * SG_PI/10.0);
546 float sine = r * sin(count * 2 * SG_PI/10.0);
547 glVertex2f(cosine+x1, sine+y1);
554 typedef instr_item *HIptr;
555 //typedef deque < instr_item * > hud_deque_type;
556 //typedef hud_deque_type::iterator hud_deque_iterator;
557 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
559 extern deque< instr_item *> HUD_deque;
560 extern int HUD_style;
561 //extern hud_deque_type HUD_deque;
563 // instr_item This class has no other purpose than to maintain
564 // a linked list of instrument and derived class
568 class instr_label : public instr_item {
572 const char *post_str;
576 char format_buffer[80];
586 FLTFNPTR data_source,
587 const char *label_format,
588 const char *pre_label_string,
589 const char *post_label_string,
592 fgLabelJust justification,
599 int digit ); //suma);
603 instr_label( const instr_label & image);
604 instr_label & operator = (const instr_label & rhs );
605 virtual void draw( void ); // Required method in base class
608 typedef instr_label * pInstlabel;
611 class lat_label : public instr_item {
615 const char *post_str;
619 char format_buffer[80];
626 FLTFNPTR data_source,
627 const char *label_format,
628 const char *pre_label_string,
629 const char *post_label_string,
632 fgLabelJust justification,
636 int digits =0 );//suma
640 lat_label( const lat_label & image);
641 lat_label & operator = (const lat_label & rhs );
642 virtual void draw( void ); // Required method in base class
645 typedef lat_label * pLatlabel;
647 class lon_label : public instr_item {
651 const char *post_str;
655 char format_buffer[80];
662 FLTFNPTR data_source,
663 const char *label_format,
664 const char *pre_label_string,
665 const char *post_label_string,
668 fgLabelJust justification,
677 lon_label( const lon_label & image);
678 lon_label & operator = (const lon_label & rhs );
679 virtual void draw( void ); // Required method in base class
682 typedef lon_label * pLonlabel;
685 // instr_scale This class is an abstract base class for both moving
686 // scale and moving needle (fixed scale) indicators. It
687 // does not draw itself, but is not instanciable.
690 class instr_scale : public instr_item {
692 float range_shown; // Width Units.
693 float Maximum_value; // ceiling.
694 float Minimum_value; // Representation floor.
695 float scale_factor; // factor => screen units/range values.
696 UINT Maj_div; // major division marker units
697 UINT Min_div; // minor division marker units
698 UINT Modulo; // Roll over point
699 int signif_digits; // digits to show to the right.
716 bool working = true);
718 virtual ~instr_scale();
719 instr_scale( const instr_scale & image);
720 instr_scale & operator = (const instr_scale & rhs);
722 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
723 UINT div_min ( void ) { return Min_div;}
724 UINT div_max ( void ) { return Maj_div;}
725 float min_val ( void ) { return Minimum_value;}
726 float max_val ( void ) { return Maximum_value;}
727 UINT modulo ( void ) { return Modulo; }
728 float factor ( void ) { return scale_factor;}
729 float range_to_show( void ) { return range_shown;}
732 // hud_card_ This class displays the indicated quantity on
733 // a scale that moves past the pointer. It may be
734 // horizontal or vertical, read above(left) or below(right) of the base
737 class hud_card : public instr_scale {
741 float half_width_units;
742 bool draw_tick_bottom;
744 bool draw_tick_right;
746 bool draw_cap_bottom;
756 float maxValue; //suma
757 float minValue; //suma
758 int divisions; //suma
780 bool draw_tick_bottom,
782 bool draw_tick_right,
784 bool draw_cap_bottom,
795 int divisions, //suma
800 hud_card( const hud_card & image);
801 hud_card & operator = (const hud_card & rhs );
802 // virtual void display_enable( bool setting );
803 virtual void draw( void ); // Required method in base class
804 void circles(float,float,float); // suma
805 void fixed(float,float,float,float,float,float); //suma
806 void zoomed_scale(int,int); //suma
809 typedef hud_card * pCardScale;
811 class gauge_instr : public instr_scale {
829 gauge_instr( const gauge_instr & image);
830 gauge_instr & operator = (const gauge_instr & rhs );
831 virtual void draw( void ); // Required method in base class
834 typedef gauge_instr * pGaugeInst;
836 // dual_instr_item This class was created to form the base class
837 // for both panel and HUD Turn Bank Indicators.
839 class dual_instr_item : public instr_item {
841 FLTFNPTR alt_data_source;
844 dual_instr_item ( int x,
848 FLTFNPTR chn1_source,
849 FLTFNPTR chn2_source,
853 virtual ~dual_instr_item() {};
854 dual_instr_item( const dual_instr_item & image);
855 dual_instr_item & operator = (const dual_instr_item & rhs );
857 float current_ch1( void ) { return (float)alt_data_source();}
858 float current_ch2( void ) { return (float)get_value();}
859 virtual void draw ( void ) { }
862 class fgTBI_instr : public dual_instr_item
876 FLTFNPTR chn1_source,
877 FLTFNPTR chn2_source,
885 fgTBI_instr( const fgTBI_instr & image);
886 fgTBI_instr & operator = (const fgTBI_instr & rhs );
890 UINT bank_limit( void ) { return BankLimit;}
891 UINT slew_limit( void ) { return SlewLimit;}
893 virtual void draw( void ); // Required method in base class
896 typedef fgTBI_instr * pTBI;
898 class HudLadder : public dual_instr_item {
908 string hudladder_type;
911 bool velocity_vector;
915 bool climb_dive_marker;
916 bool glide_slope_marker;
919 bool waypoint_marker;
927 fgLineList StippleLineList;
930 HudLadder( string name,
936 FLTFNPTR ptch_source,
937 FLTFNPTR roll_source,
939 float division_units,
940 float minor_division,
945 bool velocity_vector,
949 bool climb_dive_marker,
950 bool glide_slope_marker,
953 bool waypoint_marker,
962 HudLadder( const HudLadder & image );
963 HudLadder & operator = ( const HudLadder & rhs );
964 virtual void draw( void );
965 void drawZenith(float,float,float); //suma
966 void drawNadir(float, float, float); //suma
968 void Text( float x, float y, char *s)
970 TextList.add( fgText( x, y, s) );
973 void Line( float x1, float y1, float x2, float y2)
975 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
978 void StippleLine( float x1, float y1, float x2, float y2)
980 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
985 //using namespace std;
986 //deque <instr_item> * Hdeque_ptr;
988 extern void HUD_masterswitch( bool incr );
989 extern void HUD_brightkey( bool incr_bright );
990 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
991 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
992 extern void fgUpdateHUD( void );
993 extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
994 GLfloat x_end, GLfloat y_end );
996 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
997 extern void drawOneLine ( RECT &rect);
998 extern void textString ( int x,
1001 void *font = GLUT_BITMAP_9_BY_15,int digit=0); //suma
1002 extern void strokeString( int x,
1005 void *font = GLUT_STROKE_ROMAN,
1008 //extern void strokeString(float xx,
1011 // void *font = GLUT_STROKE_ROMAN)
1014 bool AddHUDInstrument( instr_item *pBlackBox );
1015 void DrawHUD ( void );
1016 bool DamageInstrument( INSTR_HANDLE unit );
1017 bool RepairInstrument( INSTR_HANDLE unit );
1020 void fgUpdateHUD ( Hptr hud );
1021 void fgUpdateHUD2( Hptr hud ); // Future use?
1022 void fgHUDSetTimeMode( Hptr hud, int time_of_day );