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++
43 //#ifdef HAVE_VALUES_H
44 //# include <values.h> // for MAXINT
47 #include <vector> // STL vector
48 #include <deque> // STL double ended queue
50 #include <simgear/constants.h>
52 #include <Include/fg_typedefs.h>
53 #include <Aircraft/aircraft.hxx>
54 #include <FDM/flight.hxx>
55 #include <Controls/controls.hxx>
58 #include "hud_opts.hxx"
62 FG_USING_NAMESPACE(std);
65 // some of Norman's crazy optimizations. :-)
73 int top, bottom, left, right;
77 // View mode definitions
79 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
81 // DAY, NIGHT and brightness levels need to be visible where dialogs and
82 // controls can be used to set intensity and appropriate color. This will
84 // Hud general constants
101 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
106 #define UPPER_CENTER 3
107 #define UPPER_RIGHT 4
108 #define CENTER_RIGHT 5
109 #define LOWER_RIGHT 6
110 #define LOWER_CENTER 7
112 #define CENTER_LEFT 9
113 #define SOLID_LINES 10
114 #define DASHED_LINES 11
115 #define DASHED_NEG_LINES 12
118 #define HORIZON_FIXED 1
119 #define HORIZON_MOVING 2
120 #define LABEL_COUNTER 1
121 #define LABEL_WARNING 2
123 #define HUDS_AUTOTICKS 0x0001
124 #define HUDS_VERT 0x0002
125 #define HUDS_HORZ 0x0000
126 #define HUDS_TOP 0x0004
127 #define HUDS_BOTTOM 0x0008
128 #define HUDS_LEFT HUDS_TOP
129 #define HUDS_RIGHT HUDS_BOTTOM
130 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
131 #define HUDS_NOTICKS 0x0010
132 #define HUDS_ARITHTIC 0x0020
133 #define HUDS_DECITICS 0x0040
134 #define HUDS_NOTEXT 0x0080
137 // #define HUD_VERTICAL 1
138 // #define HUD_HORIZONTAL 2
139 // #define HUD_FREEFLOAT 3
141 // Ladder orientation modes
142 // #define HUD_LEFT 1
143 // #define HUD_RIGHT 2
145 // #define HUD_BOTTOM 2
146 // #define HUD_V_LEFT 1
147 // #define HUD_V_RIGHT 2
148 // #define HUD_H_TOP 1
149 // #define HUD_H_BOTTOM 2
154 // #define HUD_NOLIM 2
155 // #define HUD_CIRC 3
157 // #define HUD_INSTR_LADDER 1
158 // #define HUD_INSTR_CLADDER 2
159 // #define HUD_INSTR_HORIZON 3
160 // #define HUD_INSTR_LABEL 4
163 extern float get_throttleval ( void );
164 extern float get_aileronval ( void );
165 extern float get_elevatorval ( void );
166 extern float get_elev_trimval( void );
167 extern float get_rudderval ( void );
168 extern float get_speed ( void );
169 extern float get_aoa ( void );
170 extern float get_roll ( void );
171 extern float get_pitch ( void );
172 extern float get_heading ( void );
173 extern float get_view_direction( void );
174 extern float get_altitude ( void );
175 extern float get_agl ( void );
176 extern float get_sideslip ( void );
177 extern float get_frame_rate ( void );
178 extern float get_latitude ( void );
179 extern float get_lat_min ( void );
180 extern float get_longitude ( void );
181 extern float get_long_min ( void );
182 extern float get_fov ( void );
183 extern float get_vfc_ratio ( void );
184 extern float get_vfc_tris_drawn ( void );
185 extern float get_vfc_tris_culled ( void );
186 extern float get_climb_rate ( void );
187 extern float get_mach( void );
188 extern char *coord_format_lat(float);
189 extern char *coord_format_lon(float);
190 //extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
192 extern char *get_formated_gmt_time( void );
193 extern void fgHUDReshape(void);
195 enum hudinstype{ HUDno_instr,
207 typedef struct gltagRGBTRIPLE { // rgbt
215 GLfloat x0, y0, x1, y1;
218 fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
219 : x0(a), y0(b), x1(c), y1(d) {}
221 fgLineSeg2D( const fgLineSeg2D & image )
222 : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
224 fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
225 x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
237 #define USE_HUD_TextList
238 extern float HUD_TextSize;
239 extern fntRenderer *HUDtext;
240 extern float HUD_matrix[16];
247 fgText( float x = 0, float y = 0, char *c = NULL )
248 : x(x), y(y) {strncpy(msg,c,64-1);}
250 fgText( const fgText & image )
251 : x(image.x), y(image.y) {strcpy(msg,image.msg);}
253 fgText& operator = ( const fgText & image ) {
254 strcpy(msg,image.msg); x = image.x; y = image.y;
258 ~fgText() {msg[0]='\0';}
260 int getStringWidth ( char *str )
262 if ( HUDtext && str )
265 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
266 return FloatToInt( r - l );
271 int StringWidth (void )
273 if ( HUDtext && strlen( msg ))
276 guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
277 return FloatToInt( r - l );
282 void Draw(fntRenderer *fnt)
284 fnt->start2f( x, y );
290 puDrawString ( guiFnt, msg, FloatToInt(x), FloatToInt(y) );
295 vector < fgLineSeg2D > List;
297 fgLineList( void ) {}
298 ~fgLineList( void ) {}
299 void add( fgLineSeg2D seg ) { List.push_back(seg); }
300 void erase( void ) { List.erase( List.begin(), List.end() ); }
302 vector < fgLineSeg2D > :: iterator curSeg;
303 vector < fgLineSeg2D > :: iterator lastSeg;
304 curSeg = List.begin();
305 lastSeg = List.end();
307 for ( ; curSeg != lastSeg; curSeg++ ) {
312 /* void draw( void ) {
313 vector < fgLineSeg2D > :: iterator curSeg;
314 vector < fgLineSeg2D > :: iterator lastSeg;
315 curSeg = List.begin();
316 lastSeg = List.end();
318 for ( ; curSeg != lastSeg; curSeg++ ) {
327 vector< fgText > List;
329 fgTextList ( void ) { Font = 0; }
330 ~fgTextList( void ) {}
332 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
333 void add( fgText String ) { List.push_back(String); }
334 void erase( void ) { List.erase( List.begin(), List.end() ); }
337 vector < fgText > :: iterator curString;
338 vector < fgText > :: iterator lastString;
339 if( Font == 0 ) return;
340 curString = List.begin();
341 lastString = List.end();
342 glPushAttrib( GL_COLOR_BUFFER_BIT );
343 glEnable ( GL_ALPHA_TEST ) ;
344 glEnable ( GL_BLEND ) ;
345 glAlphaFunc ( GL_GREATER, 0.1 ) ;
346 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
349 for( ; curString != lastString; curString++ ) {
350 curString->Draw(Font);
354 glDisable ( GL_TEXTURE_2D ) ;
360 inline void Text( fgTextList &List, float x, float y, char *s)
362 List.add( fgText( x, y, s) );
365 inline void Text( fgTextList &List, fgText &me)
370 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
372 List.add(fgLineSeg2D(x1,y1,x2,y2));
376 // Declare our externals
377 extern fgTextList HUD_TextList;
378 extern fgLineList HUD_LineList;
379 extern fgLineList HUD_StippleLineList;
382 class instr_item { // An Abstract Base Class (ABC)
384 static UINT instances; // More than 64K instruments? Nah!
385 static int brightness;
386 static glRGBTRIPLE color;
389 RECT scrn_pos; // Framing - affects scale dimensions
390 // and orientation. Vert vs Horz, etc.
391 FLTFNPTR load_value_fn;
392 float disp_factor; // Multiply by to get numbers shown on scale.
396 UINT scr_span; // Working values for draw;
404 FLTFNPTR data_source,
407 bool working = true);
409 instr_item( const instr_item & image );
411 instr_item & operator = ( const instr_item & rhs );
412 virtual ~instr_item ();
414 int get_brightness ( void ) { return brightness;}
415 RECT get_location ( void ) { return scrn_pos; }
416 bool is_broken ( void ) { return broken; }
417 bool enabled ( void ) { return is_enabled;}
418 bool data_available ( void ) { return !!load_value_fn; }
419 float get_value ( void ) { return load_value_fn(); }
420 float data_scaling ( void ) { return disp_factor; }
421 UINT get_span ( void ) { return scr_span; }
422 POINT get_centroid ( void ) { return mid_span; }
423 UINT get_options ( void ) { return opts; }
425 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
426 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
427 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
428 UINT huds_both (UINT options) { return( (options & HUDS_BOTH) == HUDS_BOTH ); }
429 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
430 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
431 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
432 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
434 virtual void display_enable( bool working ) { is_enabled = !! working;}
436 virtual void update( void );
437 virtual void break_display ( bool bad );
438 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
439 void SetPosition ( int x, int y, UINT width, UINT height );
440 UINT get_Handle( void );
441 virtual void draw( void ) = 0; // Required method in derived classes
443 void drawOneLine( float x1, float y1, float x2, float y2)
445 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
447 void drawOneStippleLine( float x1, float y1, float x2, float y2)
449 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
451 void TextString( char *msg, float x, float y )
453 HUD_TextList.add(fgText(x, y, msg));
455 int getStringWidth ( char *str )
457 if ( HUDtext && str )
460 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
461 return FloatToInt( r - l );
468 typedef instr_item *HIptr;
469 //typedef deque < instr_item * > hud_deque_type;
470 //typedef hud_deque_type::iterator hud_deque_iterator;
471 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
473 extern deque< instr_item *> HUD_deque;
474 extern int HUD_style;
475 //extern hud_deque_type HUD_deque;
477 // instr_item This class has no other purpose than to maintain
478 // a linked list of instrument and derived class
482 class instr_label : public instr_item {
486 const char *post_str;
490 char format_buffer[80];
497 FLTFNPTR data_source,
498 const char *label_format,
499 const char *pre_label_string = 0,
500 const char *post_label_string = 0,
501 float scale_data = 1.0,
502 UINT options = HUDS_TOP,
503 fgLabelJust justification = CENTER_JUST,
504 int font_size = SMALL,
505 int blinking = NOBLINK,
506 bool working = true);
510 instr_label( const instr_label & image);
511 instr_label & operator = (const instr_label & rhs );
512 virtual void draw( void ); // Required method in base class
515 typedef instr_label * pInstlabel;
518 class lat_label : public instr_item {
522 const char *post_str;
526 char format_buffer[80];
533 FLTFNPTR data_source,
534 const char *label_format,
535 const char *pre_label_string = 0,
536 const char *post_label_string = 0,
537 float scale_data = 1.0,
538 UINT options = HUDS_TOP,
539 fgLabelJust justification = CENTER_JUST,
540 int font_size = SMALL,
541 int blinking = NOBLINK,
542 bool working = true);
546 lat_label( const lat_label & image);
547 lat_label & operator = (const lat_label & rhs );
548 virtual void draw( void ); // Required method in base class
551 typedef lat_label * pLatlabel;
553 class lon_label : public instr_item {
557 const char *post_str;
561 char format_buffer[80];
568 FLTFNPTR data_source,
569 const char *label_format,
570 const char *pre_label_string = 0,
571 const char *post_label_string = 0,
572 float scale_data = 1.0,
573 UINT options = HUDS_TOP,
574 fgLabelJust justification = CENTER_JUST,
575 int font_size = SMALL,
576 int blinking = NOBLINK,
577 bool working = true);
581 lon_label( const lon_label & image);
582 lon_label & operator = (const lon_label & rhs );
583 virtual void draw( void ); // Required method in base class
586 typedef lon_label * pLonlabel;
589 // instr_scale This class is an abstract base class for both moving
590 // scale and moving needle (fixed scale) indicators. It
591 // does not draw itself, but is not instanciable.
594 class instr_scale : public instr_item {
596 float range_shown; // Width Units.
597 float Maximum_value; // ceiling.
598 float Minimum_value; // Representation floor.
599 float scale_factor; // factor => screen units/range values.
600 UINT Maj_div; // major division marker units
601 UINT Min_div; // minor division marker units
602 UINT Modulo; // Roll over point
603 int signif_digits; // digits to show to the right.
613 float max_value = 100.0,
614 float min_value = 0.0,
615 float disp_scaling = 1.0,
616 UINT major_divs = 10,
620 bool working = true);
622 virtual ~instr_scale();
623 instr_scale( const instr_scale & image);
624 instr_scale & operator = (const instr_scale & rhs);
626 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
627 UINT div_min ( void ) { return Min_div;}
628 UINT div_max ( void ) { return Maj_div;}
629 float min_val ( void ) { return Minimum_value;}
630 float max_val ( void ) { return Maximum_value;}
631 UINT modulo ( void ) { return Modulo; }
632 float factor ( void ) { return scale_factor;}
633 float range_to_show( void ) { return range_shown;}
636 // hud_card_ This class displays the indicated quantity on
637 // a scale that moves past the pointer. It may be
638 // horizontal or vertical, read above(left) or below(right) of the base
641 class hud_card : public instr_scale {
644 float half_width_units;
653 float maxValue = 100.0,
654 float minValue = 0.0,
655 float disp_scaling = 1.0,
656 UINT major_divs = 10,
658 UINT modulator = 100,
660 float value_span = 100.0,
661 bool working = true);
664 hud_card( const hud_card & image);
665 hud_card & operator = (const hud_card & rhs );
666 // virtual void display_enable( bool setting );
667 virtual void draw( void ); // Required method in base class
670 typedef hud_card * pCardScale;
672 class guage_instr : public instr_scale {
680 float disp_scaling = 1.0,
681 float maxValue = 100,
683 UINT major_divs = 50,
687 bool working = true);
690 guage_instr( const guage_instr & image);
691 guage_instr & operator = (const guage_instr & rhs );
692 virtual void draw( void ); // Required method in base class
695 typedef guage_instr * pGuageInst;
697 // dual_instr_item This class was created to form the base class
698 // for both panel and HUD Turn Bank Indicators.
700 class dual_instr_item : public instr_item {
702 FLTFNPTR alt_data_source;
705 dual_instr_item ( int x,
709 FLTFNPTR chn1_source,
710 FLTFNPTR chn2_source,
712 UINT options = HUDS_TOP);
714 virtual ~dual_instr_item() {};
715 dual_instr_item( const dual_instr_item & image);
716 dual_instr_item & operator = (const dual_instr_item & rhs );
718 float current_ch1( void ) { return (float)alt_data_source();}
719 float current_ch2( void ) { return (float)get_value();}
720 virtual void draw ( void ) { }
723 class fgTBI_instr : public dual_instr_item {
734 FLTFNPTR chn1_source = get_roll,
735 FLTFNPTR chn2_source = get_sideslip,
736 float maxBankAngle = 45.0,
737 float maxSlipAngle = 5.0,
739 bool working = true);
741 fgTBI_instr( const fgTBI_instr & image);
742 fgTBI_instr & operator = (const fgTBI_instr & rhs );
746 UINT bank_limit( void ) { return BankLimit;}
747 UINT slew_limit( void ) { return SlewLimit;}
749 virtual void draw( void ); // Required method in base class
752 typedef fgTBI_instr * pTBI;
754 class HudLadder : public dual_instr_item {
768 fgLineList StippleLineList;
776 FLTFNPTR ptch_source = get_roll,
777 FLTFNPTR roll_source = get_pitch,
778 float span_units = 45.0,
779 float division_units = 10.0,
780 float minor_division = 0.0,
781 UINT screen_hole = 70,
783 bool working = true );
787 HudLadder( const HudLadder & image );
788 HudLadder & operator = ( const HudLadder & rhs );
789 virtual void draw( void );
791 void Text( float x, float y, char *s)
793 TextList.add( fgText( x, y, s) );
796 void Line( float x1, float y1, float x2, float y2)
798 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
801 void StippleLine( float x1, float y1, float x2, float y2)
803 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
808 //using namespace std;
809 //deque <instr_item> * Hdeque_ptr;
811 extern void HUD_masterswitch( bool incr );
812 extern void HUD_brightkey( bool incr_bright );
813 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
814 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
815 extern void fgUpdateHUD( void );
817 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
818 extern void drawOneLine ( RECT &rect);
819 extern void textString ( int x,
822 void *font = GLUT_BITMAP_8_BY_13);
823 extern void strokeString( int x,
826 void *font = GLUT_STROKE_ROMAN,
828 //extern void strokeString(float xx,
831 // void *font = GLUT_STROKE_ROMAN)
834 bool AddHUDInstrument( instr_item *pBlackBox );
835 void DrawHUD ( void );
836 bool DamageInstrument( INSTR_HANDLE unit );
837 bool RepairInstrument( INSTR_HANDLE unit );
840 void fgUpdateHUD ( Hptr hud );
841 void fgUpdateHUD2( Hptr hud ); // Future use?
842 void fgHUDSetTimeMode( Hptr hud, int time_of_day );