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