]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud.hxx
24525fca6a87a1f8de127171c3cfa192694a7492
[flightgear.git] / src / Cockpit / hud.hxx
1 // hud.hxx -- hud defines and prototypes (initial draft)
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
6 //
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.
11 //
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.
16 //
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _HUD_HXX
25 #define _HUD_HXX
26
27 #ifndef __cplusplus
28 # error This library requires C++
29 #endif
30
31 #include <simgear/compiler.h>
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <stdlib.h>
42 #include <string.h>
43
44 //#ifdef HAVE_VALUES_H
45 //#  include <values.h>  // for MAXINT
46 //#endif
47
48 #include <algorithm>    // for_each()
49 #include <vector>       // STL vector
50 #include <deque>        // STL double ended queue
51 #include STL_FSTREAM
52
53 #include <simgear/constants.h>
54
55 #include <Include/fg_typedefs.h>
56 #include <Aircraft/aircraft.hxx>
57 #include <Aircraft/controls.hxx>
58 #include <FDM/flight.hxx>
59 #include <GUI/gui.h>
60 #include <Main/globals.hxx>
61 #include <Main/viewmgr.hxx>
62 #include <Airports/runways.hxx>
63
64 #include "hud_opts.hxx"
65 #include <plib/sg.h>
66
67 SG_USING_STD(deque);
68 SG_USING_STD(vector);
69 SG_USING_NAMESPACE(std);
70
71
72
73 // some of Norman's crazy optimizations. :-)
74
75 #ifndef WIN32
76 typedef struct {
77     int x, y;
78 } POINT;
79  
80 typedef struct {
81     int top, bottom, left, right;
82 } RECT;
83 #endif
84
85 // View mode definitions
86
87 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
88
89 // Label constants
90 #define HUD_FONT_SMALL     1
91 #define HUD_FONT_LARGE     2
92
93 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
94
95 #define HUDS_AUTOTICKS           0x0001
96 #define HUDS_VERT                0x0002
97 #define HUDS_HORZ                0x0000
98 #define HUDS_TOP                 0x0004
99 #define HUDS_BOTTOM              0x0008
100 #define HUDS_LEFT     HUDS_TOP
101 #define HUDS_RIGHT    HUDS_BOTTOM
102 #define HUDS_BOTH     (HUDS_LEFT | HUDS_RIGHT)
103 #define HUDS_NOTICKS             0x0010
104 #define HUDS_ARITHTIC            0x0020
105 #define HUDS_DECITICS            0x0040
106 #define HUDS_NOTEXT              0x0080
107
108 // Ladder orientaion
109 // #define HUD_VERTICAL        1
110 // #define HUD_HORIZONTAL       2
111 // #define HUD_FREEFLOAT        3
112
113 // Ladder orientation modes
114 // #define HUD_LEFT         1
115 // #define HUD_RIGHT            2
116 // #define HUD_TOP              1
117 // #define HUD_BOTTOM           2
118 // #define HUD_V_LEFT           1
119 // #define HUD_V_RIGHT          2
120 // #define HUD_H_TOP            1
121 // #define HUD_H_BOTTOM         2
122
123
124 // Ladder sub-types
125 // #define HUD_LIM              1
126 // #define HUD_NOLIM            2
127 // #define HUD_CIRC         3
128
129 // #define HUD_INSTR_LADDER 1
130 // #define HUD_INSTR_CLADDER    2
131 // #define HUD_INSTR_HORIZON    3
132 // #define HUD_INSTR_LABEL      4
133
134 // in cockpit.cxx
135 extern float get_throttleval ( void );
136 extern float get_aileronval  ( void );
137 extern float get_elevatorval ( void );
138 extern float get_elev_trimval( void );
139 extern float get_rudderval   ( void );
140 extern float get_speed       ( void );
141 extern float get_aoa         ( void );
142 extern float get_nlf         ( void );
143 extern float get_roll        ( void );
144 extern float get_pitch       ( void );
145 extern float get_heading     ( void );
146 extern float get_view_direction( void );
147 extern float get_altitude    ( void );
148 extern float get_agl         ( void );
149 extern float get_sideslip    ( void );
150 extern float get_frame_rate  ( void );
151 extern float get_latitude    ( void );
152 extern float get_lat_min     ( void );
153 extern float get_longitude   ( void );
154 extern float get_long_min    ( void );
155 extern float get_fov         ( void );
156 extern float get_vfc_ratio   ( void );
157 extern float get_vfc_tris_drawn   ( void );
158 extern float get_vfc_tris_culled   ( void );
159 extern float get_climb_rate  ( void );
160 extern float get_mach( void );
161 extern char *coord_format_lat(float);
162 extern char *coord_format_lon(float);
163 //extern char *coord_format_latlon(float latitude, float longitude);  // cockpit.cxx
164
165 // $$$ begin - added, VS Renganathan, 13 Oct 2K
166 // #define FIGHTER_HUD
167 extern float get_anzg (void);
168 extern float get_Vx (void);
169 extern float get_Vy (void);
170 extern float get_Vz (void);
171 extern float get_Ax (void);
172 extern float get_Ay (void);
173 extern float get_Az (void);
174 extern int get_iaux1 (void);
175 extern int get_iaux2 (void);
176 extern int get_iaux3 (void);
177 extern int get_iaux4 (void);
178 extern int get_iaux5 (void);
179 extern int get_iaux6 (void);
180 extern int get_iaux7 (void);
181 extern int get_iaux8 (void);
182 extern int get_iaux9 (void);
183 extern int get_iaux10 (void);
184 extern int get_iaux11 (void);
185 extern int get_iaux12 (void);
186 extern float get_aux1(void);
187 extern float get_aux2(void);
188 extern float get_aux3(void);
189 extern float get_aux4(void);
190 extern float get_aux5 (void);
191 extern float get_aux6 (void);
192 extern float get_aux7 (void);
193 extern float get_aux8(void);
194 extern float get_aux9(void);
195 extern float get_aux10(void);
196 extern float get_aux11(void);
197 extern float get_aux12(void);
198 extern float get_aux13(void);
199 extern float get_aux14(void);
200 extern float get_aux15(void);
201 extern float get_aux16(void);
202 extern float get_aux17(void);
203 extern float get_aux18(void);
204 // $$$ end - added, VS Renganathan, 13 Oct 2K
205
206 extern char *get_formated_gmt_time( void );
207 extern void fgHUDReshape(void);
208
209 enum  hudinstype{ HUDno_instr,
210                   HUDscale,
211                   HUDlabel,
212                   HUDladder,
213                   HUDcirc_ladder,
214                   HUDhorizon,
215                   HUDgauge,
216                   HUDdual_inst,
217                   HUDmoving_scale,
218                   HUDtbi
219 };
220
221 typedef struct gltagRGBTRIPLE { // rgbt
222     GLfloat Blue;
223     GLfloat Green;
224     GLfloat Red;
225 } glRGBTRIPLE;
226
227 class fgLineSeg2D {
228 private:
229     GLfloat x0, y0, x1, y1;
230
231 public:
232     fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
233         : x0(a), y0(b),  x1(c), y1(d) {}
234
235     fgLineSeg2D( const fgLineSeg2D & image )
236         : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
237
238     fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
239         x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
240     }
241
242     ~fgLineSeg2D() {}
243     
244     void draw() const
245     {
246         glVertex2f(x0, y0);
247         glVertex2f(x1, y1);
248     }
249 };
250
251 class DrawLineSeg2D {
252     public:
253         void operator() (const fgLineSeg2D& elem) const {
254             elem.draw();
255         }
256 };
257
258
259 #define USE_HUD_TextList
260 extern fntTexFont        *HUD_Font;
261 extern float              HUD_TextSize;
262 extern fntRenderer       *HUDtext;
263 extern float HUD_matrix[16];
264
265 class fgText {
266 private:
267     float x, y;
268     char msg[64];
269 public:
270     int digit; //suma
271     fgText(float x = 0, float y = 0, char *c = NULL,int digits=0): x(x), y(y) //suma
272     { 
273         strcpy(msg,c);
274         digit=digits; //suma
275     }
276                    
277     fgText( const fgText & image )
278         : x(image.x), y(image.y),digit(image.digit) {strcpy(msg,image.msg);} //suma
279
280     fgText& operator = ( const fgText & image ) {
281         strcpy(msg,image.msg); x = image.x; y = image.y;digit=image.digit; //suma
282         return *this;   
283     }
284
285     ~fgText() {msg[0]='\0';}
286
287     int getStringWidth ( char *str )
288     {
289         if ( HUDtext && str ) {
290             float r, l ;
291             HUD_Font->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
292             return FloatToInt( r - l );
293         }
294         return 0 ;
295     }
296     
297     int StringWidth (void )
298     {
299         if ( HUDtext && strlen( msg )) {
300             float r, l ;
301             HUD_Font->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
302             return FloatToInt( r - l );
303         }
304         return 0 ;
305     }
306    
307     // this code is changed to display Numbers with big/small digits
308     // according to MIL Standards for example Altitude above 10000 ft
309     // is shown as 10ooo.  begin suma
310
311     void Draw(fntRenderer *fnt,int digits) {
312         if(digits==1) {
313             int c=0,i=0;
314             char *t=msg;
315             int p=4;
316
317             if(t[0]=='-') {
318                 //if negative value then increase the c and p values
319                 //for '-' sign.  c++;
320                 p++;
321             }
322             char *tmp=msg;
323             while(tmp[i]!='\0') {
324                 if((tmp[i]>='0') && (tmp[i]<='9'))  
325                     c++;
326                 i++;
327             }
328             if(c>p) {
329                 fnt->setPointSize(HUD_TextSize * 0.8);
330                 int p1=c-3;
331                 char *tmp1=msg+p1;
332                 int p2=p1*8;
333                           
334                 fnt->start2f(x+p2,y);
335                 fnt->puts(tmp1);
336
337                 fnt->setPointSize(HUD_TextSize * 1.2);
338                 char tmp2[64];
339                 strncpy(tmp2,msg,p1);
340                 tmp2[p1]='\0';
341                          
342                 fnt->start2f(x,y);
343                 fnt->puts(tmp2);
344             } else {
345                 fnt->setPointSize(HUD_TextSize * 1.2);
346                 fnt->start2f( x, y );
347                 fnt->puts(tmp);
348             }
349         } else {
350             //if digits not equal to 1
351             fnt->setPointSize(HUD_TextSize * 0.8);
352             fnt->start2f( x, y );
353             fnt->puts( msg ) ;
354         }
355     }
356     //end suma
357
358     void Draw()
359     {
360         guiFnt.drawString( msg, FloatToInt(x), FloatToInt(y) );
361     }
362 };
363
364 class fgLineList {
365     vector < fgLineSeg2D > List;
366 public:
367     fgLineList( void ) {}
368     ~fgLineList( void ) {}
369     void add( const fgLineSeg2D& seg ) { List.push_back(seg); }
370     void erase( void ) { List.erase( List.begin(), List.end() ); }
371     void draw( void ) {
372         glBegin(GL_LINES);
373         for_each( List.begin(), List.end(), DrawLineSeg2D());
374         glEnd();
375     }
376 };
377
378 class fgTextList {
379     fntRenderer *Font;
380     vector< fgText > List;
381 public:
382     fgTextList ( void ) { Font = 0; }
383     ~fgTextList( void ) {}
384     
385     void setFont( fntRenderer *Renderer ) { Font = Renderer; }
386     void add( const fgText& String ) { List.push_back(String); }
387     void erase( void ) { List.erase( List.begin(), List.end() ); }
388     
389     void draw( void ) {
390         if( Font == 0 )
391             return;
392         vector < fgText > :: iterator curString = List.begin();
393         vector < fgText > :: iterator lastString = List.end();
394
395         glPushAttrib( GL_COLOR_BUFFER_BIT );
396         glEnable    ( GL_ALPHA_TEST   ) ;
397         glEnable    ( GL_BLEND        ) ;
398         glAlphaFunc ( GL_GREATER, 0.1 ) ;
399         glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
400
401         Font->begin();
402         for( ; curString != lastString; curString++ ) {
403             curString->Draw(Font,curString->digit); //suma
404         }
405         Font->end();
406
407         glDisable ( GL_TEXTURE_2D ) ;
408         glPopAttrib();
409     }
410 };
411
412
413 inline void Text( fgTextList &List, float x, float y, char *s)
414 {
415     List.add( fgText( x, y, s) );
416 }
417
418 inline void Text( fgTextList &List, const fgText &me)
419 {
420     List.add(me);
421 }
422
423 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
424 {
425     List.add(fgLineSeg2D(x1,y1,x2,y2));
426 }
427
428
429 // Declare our externals
430 extern fgTextList         HUD_TextList;
431 extern fgLineList         HUD_LineList;
432 extern fgLineList         HUD_StippleLineList;
433
434
435 class instr_item {  // An Abstract Base Class (ABC)
436 private:
437     static UINT        instances;     // More than 64K instruments? Nah!
438     static int         brightness;
439     static glRGBTRIPLE color;
440
441     UINT               handle;
442     RECT               scrn_pos;      // Framing - affects scale dimensions
443                                       // and orientation. Vert vs Horz, etc.
444     FLTFNPTR           load_value_fn;
445     float              disp_factor;   // Multiply by to get numbers shown on scale.
446     UINT               opts;
447     bool               is_enabled;
448     bool               broken;
449     UINT               scr_span;      // Working values for draw;
450     POINT              mid_span;      //
451     int                digits;        //suma
452   
453 public:
454     instr_item( int            x,
455                 int            y,
456                 UINT           height,
457                 UINT           width,
458                 FLTFNPTR       data_source,
459                 float          data_scaling,
460                 UINT           options,
461                 bool           working  = true,
462                 int            digit = 0); //suma
463
464     instr_item( const instr_item & image );
465
466     instr_item & operator = ( const instr_item & rhs );
467     virtual ~instr_item ();
468
469     int     get_brightness  ( void ) { return brightness;}
470     RECT    get_location    ( void ) { return scrn_pos;  }
471     bool    is_broken       ( void ) { return broken;    }
472     bool    enabled         ( void ) { return is_enabled;}
473     bool    data_available  ( void ) { return !!load_value_fn; }
474     float   get_value       ( void ) { return load_value_fn(); }
475     float   data_scaling    ( void ) { return disp_factor; }
476     UINT    get_span        ( void ) { return scr_span;  }
477     POINT   get_centroid    ( void ) { return mid_span;  }
478     UINT    get_options     ( void ) { return opts;      }
479     int     get_digits      ( void ) { return digits;    } //suma
480
481     UINT    huds_vert     (UINT options) { return( options  & HUDS_VERT ); }
482     UINT    huds_left     (UINT options) { return( options  & HUDS_LEFT ); }
483     UINT    huds_right    (UINT options) { return( options  & HUDS_RIGHT ); }
484     UINT    huds_both     (UINT options) {
485         return( (options & HUDS_BOTH) == HUDS_BOTH );
486     }
487     UINT    huds_noticks  (UINT options) { return( options  & HUDS_NOTICKS ); }
488     UINT    huds_notext   (UINT options) { return( options  & HUDS_NOTEXT ); }
489     UINT    huds_top      (UINT options) { return( options  & HUDS_TOP ); }
490     UINT    huds_bottom   (UINT options) { return( options  & HUDS_BOTTOM ); }
491   
492     virtual void display_enable( bool working ) { is_enabled = !! working;}
493
494     virtual void update( void );
495     virtual void break_display ( bool bad );
496     virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
497     void         SetPosition  ( int x, int y, UINT width, UINT height );
498     UINT         get_Handle( void );
499     virtual void draw( void ) = 0;   // Required method in derived classes
500     
501     void drawOneLine( float x1, float y1, float x2, float y2)
502     {
503         HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
504     }
505     void drawOneStippleLine( float x1, float y1, float x2, float y2)
506     {
507         HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
508     }
509     void TextString( char *msg, float x, float y,int digit ) //suma
510     {
511         HUD_TextList.add(fgText(x, y, msg,digit)); //suma  
512     }
513     int getStringWidth ( char *str )
514     {
515         if ( HUDtext && str ) {
516             float r, l ;
517             HUD_Font->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
518             return FloatToInt( r - l );
519         }
520         return 0 ;
521     }
522
523     //code to draw ticks as small circles
524     void drawOneCircle(float x1, float y1, float r)
525     {
526         glBegin(GL_LINE_LOOP);  // Use polygon to approximate a circle 
527         for(int count=0; count<25; count++) {             
528             float cosine = r * cos(count * 2 * SG_PI/10.0); 
529             float sine =   r * sin(count * 2 * SG_PI/10.0); 
530             glVertex2f(cosine+x1, sine+y1);
531         }     
532         glEnd(); 
533     }
534     
535 };
536
537 typedef instr_item *HIptr;
538
539 class HUDdraw {
540     public:
541         void operator() (HIptr elem) const {
542             if( elem->enabled())
543                 elem->draw();
544         }
545 };
546
547 //typedef deque <  instr_item * > hud_deque_type;
548 //typedef hud_deque_type::iterator hud_deque_iterator;
549 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
550
551 extern deque< instr_item *> HUD_deque;
552 extern int HUD_style;
553 //extern hud_deque_type HUD_deque;
554
555 // instr_item           This class has no other purpose than to maintain
556 //                      a linked list of instrument and derived class
557 // object pointers.
558
559
560 class instr_label : public instr_item {
561 private:
562     const char *pformat;
563     const char *pre_str;
564     const char *post_str;
565     fgLabelJust justify;
566     int         fontSize;
567     int         blink;
568     char format_buffer[80];
569     bool                lat;
570     bool                lon;
571     bool                lbox;
572
573 public:
574     instr_label( int          x,
575                  int          y,
576                  UINT         width,
577                  UINT         height,
578                  FLTFNPTR     data_source,
579                  const char  *label_format,
580                  const char  *pre_label_string,
581                  const char  *post_label_string,
582                  float        scale_data,
583                  UINT         options,
584                  fgLabelJust  justification,
585                  int          font_size,
586                  int          blinking,
587                  bool             latitude,
588                  bool             longitude,
589                  bool             label_box,
590                  bool         working,
591                  int          digit ); //suma);
592
593     ~instr_label();
594
595     instr_label( const instr_label & image);
596     instr_label & operator = (const instr_label & rhs );
597     virtual void draw( void );       // Required method in base class
598 };
599
600 typedef instr_label * pInstlabel;
601
602
603 class lat_label : public instr_item {
604 private:
605     const char *pformat;
606     const char *pre_str;
607     const char *post_str;
608     fgLabelJust justify;
609     int         fontSize;
610     int         blink;
611     char format_buffer[80];
612
613 public:
614     lat_label( int          x,
615                int          y,
616                UINT         width,
617                UINT         height,
618                FLTFNPTR     data_source,
619                const char  *label_format,
620                const char  *pre_label_string,
621                const char  *post_label_string,
622                float       scale_data,
623                UINT         options,
624                fgLabelJust  justification,
625                int          font_size,
626                int          blinking,
627                bool         working,
628                int          digits =0 );//suma
629
630     ~lat_label();
631
632     lat_label( const lat_label & image);
633     lat_label & operator = (const lat_label & rhs );
634     virtual void draw( void );       // Required method in base class
635 };
636
637 typedef lat_label * pLatlabel;
638
639 class lon_label : public instr_item {
640 private:
641     const char *pformat;
642     const char *pre_str;
643     const char *post_str;
644     fgLabelJust justify;
645     int         fontSize;
646     int         blink;
647     char format_buffer[80];
648
649 public:
650     lon_label( int          x,
651                int          y,
652                UINT         width,
653                UINT         height,
654                FLTFNPTR     data_source,
655                const char  *label_format,
656                const char  *pre_label_string,
657                const char  *post_label_string,
658                float       scale_data,
659                UINT         options,
660                fgLabelJust  justification,
661                int          font_size,
662                int          blinking,
663                bool         working,
664                int          digit=0); //suma
665
666
667     ~lon_label();
668
669     lon_label( const lon_label & image);
670     lon_label & operator = (const lon_label & rhs );
671     virtual void draw( void );       // Required method in base class
672 };
673
674 typedef lon_label * pLonlabel;
675
676 //
677 // fgRunway_instr       This class is responsible for rendering the active runway
678 //                      in the hud (if visible).
679 class runway_instr : public instr_item 
680 {
681 private:        
682         void boundPoint(const sgdVec3& v, sgdVec3& m);
683         bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
684         bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
685         void drawArrow();
686         bool get_active_runway(FGRunway& rwy);
687         void get_rwy_points(sgdVec3 *points);
688         void setLineWidth(void);
689
690         sgdVec3 points3d[6],points2d[6];
691         double mm[16],pm[16], arrowScale, arrowRad, lnScale, scaleDist, default_pitch, default_heading;
692         GLint view[4];
693         FGRunway runway;
694         FGViewer* cockpit_view; 
695         unsigned short stippleOut,stippleCen;
696         bool drawIA,drawIAAlways;
697         RECT location;
698         POINT center; 
699         
700 public:
701     runway_instr( int    x,
702                   int    y,                     
703                                   int    width,
704                                   int    height,
705                   float  scale_data,
706                   bool   working = true);
707
708     virtual void draw( void );       // Required method in base class
709         void setArrowRotationRadius(double radius);
710         void setArrowScale(double scale); // Scales the runway indication arrow
711         void setDrawArrow(bool draw);    // Draws arrow when runway is not visible in HUD if draw=true
712         void setDrawArrowAlways(bool draw); //Always draws arrow if draw=true;
713         void setLineScale(double scale); //Sets the maximum line scale
714         void setScaleDist(double dist_nm); //Sets the distance where to start scaling the lines
715         void setStippleOutline(unsigned short stipple); //Sets the stipple pattern of the outline of the runway
716         void setStippleCenterline(unsigned short stipple); //Sets the stipple patter of the center line of the runway
717 };
718
719
720 //
721 // instr_scale           This class is an abstract base class for both moving
722 //                       scale and moving needle (fixed scale) indicators. It
723 // does not draw itself, but is not instanciable.
724 //
725
726 class instr_scale : public instr_item {
727 private:
728     float range_shown;   // Width Units.
729     float Maximum_value; //                ceiling.
730     float Minimum_value; // Representation floor.
731     float scale_factor;  // factor => screen units/range values.
732     UINT   Maj_div;       // major division marker units
733     UINT   Min_div;       // minor division marker units
734     UINT   Modulo;        // Roll over point
735     int    signif_digits; // digits to show to the right.
736
737 public:
738     instr_scale( int          x,
739                  int          y,
740                  UINT         width,
741                  UINT         height,
742                  FLTFNPTR     load_fn,
743                  UINT         options,
744                  float       show_range,
745                  float       max_value,
746                  float       min_value,
747                  float       disp_scaling,
748                  UINT         major_divs,
749                  UINT         minor_divs,
750                  UINT         rollover,
751                  int          dp_showing,
752                  bool         working = true);
753
754     virtual ~instr_scale();
755     instr_scale( const instr_scale & image);
756     instr_scale & operator = (const instr_scale & rhs);
757
758     virtual void draw   ( void ) {}; // No-op here. Defined in derived classes.
759     UINT   div_min      ( void ) { return Min_div;}
760     UINT   div_max      ( void ) { return Maj_div;}
761     float min_val      ( void ) { return Minimum_value;}
762     float max_val      ( void ) { return Maximum_value;}
763     UINT   modulo       ( void ) { return Modulo; }
764     float factor       ( void ) { return scale_factor;}
765     float range_to_show( void ) { return range_shown;}
766 };
767
768 // hud_card_               This class displays the indicated quantity on
769 //                         a scale that moves past the pointer. It may be
770 // horizontal or vertical, read above(left) or below(right) of the base
771 // line.
772
773 class hud_card : public instr_scale {
774 private:
775     float val_span;
776     string type;
777     float half_width_units;
778     bool  draw_tick_bottom;
779     bool  draw_tick_top;
780     bool  draw_tick_right;
781     bool  draw_tick_left;
782     bool  draw_cap_bottom;
783     bool  draw_cap_top;
784     bool  draw_cap_right;
785     bool  draw_cap_left;
786     float marker_offset;
787     bool  pointer;
788     string  pointer_type;
789     string  tick_type;
790     string  tick_length;
791     float   radius; //suma
792     float   maxValue; //suma
793     float   minValue; //suma
794     int         divisions; //suma
795     int     zoom; //suma
796     UINT        Maj_div; //suma
797     UINT        Min_div; //suma
798         
799     
800 public:
801     hud_card( int      x,
802               int      y,
803               UINT     width,
804               UINT     height,
805               FLTFNPTR load_fn,
806               UINT     options,
807               float    maxValue,
808               float    minValue,
809               float    disp_scaling,
810               UINT     major_divs,
811               UINT     minor_divs,
812               UINT     modulator,
813               int      dp_showing,
814               float    value_span,
815               string   type,
816               bool     draw_tick_bottom,
817               bool     draw_tick_top,
818               bool     draw_tick_right,
819               bool     draw_tick_left,
820               bool     draw_cap_bottom,
821               bool     draw_cap_top,
822               bool     draw_cap_right,
823               bool     draw_cap_left,
824               float    marker_offset,
825               bool     pointer,
826               string   pointer_type,
827               string  tick_type,
828               string  tick_length,
829               bool     working,
830               float    radius, //suma
831               int      divisions, //suma
832               int       zoom //suma
833             );
834
835
836     ~hud_card();
837     hud_card( const hud_card & image);
838     hud_card & operator = (const hud_card & rhs );
839     //    virtual void display_enable( bool setting );
840     virtual void draw( void );       // Required method in base class
841     void circles(float,float,float); // suma
842     void fixed(float,float,float,float,float,float); //suma
843     void zoomed_scale(int,int); //suma
844 };
845
846 typedef hud_card * pCardScale;
847
848 class gauge_instr : public instr_scale {
849 public:
850     gauge_instr( int       x,
851                  int       y,
852                  UINT      width,
853                  UINT      height,
854                  FLTFNPTR  load_fn,
855                  UINT      options,
856                  float     disp_scaling,
857                  float     maxValue,
858                  float     minValue,
859                  UINT      major_divs,
860                  UINT      minor_divs,
861                  int       dp_showing,
862                  UINT      modulus,
863                  bool      working);
864
865     ~gauge_instr();
866     gauge_instr( const gauge_instr & image);
867     gauge_instr & operator = (const gauge_instr & rhs );
868     virtual void draw( void );       // Required method in base class
869 };
870
871 typedef gauge_instr * pGaugeInst;
872 //
873 // dual_instr_item         This class was created to form the base class
874 //                         for both panel and HUD Turn Bank Indicators.
875
876 class dual_instr_item : public instr_item {
877 private:
878     FLTFNPTR alt_data_source;
879
880 public:
881     dual_instr_item ( int       x,
882                       int       y,
883                       UINT      width,
884                       UINT      height,
885                       FLTFNPTR  chn1_source,
886                       FLTFNPTR  chn2_source,
887                       bool      working,
888                       UINT      options );
889
890     virtual ~dual_instr_item() {};
891     dual_instr_item( const dual_instr_item & image);
892     dual_instr_item & operator = (const dual_instr_item & rhs );
893
894     float current_ch1( void ) { return (float)alt_data_source();}
895     float current_ch2( void ) { return (float)get_value();}
896     virtual void draw ( void ) { }
897 };
898
899 class fgTBI_instr : public dual_instr_item 
900 {
901 private:
902     UINT BankLimit;
903     UINT SlewLimit;
904     UINT scr_hole;
905     bool tsi;  //suma
906     float rad; //suma
907
908 public:
909     fgTBI_instr( int       x,
910                  int       y,
911                  UINT      width,
912                  UINT      height,
913                  FLTFNPTR  chn1_source,
914                  FLTFNPTR  chn2_source,
915                  float    maxBankAngle,
916                  float    maxSlipAngle,
917                  UINT      gap_width,
918                  bool      working,
919                  bool      tsi, //suma
920                  float     rad); //suma
921
922     fgTBI_instr( const fgTBI_instr & image);
923     fgTBI_instr & operator = (const fgTBI_instr & rhs );
924
925     ~fgTBI_instr();
926
927     UINT bank_limit( void ) { return BankLimit;}
928     UINT slew_limit( void ) { return SlewLimit;}
929
930     virtual void draw( void );       // Required method in base class
931 };
932
933 typedef fgTBI_instr * pTBI;
934
935 class HudLadder : public dual_instr_item {
936 private:
937     UINT   width_units;
938     int    div_units;
939     UINT   minor_div;
940     UINT   label_pos;
941     UINT   scr_hole;
942     float  vmax;
943     float  vmin;
944     float  factor;
945     string hudladder_type;
946     bool   frl;
947     bool   target_spot;
948     bool   velocity_vector;
949     bool   drift_marker;
950     bool   alpha_bracket;
951     bool        energy_marker;
952     bool        climb_dive_marker;
953     bool        glide_slope_marker;
954     float       glide_slope;
955     bool        energy_worm;
956     bool        waypoint_marker;
957     int     zenith; //suma
958     int     nadir; //suma
959     int         hat; //suma
960     
961
962     // The Ladder has it's own temporary display lists
963     fgTextList         TextList;
964     fgLineList         LineList;
965     fgLineList         StippleLineList;
966
967 public:
968     HudLadder( const string&    name,
969                int       x,
970                int       y,
971                UINT      width,
972                UINT      height,
973                float     factor,
974                FLTFNPTR  ptch_source,
975                FLTFNPTR  roll_source,
976                float     span_units,
977                float     division_units,
978                float     minor_division,
979                UINT      screen_hole,
980                UINT      lbl_pos,
981                bool      frl,
982                bool      target_spot,
983                bool     velocity_vector,
984                bool     drift_marker,
985                bool     alpha_bracket,
986                bool      energy_marker,
987                bool      climb_dive_marker,
988                bool      glide_slope_marker,
989                float     glide_slope,
990                bool      energy_worm,
991                bool      waypoint_marker,
992                bool  working,
993                int   zenith, //suma
994                int   nadir, //suma
995                int      hat
996              ); //suma
997
998
999     ~HudLadder();
1000
1001     HudLadder( const HudLadder & image );
1002     HudLadder & operator = ( const HudLadder & rhs );
1003     virtual void draw( void );
1004     void drawZenith(float,float,float); //suma
1005     void drawNadir(float, float, float); //suma
1006
1007     void Text( float x, float y, char *s)
1008     {
1009         TextList.add( fgText( x, y, s) );
1010     }
1011
1012     void Line( float x1, float y1, float x2, float y2)
1013     {
1014         LineList.add(fgLineSeg2D(x1,y1,x2,y2));
1015     }
1016
1017     void StippleLine( float x1, float y1, float x2, float y2)
1018     {
1019         StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
1020     }
1021 };
1022
1023
1024 //using namespace std;
1025 //deque <instr_item>  * Hdeque_ptr;
1026
1027 extern int  fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
1028 extern int  fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
1029 extern void fgUpdateHUD( void );
1030 extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1031                          GLfloat x_end, GLfloat y_end );
1032
1033 /*
1034 bool AddHUDInstrument( instr_item *pBlackBox );
1035 void DrawHUD ( void );
1036 bool DamageInstrument( INSTR_HANDLE unit );
1037 bool RepairInstrument( INSTR_HANDLE unit );
1038
1039
1040 void fgUpdateHUD ( Hptr hud );
1041 void fgUpdateHUD2( Hptr hud ); // Future use?
1042 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
1043 */
1044
1045
1046
1047
1048 class HUD_Properties : public SGPropertyChangeListener {
1049 public:
1050     HUD_Properties();
1051     void valueChanged(SGPropertyNode *n);
1052     void setColor() const;
1053     bool isVisible() const { return _visible; }
1054     bool isAntialiased() const { return _antialiased; }
1055
1056 private:
1057     float clamp(float f) { return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f; }
1058     vector<SGPropertyNode_ptr> _colors;
1059     SGPropertyNode_ptr _which;
1060     SGPropertyNode_ptr _brightness;
1061     SGPropertyNode_ptr _alpha;
1062     SGPropertyNode_ptr _visibility;
1063     SGPropertyNode_ptr _antialiasing;
1064     bool _visible, _antialiased;
1065     float _r, _g, _b, _a;
1066 };
1067
1068 #endif // _HUD_H