]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud.cxx
83c8757232ddc01c48d264661ceff81f27d90b31
[flightgear.git] / src / Cockpit / hud.cxx
1 // hud.cxx -- hud defines and prototypes
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - micheleamerica@geocities.com
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #ifdef HAVE_WINDOWS_H
29 #  include <windows.h>
30 #endif
31
32 #ifdef __BORLANDC__
33 #  define exception c_exception
34 #endif
35 #include <math.h>
36
37 #include <GL/glut.h>
38 #include <stdlib.h>
39 #include <string.h>
40
41 #include <simgear/constants.h>
42 #include <simgear/debug/logstream.hxx>
43 //#include <simgear/math/fg_random.h>
44 //#include <simgear/math/polar3d.hxx>
45
46 #include <Aircraft/aircraft.hxx>
47 #include <Autopilot/newauto.hxx>
48 #include <GUI/gui.h>
49 #include <Main/globals.hxx>
50 #ifdef FG_NETWORK_OLK
51 #include <NetworkOLK/network.h>
52 #endif
53 #include <Scenery/scenery.hxx>
54 //#include <Time/fg_timer.hxx>
55
56 #if defined ( __sun__ ) || defined ( __sgi )
57 extern "C" {
58   extern void *memmove(void *, const void *, size_t);
59 }
60 #endif
61
62 #include "hud.hxx"
63
64 static char units[5];
65
66 // The following routines obtain information concerning the aircraft's
67 // current state and return it to calling instrument display routines.
68 // They should eventually be member functions of the aircraft.
69 //
70
71 deque< instr_item * > HUD_deque;
72
73 fgTextList         HUD_TextList;
74 fgLineList         HUD_LineList;
75 fgLineList         HUD_StippleLineList;
76
77 fntRenderer *HUDtext = 0;
78 float  HUD_TextSize = 0;
79 int HUD_style = 0;
80
81 float HUD_matrix[16];
82 static float hud_trans_alpha = 0.67f;
83
84 void fgHUDalphaInit( void );
85
86 class locRECT {
87   public:
88     RECT rect;
89
90     locRECT( UINT left, UINT top, UINT right, UINT bottom);
91     RECT get_rect(void) { return rect;}
92 };
93
94 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
95 {
96   rect.left   =  left;
97   rect.top    =  top;
98   rect.right  =  right;
99   rect.bottom =  bottom;
100
101 }
102 // #define DEBUG
103
104 #ifdef OLD_CODE
105 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
106 {
107   glBegin(GL_LINES);
108   glVertex2f(x1, y1);
109   glVertex2f(x2, y2);
110   glEnd();
111 }
112
113 void drawOneLine( RECT &rect)
114 {
115   glBegin(GL_LINES);
116   glVertex2f(rect.left, rect.top);
117   glVertex2f(rect.right, rect.bottom);
118   glEnd();
119 }
120
121 //
122 // The following code deals with painting the "instrument" on the display
123 //
124    /* textString - Bitmap font string */
125
126 void textString( int x, int y, char *msg, void *font ){
127
128     if(*msg)
129     {
130 //      puDrawString (  NULL, msg, x, y );
131         glRasterPos2f(x, y);
132         while (*msg) {
133             glutBitmapCharacter(font, *msg);
134             msg++;
135         }
136     }
137 }
138
139
140 /* strokeString - Stroke font string */
141 void strokeString(int x, int y, char *msg, void *font, float theta)
142 {
143     int xx;
144     int yy;
145     int c;
146     float sintheta,costheta;
147     
148
149     if(*msg)
150     {
151     glPushMatrix();
152     glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
153     sintheta = sin(theta);
154     costheta = cos(theta);
155     xx = (int)(x * costheta + y * sintheta);
156     yy = (int)(y * costheta - x * sintheta);
157     glTranslatef( xx, yy, 0);
158     glScalef(.1, .1, 0.0);
159     while( (c=*msg++) ) {
160         glutStrokeCharacter(font, c);
161     }
162     glPopMatrix();
163     }
164 }
165
166 int getStringWidth ( char *str )
167 {
168     if ( HUDtext && str )
169     {
170         float r, l ;
171         guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
172         return FloatToInt( r - l );
173     }
174     return 0 ;
175 }
176 #endif // OLD_CODE
177
178 //========================= End of Class Implementations===================
179 // fgHUDInit
180 //
181 // Constructs a HUD object and then adds in instruments. At the present
182 // the instruments are hard coded into the routine. Ultimately these need
183 // to be defined by the aircraft's instrumentation records so that the
184 // display for a Piper Cub doesn't show the speed range of a North American
185 // mustange and the engine readouts of a B36!
186 //
187
188 #define INSTRDEFS 21
189
190 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
191 {
192     instr_item *HIptr;
193     //  int index;
194
195     // $$$ begin - added VS Renganathan
196 #ifdef FIGHTER_HUD
197     //  int off = 400;
198     int min_x = 200; 
199     int max_x = 440; 
200     //  int min_y = 100;
201     int max_y = 380; 
202     int cen_x = 320;
203     int cen_y = 240;
204     unsigned int text_h = 10;
205     unsigned int ladr_w2 = 60;
206     int ladr_h2 = 90;
207     int ladr_t = 35;
208     int compass_w = 120;
209     int gap = 10;
210 #else
211     // $$$ end - added VS Renganathan
212
213     //  int off = 50;
214     int min_x = 25; //off/2;
215     int max_x = 615; //640-(off/2);
216     //  int min_y = off;
217     int max_y = 430; //480-off;
218     int cen_x = 320;
219     int cen_y = 240;
220     unsigned int text_h = 10;
221     unsigned int ladr_w2 = 60;
222     int ladr_h2 = 90;
223     int ladr_t = 35;
224     int compass_w = 200;
225     int gap = 10;
226 #endif
227
228 //  int font_size = globals->get_options()->get_xsize() / 60;
229   int font_size = (globals->get_options()->get_xsize() > 1000) ? LARGE : SMALL;
230   
231   HUD_style = 1;
232
233   FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
234
235 //  deque < instr_item * > :: iterator first = HUD_deque.begin();
236 //  deque < instr_item * > :: iterator last = HUD_deque.end();
237 //  HUD_deque.erase( first, last);  // empty the HUD deque  
238
239   HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());  // empty the HUD deque
240
241 //  hud->code = 1;
242 //  hud->status = 0;
243
244   // For now lets just hardcode the hud here.
245   // In the future, hud information has to come from the same place
246   // aircraft information came from.
247
248 //  fgHUDSetTimeMode( hud, NIGHT );
249 //  fgHUDSetBrightness( hud, BRT_LIGHT );
250
251 //      case 0:     // TBI
252 //  int x = 290; /*cen_x-30*/
253 //  int y = 45;  /*off-5*/
254 //  HIptr = (instr_item *) new fgTBI_instr( x, y, ladr_w2, text_h );
255 // $$$ begin - added, VS Renganathan 13 Oct 2K
256 #ifdef FIGHTER_HUD
257 //      case 1:     // Artificial Horizon
258   HIptr = (instr_item *) new HudLadder( cen_x-ladr_w2, cen_y-ladr_h2,
259                                         2*ladr_w2, 2*ladr_h2 );
260   HUD_deque.insert( HUD_deque.begin(), HIptr);
261
262 //      case 4:    // GYRO COMPASS
263   HIptr = (instr_item *) new hud_card( cen_x-(compass_w/2),
264                                        cen_y+8.0,  //CENTER_DIAMOND_SIZE
265                                        compass_w,
266                                        28,
267                                        get_heading,
268                                        HUDS_TOP,
269                                        360, 0,
270                                        1.0,
271                                        10,   1,
272                                        360,
273                                        0,
274                                        25,
275                                        true);
276   HUD_deque.insert( HUD_deque.begin(), HIptr);
277
278 //      case 10:    // Digital KIAS
279         HIptr = (instr_item *) new instr_label ( cen_x-190,
280                                                  cen_y+25,
281                                                   40,
282                                                   30,
283                                                  get_speed,
284                                                  "%5.0f",
285                                                  NULL,
286                                                  " ",
287                                                  1.0,
288                                                  HUDS_TOP,
289                                                  RIGHT_JUST,
290                                                  font_size,
291                                                  0,
292                                                  TRUE );
293   HUD_deque.insert( HUD_deque.begin(), HIptr);
294 // Mach no
295         HIptr = (instr_item *) new instr_label ( cen_x-180,
296                                                  cen_y+5,
297                                                   40,
298                                                   30,
299                                                  get_mach,
300                                                  "%5.2f",
301                                                  NULL,
302                                                  " ",
303                                                  1.0,
304                                                  HUDS_TOP,
305                                                  RIGHT_JUST,
306                                                  font_size,
307                                                  0,
308                                                  TRUE );
309   HUD_deque.insert( HUD_deque.begin(), HIptr);
310 // Pressure Altitude
311         HIptr = (instr_item *) new instr_label ( cen_x+110,
312                                                  cen_y+25,
313                                                   40,
314                                                   30,
315                                                  get_altitude,
316                                                  "%5.0f",
317                                                  NULL,
318                                                  " ",
319                                                  1.0,
320                                                  HUDS_TOP,
321                                                  LEFT_JUST,
322                                                  font_size,
323                                                  0,
324                                                  TRUE );
325   HUD_deque.insert( HUD_deque.begin(), HIptr);
326 // Radio Altitude
327         HIptr = (instr_item *) new instr_label ( cen_x+110,
328                                                  cen_y+5,
329                                                   40,
330                                                   30,
331                                                  get_agl,
332                                                  "%5.0f",
333                                                  NULL,
334                                                  " R",
335                                                  1.0,
336                                                  HUDS_TOP,
337                                                  LEFT_JUST,
338                                                  font_size,
339                                                  0,
340                                                  TRUE );
341   HUD_deque.insert( HUD_deque.begin(), HIptr);
342
343 //      case 2:    // AOA
344   HIptr = (instr_item *) new hud_card( cen_x-145.0, //min_x +18,
345                                        cen_y-190,
346                                        28,
347                                        120,
348                                        get_aoa,
349                                        HUDS_LEFT | HUDS_VERT,
350 //                                       HUDS_RIGHT | HUDS_VERT,                                     
351                                        30.0, -15.0,
352                                        1.0,
353                                        10,  2,
354                                        0,
355                                        0,
356                                        60.0,
357                                        true);
358   HUD_deque.insert( HUD_deque.begin(), HIptr);
359 //      case 2:    // normal acceleration at cg, g's
360   HIptr = (instr_item *) new hud_card( cen_x-185, //min_x +18,
361                                        cen_y-220,
362                                        18,
363                                        130,
364                                        get_anzg,
365                                        HUDS_LEFT | HUDS_VERT,
366 //                                       HUDS_RIGHT | HUDS_VERT,                                     
367                                        10.0, -5.0,
368                                        1.0,
369                                        2,  1,
370                                        0,
371                                        0,
372                                        20.0,
373                                        true);
374   HUD_deque.insert( HUD_deque.begin(), HIptr);
375 //      case 2:    // VSI
376   HIptr = (instr_item *) new hud_card( (2*cen_x)-195.0, //min_x +18,
377                                        cen_y-190,
378                                        28,
379                                        120,
380                                        get_climb_rate, //fix
381 //                                       HUDS_LEFT | HUDS_VERT,
382                                        HUDS_RIGHT | HUDS_VERT,                                     
383                                        500.0, -500.0,
384                                        1.0,
385                                        5,  1,
386                                        0,
387                                        0,
388                                        15.0,
389                                        true);
390   HUD_deque.insert( HUD_deque.begin(), HIptr);
391
392
393 // Aux parameter 16 - xposn
394         HIptr = (instr_item *) new instr_label ( cen_x+170,
395                                                  cen_y+200,
396                                                   40,
397                                                   30,
398                                                  get_aux16,
399                                                  "%5.1f",
400                                                  NULL,
401                                                  " pstick",
402                                                  1.0,
403                                                  HUDS_TOP,
404                                                  LEFT_JUST,
405                                                  font_size,
406                                                  0,
407                                                  TRUE );
408   HUD_deque.insert( HUD_deque.begin(), HIptr);
409   
410
411 // Aux parameter 17 - xposn
412         HIptr = (instr_item *) new instr_label ( cen_x+170,
413                                                  cen_y+190,
414                                                   40,
415                                                   30,
416                                                  get_aux17,
417                                                  "%5.1f",
418                                                  NULL,
419                                                  " rstick",
420                                                  1.0,
421                                                  HUDS_TOP,
422                                                  LEFT_JUST,
423                                                  font_size,
424                                                  0,
425                                                  TRUE );
426   HUD_deque.insert( HUD_deque.begin(), HIptr);
427   
428   
429   
430   
431   
432   
433   
434 // Aux parameter 1 - xposn
435         HIptr = (instr_item *) new instr_label ( cen_x+240,
436                                                  cen_y+200,
437                                                   40,
438                                                   30,
439                                                  get_aux1,
440                                                  "%5.0f",
441                                                  NULL,
442                                                  " m",
443                                                  1.0,
444                                                  HUDS_TOP,
445                                                  LEFT_JUST,
446                                                  font_size,
447                                                  0,
448                                                  TRUE );
449   HUD_deque.insert( HUD_deque.begin(), HIptr);
450
451 // Aux parameter 2 - pla
452         HIptr = (instr_item *) new instr_label ( cen_x+240,
453                                                  cen_y+190,
454                                                   40,
455                                                   30,
456                                                  get_aux9,
457                                                  "%5.0f",
458                                                  NULL,
459                                                  " pla",
460                                                  1.0,
461                                                  HUDS_TOP,
462                                                  LEFT_JUST,
463                                                  font_size,
464                                                  0,
465                                                  TRUE );
466   HUD_deque.insert( HUD_deque.begin(), HIptr);
467
468 // Aux parameter 3 - xtd
469         HIptr = (instr_item *) new instr_label ( cen_x+240,
470                                                  cen_y+170,
471                                                   40,
472                                                   30,
473                                                  get_aux11,
474                                                  "%5.1f",
475                                                  NULL,
476                                                  " xtd",
477                                                  1.0,
478                                                  HUDS_TOP,
479                                                  LEFT_JUST,
480                                                  font_size,
481                                                  0,
482                                                  TRUE );
483   HUD_deque.insert( HUD_deque.begin(), HIptr);
484
485 // Aux parameter 4 - ytd
486         HIptr = (instr_item *) new instr_label ( cen_x+240,
487                                                  cen_y+160,
488                                                   40,
489                                                   30,
490                                                  get_aux12,
491                                                  "%5.1f",
492                                                  NULL,
493                                                  " ytd",
494                                                  1.0,
495                                                  HUDS_TOP,
496                                                  LEFT_JUST,
497                                                  font_size,
498                                                  0,
499                                                  TRUE );
500   HUD_deque.insert( HUD_deque.begin(), HIptr);
501
502 // Aux parameter 5 - nztd
503         HIptr = (instr_item *) new instr_label ( cen_x+240,
504                                                  cen_y+150,
505                                                   40,
506                                                   30,
507                                                  get_aux10,
508                                                  "%5.1f",
509                                                  NULL,
510                                                  " nztd",
511                                                  1.0,
512                                                  HUDS_TOP,
513                                                  LEFT_JUST,
514                                                  font_size,
515                                                  0,
516                                                  TRUE );
517   HUD_deque.insert( HUD_deque.begin(), HIptr);
518
519 // Aux parameter 6 - vvtd
520         HIptr = (instr_item *) new instr_label ( cen_x+240,
521                                                  cen_y+140,
522                                                   40,
523                                                   30,
524                                                  get_aux13,
525                                                  "%5.1f",
526                                                  NULL,
527                                                  " vvtd",
528                                                  1.0,
529                                                  HUDS_TOP,
530                                                  LEFT_JUST,
531                                                  font_size,
532                                                  0,
533                                                  TRUE );
534   HUD_deque.insert( HUD_deque.begin(), HIptr);
535
536 // Aux parameter 7 - vtd
537         HIptr = (instr_item *) new instr_label ( cen_x+240,
538                                                  cen_y+130,
539                                                   40,
540                                                   30,
541                                                  get_aux14,
542                                                  "%5.1f",
543                                                  NULL,
544                                                  " vtd",
545                                                  1.0,
546                                                  HUDS_TOP,
547                                                  LEFT_JUST,
548                                                  font_size,
549                                                  0,
550                                                  TRUE );
551   HUD_deque.insert( HUD_deque.begin(), HIptr);
552
553 // Aux parameter 8 - alftd
554         HIptr = (instr_item *) new instr_label ( cen_x+240,
555                                                  cen_y+120,
556                                                   40,
557                                                   30,
558                                                  get_aux15,
559                                                  "%5.1f",
560                                                  NULL,
561                                                  " alftd",
562                                                  1.0,
563                                                  HUDS_TOP,
564                                                  LEFT_JUST,
565                                                  font_size,
566                                                  0,
567                                                  TRUE );
568   HUD_deque.insert( HUD_deque.begin(), HIptr);
569
570 // Aux parameter 9 - fnr
571         HIptr = (instr_item *) new instr_label ( cen_x+240,
572                                                  cen_y+100,
573                                                   40,
574                                                   30,
575                                                  get_aux8,
576                                                  "%5.1f",
577                                                  NULL,
578                                                  " fnose",
579                                                  1.0,
580                                                  HUDS_TOP,
581                                                  LEFT_JUST,
582                                                  font_size,
583                                                  0,
584                                                  TRUE );
585   HUD_deque.insert( HUD_deque.begin(), HIptr);
586
587 // Aux parameter 10 - Ax
588         HIptr = (instr_item *) new instr_label ( cen_x+240,
589                                                  cen_y+90,
590                                                   40,
591                                                   30,
592                                                  get_Ax,
593                                                  "%5.2f",
594                                                  NULL,
595                                                  " Ax",
596                                                  1.0,
597                                                  HUDS_TOP,
598                                                  LEFT_JUST,
599                                                  font_size,
600                                                  0,
601                                                  TRUE );
602   HUD_deque.insert( HUD_deque.begin(), HIptr);
603 #else
604 // $$$ end - added , VS Renganathan 13 Oct 2K
605
606   HIptr = (instr_item *) new fgTBI_instr( 290, 45, 60, 10 );  
607   HUD_deque.insert( HUD_deque.begin(), HIptr);
608
609 //      case 1:     // Artificial Horizon
610   HIptr = (instr_item *) new HudLadder( cen_x-ladr_w2, cen_y-ladr_h2,
611                                         2*ladr_w2, 2*ladr_h2 );
612   HUD_deque.insert( HUD_deque.begin(), HIptr);
613
614 //      case 4:    // GYRO COMPASS
615   HIptr = (instr_item *) new hud_card( cen_x-(compass_w/2),
616                                        max_y,
617                                        compass_w,
618                                        28,
619                                        get_heading,
620                                        HUDS_TOP,
621                                        360, 0,
622                                        1.0,
623                                        5,   1,
624                                        360,
625                                        0,
626                                        25,
627                                        true);
628   HUD_deque.insert( HUD_deque.begin(), HIptr);
629
630 //      case 5:    // AMSL
631   HIptr = (instr_item *) new hud_card( max_x - 35 -15, // 15 to balance speed card
632                                        cen_y-(compass_w/2),
633                                        35,
634                                        compass_w,
635                                        get_altitude,
636 //                                     HUDS_RIGHT | HUDS_VERT,
637                                        HUDS_LEFT | HUDS_VERT,
638                                        5000, -1000,
639                                        1.0,
640                                        100,  25,
641                                        0,
642                                        0,
643                                        250,
644                                        true);
645   HUD_deque.insert( HUD_deque.begin(), HIptr);
646
647 //      case 6:
648   HIptr = (instr_item *) new  guage_instr( cen_x-50,            // x
649                                            cen_y + ladr_h2 -20,  // y
650                                            100,            // width
651                                            20,            // height
652                                            get_aileronval, // data source
653                                            HUDS_BOTTOM | HUDS_NOTEXT,
654                                            100.0,
655                                            +1.0,
656                                            -1.0);
657   HUD_deque.insert( HUD_deque.begin(), HIptr);
658
659 //      case 3:    // Radio Altimeter
660   HIptr = (instr_item *) new hud_card( cen_x + ladr_w2 + gap + 13 + ladr_t,
661                                        cen_y-75,
662                                        25,
663                                        150,
664                                        get_agl,
665                                        HUDS_LEFT | HUDS_VERT,
666                                        1000, 0,
667                                        1.0,
668                                        25, 5,
669                                        0,
670                                        0,
671                                        200.0,
672                                        true);
673   HUD_deque.insert( HUD_deque.begin(), HIptr);
674
675 //      case 7:
676   HIptr = (instr_item *) new  guage_instr( cen_x -ladr_w2 -gap -13 -20 -ladr_t,
677                                            cen_y-50,             // y
678                                            20,             // width
679                                            100,             // height
680                                            get_elevatorval, // data source
681                                            HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
682                                            -100.0,           // Scale data
683                                            +1.0,           // Data Range
684                                            -1.0);
685   HUD_deque.insert( HUD_deque.begin(), HIptr);
686
687 //      case 8:
688   HIptr = (instr_item *) new  guage_instr( cen_x-50,             // x
689                                            cen_y -gap -ladr_w2 -20, //-85   // y
690                                            100,             // width
691                                            20,             // height
692                                            get_rudderval,   // data source
693                                            HUDS_TOP | HUDS_NOTEXT,
694                                            100.0,
695                                            +1.0,
696                                            -1.0);
697   HUD_deque.insert( HUD_deque.begin(), HIptr);
698
699 //      case 2:    // KIAS
700   HIptr = (instr_item *) new hud_card( min_x +10 +5, //min_x +18,
701                                        cen_y-(compass_w/2),
702                                        28,
703                                        compass_w,
704                                        get_speed,
705 //                                     HUDS_LEFT | HUDS_VERT,
706                                        HUDS_RIGHT | HUDS_VERT,                                     
707                                        200.0, 0.0,
708                                        1.0,
709                                        10,  5,
710                                        0,
711                                        0,
712                                        50.0,
713                                        true);
714
715   
716  
717   HUD_deque.insert( HUD_deque.begin(), HIptr);
718     
719
720 //      case 10:    // Digital Mach number
721         HIptr = (instr_item *) new instr_label ( min_x , //same as speed tape
722                                                  cen_y-(compass_w/2) -10, //below speed tape
723                                                   40,
724                                                   30,
725                                                  get_mach,
726                                                  "%4.2f",
727                                                  "",
728                                                  NULL,
729                                                  1.0,
730                                                  HUDS_TOP,
731                                                  RIGHT_JUST,
732                                                  font_size,
733                                                  0,
734                                                  TRUE );
735   HUD_deque.insert( HUD_deque.begin(), HIptr);
736
737 //      case 9:
738   HIptr = (instr_item *) new  guage_instr( min_x-10,           // x
739                                            cen_y -75,       // y 
740                                            20,              // width
741                                            150,             // height
742                                            get_throttleval, // data source
743 //                                         HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
744                                            HUDS_VERT | HUDS_LEFT | HUDS_NOTEXT,                                        100.0,
745                                            1.0,
746                                            0.0
747                                           );
748   HUD_deque.insert( HUD_deque.begin(), HIptr);
749 #endif
750 // Remove this when below uncommented       
751 //      case 10:
752   HIptr = (instr_item *) new instr_label( 10,
753                                           25,
754                                           60,
755                                           10,
756                                           get_frame_rate,
757                                           "%5.1f",
758                                           "",
759                                           NULL,
760                                           1.0,
761                                           HUDS_TOP,
762                                           RIGHT_JUST,
763                                           font_size,
764                                           0,
765                                           TRUE );
766   HUD_deque.insert( HUD_deque.begin(), HIptr);
767   
768 // $$$ begin - added VS Renganthan 19 Oct 2K
769 #ifdef FIGHTER_HUD
770   HIptr = (instr_item *) new lat_label(  70,
771                                           40,    
772                                           1,
773                                           text_h,
774                                           get_latitude,
775                                           "%s%", //"%.0f",
776                                           "", //"Lat ",
777                                           "",
778                                           1.0,
779                                           HUDS_TOP,
780                                           CENTER_JUST,
781                                           font_size,
782                                           0,
783                                           TRUE );
784   HUD_deque.insert( HUD_deque.begin(), HIptr);
785     
786     HIptr = (instr_item *) new lon_label( 475,
787                                           40,
788                                           1, text_h,
789                                           get_longitude,
790                                           "%s%",//"%.0f",
791                                           "", //"Lon ", 
792                                           "",
793                                           1.0,
794                                           HUDS_TOP,
795                                           CENTER_JUST,
796                                           font_size,
797                                           0,
798                                           TRUE );
799   HUD_deque.insert( HUD_deque.begin(), HIptr);
800 #else
801     HIptr = (instr_item *) new lat_label(  (cen_x - (compass_w/2))/2,
802                                           max_y,    
803                                           1,
804                                           text_h,
805                                           get_latitude,
806                                           "%s%", //"%.0f",
807                                           "", //"Lat ",
808                                           "",
809                                           1.0,
810                                           HUDS_TOP,
811                                           CENTER_JUST,
812                                           font_size,
813                                           0,
814                                           TRUE );
815   HUD_deque.insert( HUD_deque.begin(), HIptr);
816     
817     HIptr = (instr_item *) new lon_label(((cen_x+compass_w/2)+(2*cen_x))/2,
818                                           max_y,
819                                           1, text_h,
820                                           get_longitude,
821                                           "%s%",//"%.0f",
822                                           "", //"Lon ", 
823                                           "",
824                                           1.0,
825                                           HUDS_TOP,
826                                           CENTER_JUST,
827                                           font_size,
828                                           0,
829                                           TRUE );
830   HUD_deque.insert( HUD_deque.begin(), HIptr);
831 #endif
832 // $$$ end - added VS Renganthan 19 Oct 2K
833 /*
834 //      case 10:    // Digital KIAS
835         HIptr = (instr_item *) new instr_label ( 110,
836                                                  150,
837                                                   40,
838                                                   30,
839                                                  get_speed,
840                                                  "%5.0f",
841                                                  NULL,
842                                                  " Kts",
843                                                  1.0,
844                                                  HUDS_TOP,
845                                                  RIGHT_JUST,
846                                                  font_size,
847                                                  0,
848                                                  TRUE );
849   HUD_deque.insert( HUD_deque.begin(), HIptr);
850
851 //      case 11:    // Digital Rate of Climb
852         HIptr = (instr_item *) new instr_label ( 110,
853                                                  135,
854                                                   40,
855                                                   10,
856                                                  get_climb_rate,
857                                                  "%5.0f",
858                                                  " Climb",
859                                                  NULL,
860                                                  1.0,
861                                                  HUDS_TOP,
862                                                  RIGHT_JUST,
863                                                  font_size,
864                                                  0,
865                                                  TRUE );
866   HUD_deque.insert( HUD_deque.begin(), HIptr);
867
868 //      case 12:    // Roll indication diagnostic
869         HIptr = (instr_item *) new instr_label ( 110,
870                                                  120,
871                                                   40,
872                                                   10,
873                                                  get_roll,
874                                                  "%5.2f",
875                                                  " Roll",
876                                                  " Deg",
877                                                  1.0,
878                                                  HUDS_TOP,
879                                                  RIGHT_JUST,
880                                                  font_size,
881                                                  0,
882                                                  TRUE );
883   HUD_deque.insert( HUD_deque.begin(), HIptr);
884
885 //      case 13:    // Angle of attack diagnostic
886         HIptr = (instr_item *) new instr_label ( 440,
887                                                  150,
888                                                   60,
889                                                   10,
890                                                  get_aoa,
891                                                  "      %5.2f",
892                                                  "AOA",
893                                                  " Deg",
894                                                  1.0,
895                                                  HUDS_TOP,
896                                                  RIGHT_JUST,
897                                                  font_size,
898                                                  0,
899                                                  TRUE );
900   HUD_deque.insert( HUD_deque.begin(), HIptr);
901
902 //      case 14:
903         HIptr = (instr_item *) new instr_label ( 440,
904                                                  135,
905                                                   60,
906                                                   10,
907                                                  get_heading,
908                                                  " %5.1f",
909                                                  "Heading ",
910                                                  " Deg",
911                                                  1.0,
912                                                  HUDS_TOP,
913                                                  RIGHT_JUST,
914                                                  font_size,
915                                                  0,
916                                                  TRUE );
917   HUD_deque.insert( HUD_deque.begin(), HIptr);
918
919 //      case 15:
920         HIptr = (instr_item *) new instr_label ( 440,
921                                                  120,
922                                                   60,
923                                                   10,
924                                                  get_sideslip,
925                                                  "%5.2f",
926                                                  "Sideslip ",
927                                                  NULL,
928                                                  1.0,
929                                                  HUDS_TOP,
930                                                  RIGHT_JUST,
931                                                  font_size,
932                                                  0,
933                                                  TRUE );
934   HUD_deque.insert( HUD_deque.begin(), HIptr);
935
936 //      case 16:
937         HIptr = (instr_item *) new instr_label( 440,
938                                                 100,
939                                                  60,
940                                                  10,
941                                                 get_throttleval,
942                                                 "%5.2f",
943                                                 "Throttle ",
944                                                 NULL,
945                                                  1.0,
946                                                 HUDS_TOP,
947                                                 RIGHT_JUST,
948                                                 font_size,
949                                                 0,
950                                                 TRUE );
951   HUD_deque.insert( HUD_deque.begin(), HIptr);
952
953 //      case 17:
954         HIptr = (instr_item *) new instr_label( 440,
955                                                  85,
956                                                  60,
957                                                  10,
958                                                 get_elevatorval,
959                                                 "%5.2f",
960                                                 "Elevator ",
961                                                 NULL,
962                                                  1.0,
963                                                 HUDS_TOP,
964                                                 RIGHT_JUST,
965                                                 font_size,
966                                                 0,
967                                                 TRUE );
968   HUD_deque.insert( HUD_deque.begin(), HIptr);
969
970 //      case 18:
971         HIptr = (instr_item *) new instr_label( 440,
972                                                  60,
973                                                  60,
974                                                  10,
975                                                 get_aileronval,
976                                                 "%5.2f",
977                                                 "Aileron  ",
978                                                 NULL,
979                                                  1.0,
980                                                 HUDS_TOP,
981                                                 RIGHT_JUST,
982                                                 font_size,
983                                                 0,
984                                                 TRUE );
985   HUD_deque.insert( HUD_deque.begin(), HIptr);
986
987 //      case 19:
988         HIptr = (instr_item *) new instr_label( 10,
989                                                 10,
990                                                 60,
991                                                 10,
992                                                  get_frame_rate,
993                                                 "%.1f",
994                                                 "Frame rate = ",
995                                                 NULL,
996                                                  1.0,
997                                                 HUDS_TOP,
998                                                 RIGHT_JUST,
999                                                 font_size,
1000                                                 0,
1001                                                 TRUE );
1002   HUD_deque.insert( HUD_deque.begin(), HIptr);
1003
1004 //      case 20:
1005       switch( globals->get_options()->get_tris_or_culled() ) {
1006       case 0:
1007           HIptr = (instr_item *) new instr_label( 10,
1008                               25,
1009                               120,
1010                               10,
1011                               get_vfc_tris_drawn,
1012                               "%.0f",
1013                               "Tris Rendered = ",
1014                               NULL,
1015                               1.0,
1016                               HUDS_TOP,
1017                               RIGHT_JUST,
1018                               font_size,
1019                               0,
1020                               TRUE );
1021           break;
1022       case 1:
1023           HIptr = (instr_item *) new instr_label( 10,
1024                               25,
1025                               90,
1026                               10,
1027                               get_vfc_ratio,
1028                               "%.2f",
1029                               "VFC Ratio = ",
1030                               NULL,
1031                               1.0,
1032                               HUDS_TOP,
1033                               RIGHT_JUST,
1034                               font_size,
1035                               0,
1036                               TRUE );
1037           break;
1038       }
1039       break;
1040
1041 //      case 21:
1042         HIptr = (instr_item *) new instr_label( 10,
1043                                                 40,
1044                                                 90,
1045                                                 10,
1046                                                 get_fov,
1047                                                 "%.1f",
1048                                                 "FOV = ",
1049                                                 NULL,
1050                         1.0,
1051                                                 HUDS_TOP,
1052                                                 RIGHT_JUST,
1053                                                 font_size,
1054                                                 0,
1055                                                 TRUE );
1056   HUD_deque.insert( HUD_deque.begin(), HIptr);
1057 */
1058 //      default:
1059 //        HIptr = 0;;
1060 //      }
1061 //    if( HIptr ) {                   // Anything to install?
1062 //      HUD_deque.insert( HUD_deque.begin(), HIptr);
1063 //      }
1064 //    index++;
1065 //    }
1066 //  while( HIptr );
1067
1068   fgHUDalphaInit();
1069   fgHUDReshape();
1070    return 0;  // For now. Later we may use this for an error code.
1071
1072 }
1073
1074 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
1075 {
1076 //    instr_item *HIptr;
1077 //    int index;
1078
1079     int off = 50;
1080 //  int min_x = off;
1081 //  int max_x = 640-off;
1082 //  int min_y = off;
1083     int max_y = 480-off;
1084     int cen_x = 640 / 2;
1085     int cen_y = 480 / 2;
1086     int text_h = 10;
1087     int ladr_w2 = 60;
1088     int ladr_h2 = 90;
1089 //  int ladr_t = 35;
1090     int compass_w = 200;
1091 //  int gap = 10;
1092
1093 //      int font_size = globals->get_options()->get_xsize() / 60;
1094     int font_size = (globals->get_options()->get_xsize() > 1000) ? LARGE : SMALL;
1095
1096     HUD_style = 2;
1097
1098     FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
1099
1100 //  deque < instr_item * > :: iterator first = HUD_deque.begin();
1101 //  deque < instr_item * > :: iterator last = HUD_deque.end();
1102 //  HUD_deque.erase( first, last);  // empty the HUD deque  
1103     HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
1104
1105     //  hud->code = 1;
1106     //  hud->status = 0;
1107
1108     // For now lets just hardcode the hud here.
1109     // In the future, hud information has to come from the same place
1110     // aircraft information came from.
1111
1112     //  fgHUDSetTimeMode( hud, NIGHT );
1113     //  fgHUDSetBrightness( hud, BRT_LIGHT );
1114
1115     //  index = 0;
1116 //    index = 19;  
1117
1118     instr_item* p;
1119
1120     p = new HudLadder( cen_x-ladr_w2, cen_y-ladr_h2, 2*ladr_w2, 2*ladr_h2, 1 );
1121     HUD_deque.push_front( p );
1122
1123 //      case 4:    // GYRO COMPASS
1124     p =new hud_card( cen_x-(compass_w/2),
1125                      max_y,
1126                      compass_w,
1127                      28,
1128                      get_view_direction,
1129                      HUDS_TOP,
1130                      360, 0,
1131                      1.0,
1132                      5,   1,
1133                      360,
1134                      0,
1135                      25,
1136                      true);
1137     HUD_deque.push_front( p );
1138
1139     p = new lat_label( (cen_x - compass_w/2)/2,
1140                        max_y,
1141                        0, text_h,
1142                        get_latitude,
1143                        "%s%", //"%.0f",
1144                        "", //"Lat ",
1145                        "",
1146                        1.0,
1147                        HUDS_TOP,
1148                        CENTER_JUST,
1149                        font_size,
1150                        0,
1151                        TRUE );
1152     HUD_deque.push_front( p );
1153     
1154 //    p = new instr_label( 140, 450, 60, 10,
1155 //           get_lat_min,
1156 //           "%05.2f",
1157 //           "",
1158 //           NULL,
1159 //           1.0,
1160 //           HUDS_TOP,
1161 //           CENTER_JUST,
1162 //           font_size,
1163 //           0,
1164 //           TRUE );
1165 //    HUD_deque.push_front( p );
1166     
1167     p = new lon_label(((cen_x+compass_w/2)+(2*cen_x))/2,
1168                        max_y,
1169                        1, text_h,
1170                        get_longitude,
1171                        "%s%",//"%.0f",
1172                        "", //"Lon ",
1173                        "",
1174                        1.0,
1175                        HUDS_TOP,
1176                        CENTER_JUST,
1177                        font_size,
1178                        0,
1179                        TRUE );
1180     HUD_deque.push_front( p );
1181     
1182     int x_pos = 40;
1183     
1184     p = new instr_label( x_pos, 25, 60, 10,
1185                          get_frame_rate,
1186                          "%7.1f",
1187                          "Frame rate =",
1188                          NULL,
1189                          1.0,
1190                          HUDS_TOP,
1191                          LEFT_JUST,
1192                          font_size,
1193                          0, 
1194                          TRUE );
1195     HUD_deque.push_front( p );
1196 #if 0
1197     p = new instr_label( x_pos, 40, 120, 10,
1198                          get_vfc_tris_culled,
1199                          "%7.0f",
1200                          "Culled       =",
1201                          NULL,
1202                          1.0,
1203                          HUDS_TOP,
1204                          LEFT_JUST,
1205                          font_size,
1206                          0,
1207                          TRUE );
1208     HUD_deque.push_front( p );
1209
1210     p = new instr_label( x_pos, 55, 120, 10,
1211                          get_vfc_tris_drawn,
1212                          "%7.0f",
1213                          "Rendered   =",
1214                          NULL,
1215                          1.0,
1216                          HUDS_TOP,
1217                          LEFT_JUST,
1218                          font_size,
1219                          0,
1220                          TRUE );
1221     HUD_deque.push_front( p );
1222 #endif // 0
1223         
1224 //    p = new instr_label( x_pos, 70, 90, 10,
1225     p = new instr_label( x_pos, 40, 90, 10,
1226                          get_fov,
1227                          "%7.1f",
1228                          "FOV          = ",
1229                          NULL,
1230                          1.0,
1231                          HUDS_TOP,
1232                          LEFT_JUST,
1233                          font_size,
1234                          0,
1235                          TRUE );
1236     HUD_deque.push_front( p );
1237
1238     x_pos = 480;
1239     
1240     p = new instr_label ( x_pos,
1241                           70,
1242                           60,
1243                           10,
1244                           get_aoa,
1245                           "%7.2f",
1246                           "AOA      ",
1247                           " Deg",
1248                           1.0,
1249                           HUDS_TOP,
1250                           LEFT_JUST,
1251                           font_size,
1252                           0,
1253                           TRUE );
1254     HUD_deque.push_front( p );
1255
1256     p = new instr_label( x_pos, 55, 40, 30,
1257                          get_speed,
1258                          "%5.0f",
1259                          "Airspeed ",
1260                          " Kts",
1261                          1.0,
1262                          HUDS_TOP,
1263                          LEFT_JUST,
1264                          font_size,
1265                          0,
1266                          TRUE );
1267     HUD_deque.push_front( p );
1268
1269     if ( globals->get_options()->get_units() == FGOptions::FG_UNITS_FEET ) {
1270     strcpy(units, " ft");
1271     } else {
1272     strcpy(units, " m");
1273     }
1274     p = new instr_label( x_pos, 40, 40, 10,
1275              get_altitude,
1276              "%5.0f",
1277              "Altitude ",
1278              units,
1279              1.0,
1280              HUDS_TOP,
1281              LEFT_JUST,
1282              font_size,
1283              0,
1284              TRUE );
1285     HUD_deque.push_front( p );
1286
1287     p = new instr_label( x_pos, 25, 40, 10,
1288              get_agl,
1289              "%5.0f",
1290              "Elvation ",
1291              units,
1292              1.0,
1293              HUDS_TOP,
1294              LEFT_JUST,
1295              font_size,
1296              0,
1297              TRUE );
1298     HUD_deque.push_front( p );
1299
1300     p = new instr_label( x_pos, 10, 60, 10,
1301              get_heading,
1302              "%5.1f",
1303              "Heading  ",
1304              " Deg",
1305              1.0,
1306              HUDS_TOP,
1307              LEFT_JUST,
1308              font_size,
1309              0,
1310              TRUE );
1311     HUD_deque.push_front( p );
1312
1313     p = new fgTBI_instr( 290, 55, 60, 10 ); // 270
1314     HUD_deque.push_front( p );
1315     
1316     p = new  guage_instr( 270, //250,            // x
1317                           390, //360, //400, //45, //420,            // y
1318                           100,            // width
1319                           20,            // height
1320                           get_aileronval, // data source
1321                           HUDS_BOTTOM | HUDS_NOTEXT,
1322                           100.0,
1323                           +1.0,
1324                           -1.0);
1325     HUD_deque.push_front( p );
1326
1327     p = new  guage_instr( 20,             // x
1328                           240-50,             // y
1329                           20,             // width
1330                           100,             // height
1331                           get_elevatorval, // data source
1332                           HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
1333                           -100.0,           // Scale data
1334                           +1.0,           // Data Range
1335                           -1.0);
1336     HUD_deque.push_front( p );
1337
1338     p = new  guage_instr( 270, //250,             // x
1339                           10+15,             // y
1340                           100,             // width
1341                           20,             // height
1342                           get_rudderval,   // data source
1343                           HUDS_TOP | HUDS_NOTEXT,
1344                           100.0,
1345                           +1.0,
1346                           -1.0);
1347     HUD_deque.push_front( p );
1348
1349     p = new  guage_instr( 600,             // x
1350                           240-80,
1351                           20,
1352                           160,             // height
1353                           get_throttleval, // data source
1354                           HUDS_VERT | HUDS_LEFT | HUDS_NOTEXT,
1355                           100.0,
1356                           1.0,
1357                           0.0);
1358     HUD_deque.push_front( p );
1359     
1360     return 0;  // For now. Later we may use this for an error code.
1361 }
1362
1363 int global_day_night_switch = DAY;
1364
1365 void HUD_masterswitch( bool incr )
1366 {
1367     if ( globals->get_options()->get_hud_status() ) {
1368         if ( global_day_night_switch == DAY ) {
1369             global_day_night_switch = NIGHT;
1370         } else {
1371             globals->get_options()->set_hud_status( false );
1372         }
1373     } else {
1374         globals->get_options()->set_hud_status( true );
1375         global_day_night_switch = DAY;
1376     }   
1377 }
1378
1379 void HUD_brightkey( bool incr_bright )
1380 {
1381     instr_item *pHUDInstr = HUD_deque[0];
1382     int brightness        = pHUDInstr->get_brightness();
1383
1384     if( globals->get_options()->get_hud_status() ) {
1385         if( incr_bright ) {
1386             switch (brightness)
1387                 {
1388                 case BRT_LIGHT:
1389                     brightness = BRT_BLACK;
1390                     break;
1391
1392                 case BRT_MEDIUM:
1393                     brightness = BRT_LIGHT;
1394                     break;
1395
1396                 case BRT_DARK:
1397                     brightness = BRT_MEDIUM;
1398                     break;
1399
1400                 case BRT_BLACK:
1401                     brightness = BRT_DARK;
1402                     break;
1403
1404                 default:
1405                     brightness = BRT_BLACK;
1406                 }
1407         } else {
1408             switch (brightness)
1409                 {
1410                 case BRT_LIGHT:
1411                     brightness = BRT_MEDIUM;
1412                     break;
1413
1414                 case BRT_MEDIUM:
1415                     brightness = BRT_DARK;
1416                     break;
1417
1418                 case BRT_DARK:
1419                     brightness = BRT_BLACK;
1420                     break;
1421
1422                 case BRT_BLACK:
1423                     brightness = BRT_LIGHT;
1424                     break;
1425
1426                 default:
1427                     globals->get_options()->set_hud_status(0);
1428                 }
1429         }
1430     } else {
1431         globals->get_options()->set_hud_status(true);
1432     }
1433
1434     pHUDInstr->SetBrightness( brightness );
1435 }
1436
1437
1438 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
1439
1440 static puDialogBox *HUDalphaDialog;
1441 static puText      *HUDalphaText;
1442 static puSlider    *HUDalphaHS0;
1443 //static puText      *HUDtextText;
1444 //static puSlider    *HUDalphaHS1;
1445 static char         SliderText[2][ 8 ];
1446
1447 static void alpha_adj( puObject *hs ) {
1448         float val ;
1449
1450         hs-> getValue ( &val ) ;
1451         fgAP_CLAMP ( val, 0.1, 1.0 ) ;
1452         //    printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
1453         hud_trans_alpha = val;
1454         sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
1455         HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
1456 }
1457
1458 void fgHUDalphaAdjust( puObject * ) {
1459         globals->get_options()->set_anti_alias_hud(1);
1460         FG_PUSH_PUI_DIALOG( HUDalphaDialog );
1461 }
1462
1463 static void goAwayHUDalphaAdjust (puObject *)
1464 {
1465         FG_POP_PUI_DIALOG( HUDalphaDialog );
1466 }
1467
1468 static void cancelHUDalphaAdjust (puObject *)
1469 {
1470         globals->get_options()->set_anti_alias_hud(0);
1471         FG_POP_PUI_DIALOG( HUDalphaDialog );
1472 }
1473
1474 // Done once at system initialization
1475 void fgHUDalphaInit( void ) {
1476
1477         //      printf("fgHUDalphaInit\n");
1478 #define HORIZONTAL  FALSE
1479
1480         int DialogX = 40;
1481         int DialogY = 100;
1482         int DialogWidth = 240;
1483
1484         char Label[] =  "HUD Adjuster";
1485         char *s;
1486
1487         int labelX = (DialogWidth / 2) -
1488                                  (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
1489         
1490         int nSliders = 1;
1491         int slider_x = 10;
1492         int slider_y = 55;
1493         int slider_width = 220;
1494         int slider_title_x = 15;
1495         int slider_value_x = 160;
1496         float slider_delta = 0.05f;
1497
1498         puFont HUDalphaLegendFont;
1499         puFont HUDalphaLabelFont;
1500         puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
1501         
1502         HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
1503                 int horiz_slider_height = puGetStringHeight (HUDalphaLabelFont) +
1504                                                                   puGetStringDescender (HUDalphaLabelFont) +
1505                                                                   PUSTR_TGAP + PUSTR_BGAP + 5;
1506
1507                 puFrame *
1508                 HUDalphaFrame = new puFrame ( 0, 0,
1509                                                                           DialogWidth,
1510                                                                           85 + nSliders * horiz_slider_height );
1511                 
1512                 puText *
1513                 HUDalphaDialogMessage = new puText ( labelX,
1514                                                                                          52 + nSliders
1515                                                                                          * horiz_slider_height );
1516                 HUDalphaDialogMessage -> setDefaultValue ( Label );
1517                 HUDalphaDialogMessage -> getDefaultValue ( &s );
1518                 HUDalphaDialogMessage -> setLabel        ( s );
1519
1520                 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
1521                                                                          slider_width, HORIZONTAL ) ;
1522                 HUDalphaHS0->     setDelta ( slider_delta ) ;
1523                 HUDalphaHS0->     setValue ( hud_trans_alpha ) ;
1524                 HUDalphaHS0->    setCBMode ( PUSLIDER_DELTA ) ;
1525                 HUDalphaHS0->  setCallback ( alpha_adj ) ;
1526
1527                 puText *
1528                 HUDalphaTitle =      new puText ( slider_title_x, slider_y ) ;
1529                 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
1530                 HUDalphaTitle-> getDefaultValue ( &s ) ;
1531                 HUDalphaTitle->        setLabel ( s ) ;
1532                 
1533                 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
1534                 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
1535                 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
1536
1537
1538                 puOneShot *
1539                 HUDalphaOkButton =     new puOneShot ( 10, 10, 60, 45 );
1540                 HUDalphaOkButton->         setLegend ( gui_msg_OK );
1541                 HUDalphaOkButton-> makeReturnDefault ( TRUE );
1542                 HUDalphaOkButton->       setCallback ( goAwayHUDalphaAdjust );
1543                 
1544                 puOneShot *
1545                 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
1546                 HUDalphaNoButton->     setLegend ( gui_msg_CANCEL );
1547                 HUDalphaNoButton->   setCallback ( cancelHUDalphaAdjust );
1548         }
1549         FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1550
1551 #undef HORIZONTAL
1552 }
1553
1554 void fgHUDReshape(void) {
1555         if ( HUDtext )
1556                 delete HUDtext;
1557
1558         HUD_TextSize = globals->get_options()->get_xsize() / 60;
1559         HUD_TextSize = 10;
1560         HUDtext = new fntRenderer();
1561         HUDtext -> setFont      ( guiFntHandle ) ;
1562         HUDtext -> setPointSize ( HUD_TextSize ) ;
1563         HUD_TextList.setFont( HUDtext );
1564 }
1565
1566
1567 static void set_hud_color(float r, float g, float b) {
1568         globals->get_options()->get_anti_alias_hud() ?
1569                         glColor4f(r,g,b,hud_trans_alpha) :
1570                         glColor3f(r,g,b);
1571 }
1572
1573 // fgUpdateHUD
1574 //
1575 // Performs a once around the list of calls to instruments installed in
1576 // the HUD object with requests for redraw. Kinda. It will when this is
1577 // all C++.
1578 //
1579 void fgUpdateHUD( void ) {
1580   int brightness;
1581 //  int day_night_sw = current_aircraft.controls->day_night_switch;
1582   int day_night_sw = global_day_night_switch;
1583   int hud_displays = HUD_deque.size();
1584   instr_item *pHUDInstr;
1585   float line_width;
1586
1587   if( !hud_displays ) {  // Trust everyone, but ALWAYS cut the cards!
1588     return;
1589     }
1590
1591   HUD_TextList.erase();
1592   HUD_LineList.erase();
1593 //  HUD_StippleLineList.erase();
1594   
1595   pHUDInstr = HUD_deque[0];
1596   brightness = pHUDInstr->get_brightness();
1597 //  brightness = HUD_deque.at(0)->get_brightness();
1598
1599   glMatrixMode(GL_PROJECTION);
1600   glPushMatrix();
1601
1602   glLoadIdentity();
1603   gluOrtho2D(0, 640, 0, 480);
1604   glMatrixMode(GL_MODELVIEW);
1605   glPushMatrix();
1606   glLoadIdentity();
1607
1608   glDisable(GL_DEPTH_TEST);
1609   glDisable(GL_LIGHTING);
1610
1611   if( globals->get_options()->get_anti_alias_hud() ) {
1612           glEnable(GL_LINE_SMOOTH);
1613 //        glEnable(GL_BLEND);
1614           glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1615           glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1616           glLineWidth(1.5);
1617   } else {
1618           glLineWidth(1.0);
1619   }
1620
1621   if( day_night_sw == DAY) {
1622       switch (brightness)
1623           {
1624           case BRT_LIGHT:
1625               set_hud_color (0.1f, 0.9f, 0.1f);
1626               break;
1627
1628           case BRT_MEDIUM:
1629               set_hud_color (0.1f, 0.7f, 0.0f);
1630               break;
1631
1632           case BRT_DARK:
1633               set_hud_color (0.0f, 0.6f, 0.0f);
1634               break;
1635
1636           case BRT_BLACK:
1637               set_hud_color( 0.0f, 0.0f, 0.0f);
1638               break;
1639
1640           default:
1641               set_hud_color (0.1f, 0.9f, 0.1f);
1642           }
1643   } else {
1644       if( day_night_sw == NIGHT) {
1645           switch (brightness)
1646               {
1647               case BRT_LIGHT:
1648                   set_hud_color (0.9f, 0.1f, 0.1f);
1649                   break;
1650
1651               case BRT_MEDIUM:
1652                   set_hud_color (0.7f, 0.0f, 0.1f);
1653                   break;
1654
1655               case BRT_DARK:
1656                   set_hud_color (0.6f, 0.0f, 0.0f);
1657                   break;
1658
1659               case BRT_BLACK:
1660                   set_hud_color( 0.0f, 0.0f, 0.0f);
1661                   break;
1662
1663               default:
1664                   set_hud_color (0.6f, 0.0f, 0.0f);
1665               }
1666       } else {     // Just in case default
1667           set_hud_color (0.1f, 0.9f, 0.1f);
1668       }
1669   }
1670
1671   deque < instr_item * > :: iterator current = HUD_deque.begin();
1672   deque < instr_item * > :: iterator last = HUD_deque.end();
1673
1674   for ( ; current != last; ++current ) {
1675           pHUDInstr = *current;
1676
1677           if( pHUDInstr->enabled()) {
1678                   //  fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d  Status %d\n",
1679                   //            hud->code, hud->status );
1680                   pHUDInstr->draw();
1681           }
1682   }
1683
1684   char *gmt_str = get_formated_gmt_time();
1685   HUD_TextList.add( fgText(40, 10, gmt_str) );
1686
1687 #ifdef FG_NETWORK_OLK
1688   if ( net_hud_display ) {
1689       net_hud_update();
1690   }
1691 #endif
1692
1693
1694   // temporary
1695   // extern bool fgAPAltitudeEnabled( void );
1696   // extern bool fgAPHeadingEnabled( void );
1697   // extern bool fgAPWayPointEnabled( void );
1698   // extern char *fgAPget_TargetDistanceStr( void );
1699   // extern char *fgAPget_TargetHeadingStr( void );
1700   // extern char *fgAPget_TargetAltitudeStr( void );
1701   // extern char *fgAPget_TargetLatLonStr( void );
1702
1703   int apY = 480 - 80;
1704 //  char scratch[128];
1705 //  HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1706 //  apY -= 15;
1707   if( current_autopilot->get_HeadingEnabled() ) {
1708       HUD_TextList.add( fgText( 40, apY, 
1709                                 current_autopilot->get_TargetHeadingStr()) );
1710       apY -= 15;
1711   }
1712   if( current_autopilot->get_AltitudeEnabled() ) {
1713       HUD_TextList.add( fgText( 40, apY, 
1714                                 current_autopilot->get_TargetAltitudeStr()) );
1715       apY -= 15;
1716   }
1717   if( current_autopilot->get_HeadingMode() == 
1718       FGAutopilot::FG_HEADING_WAYPOINT )
1719   {
1720       char *wpstr;
1721       wpstr = current_autopilot->get_TargetWP1Str();
1722       if ( strlen( wpstr ) ) {
1723           HUD_TextList.add( fgText( 40, apY, wpstr ) );
1724           apY -= 15;
1725       }
1726       wpstr = current_autopilot->get_TargetWP2Str();
1727       if ( strlen( wpstr ) ) {
1728           HUD_TextList.add( fgText( 40, apY, wpstr ) );
1729           apY -= 15;
1730       }
1731       wpstr = current_autopilot->get_TargetWP3Str();
1732       if ( strlen( wpstr ) ) {
1733           HUD_TextList.add( fgText( 40, apY, wpstr ) );
1734           apY -= 15;
1735       }
1736   }
1737   
1738   HUD_TextList.draw();
1739
1740   HUD_LineList.draw();
1741
1742 //  glEnable(GL_LINE_STIPPLE);
1743 //  glLineStipple( 1, 0x00FF );
1744 //  HUD_StippleLineList.draw();
1745 //  glDisable(GL_LINE_STIPPLE);
1746
1747   if( globals->get_options()->get_anti_alias_hud() ) {
1748 //        glDisable(GL_BLEND);
1749           glDisable(GL_LINE_SMOOTH);
1750           glLineWidth(1.0);
1751   }
1752
1753   glEnable(GL_DEPTH_TEST);
1754   glEnable(GL_LIGHTING);
1755   glMatrixMode(GL_PROJECTION);
1756   glPopMatrix();
1757   glMatrixMode(GL_MODELVIEW);
1758   glPopMatrix();
1759 }
1760