1 // hud.cxx -- hud defines and prototypes
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - micheleamerica@geocities.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <simgear/compiler.h>
24 #include <simgear/misc/exception.hxx>
35 # define exception c_exception
41 #include <stdio.h> //char related functions
45 #include <simgear/constants.h>
46 #include <simgear/debug/logstream.hxx>
47 #include <simgear/misc/props.hxx>
48 #include <simgear/misc/sg_path.hxx>
49 //#include <simgear/math/fg_random.h>
50 //#include <simgear/math/polar3d.hxx>
52 #include <Aircraft/aircraft.hxx>
53 #include <Autopilot/newauto.hxx>
55 #include <Main/globals.hxx>
56 #include <Main/fg_props.hxx>
58 #include <NetworkOLK/network.h>
60 #include <Scenery/scenery.hxx>
61 //#include <Time/fg_timer.hxx>
63 #if defined ( __sun__ ) || defined ( __sgi )
65 extern void *memmove(void *, const void *, size_t);
73 // The following routines obtain information concerning the aircraft's
74 // current state and return it to calling instrument display routines.
75 // They should eventually be member functions of the aircraft.
78 deque< instr_item * > HUD_deque;
80 fgTextList HUD_TextList;
81 fgLineList HUD_LineList;
82 fgLineList HUD_StippleLineList;
84 fntRenderer *HUDtext = 0;
85 float HUD_TextSize = 0;
89 static float hud_trans_alpha = 0.67f;
92 //$$$ begin - added, Neetha, 28 Nov 2k
100 static float span_units;
101 static float division_units;
102 static float minor_division = 0;
103 static UINT screen_hole;
106 static string loadfn;
108 static float maxValue;
109 static float minValue;
110 static float scaling;
111 static UINT major_divs;
112 static UINT minor_divs;
113 static UINT modulator;
114 static int dp_showing = 0;
115 static string label_format;
116 static string prelabel;
117 static string postlabel;
120 static float maxBankAngle;
121 static float maxSlipAngle;
122 static UINT gap_width;
123 static bool latitude;
124 static bool longitude;
125 static bool tick_bottom;
126 static bool tick_top;
127 static bool tick_right;
128 static bool tick_left;
129 static bool cap_bottom;
131 static bool cap_right;
132 static bool cap_left;
133 static float marker_off;
135 static bool enable_pointer;
136 static string type_pointer;
137 static bool frl_spot;
139 static bool vel_vector;
143 static bool climb_dive;
145 static float glide_slope_val;
146 static bool worm_energy;
147 static bool waypoint;
148 static string type_tick;//hud
149 static string length_tick;//hud
150 static bool label_box;//hud
151 static int digits; //suma
152 static float radius; //suma
153 static int divisions; //suma
154 static int zoom; //suma
155 static int zenith; //suma
156 static int nadir ; //suma
157 static int hat; //suma
158 static bool tsi; //suma
159 static float rad; //suma
162 static FLTFNPTR load_fn;
163 static fgLabelJust justification;
164 static const char *pre_label_string = 0;
165 static const char *post_label_string = 0;
167 int readHud( istream &input );
168 int readInstrument ( const SGPropertyNode * node);
169 static instr_item * readLadder ( const SGPropertyNode * node);
170 static instr_item * readCard ( const SGPropertyNode * node);
171 static instr_item * readLabel( const SGPropertyNode * node);
172 static instr_item * readTBI( const SGPropertyNode * node);
173 //$$$ end - added, Neetha, 28 Nov 2k
175 void fgHUDalphaInit( void );
181 locRECT( UINT left, UINT top, UINT right, UINT bottom);
182 RECT get_rect(void) { return rect;}
185 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
190 rect.bottom = bottom;
196 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
204 void drawOneLine( RECT &rect)
207 glVertex2f(rect.left, rect.top);
208 glVertex2f(rect.right, rect.bottom);
213 // The following code deals with painting the "instrument" on the display
215 /* textString - Bitmap font string */
217 void textString( int x, int y, char *msg, void *font,int digit) //suma
221 // puDrawString ( NULL, msg, x, y );
224 glutBitmapCharacter(font, *msg);
231 /* strokeString - Stroke font string */
232 void strokeString(int x, int y, char *msg, void *font, float theta)
237 float sintheta,costheta;
242 glRotatef(theta * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
243 sintheta = sin(theta);
244 costheta = cos(theta);
245 xx = (int)(x * costheta + y * sintheta);
246 yy = (int)(y * costheta - x * sintheta);
247 glTranslatef( xx, yy, 0);
248 glScalef(.1, .1, 0.0);
249 while( (c=*msg++) ) {
250 glutStrokeCharacter(font, c);
256 int getStringWidth ( char *str )
258 if ( HUDtext && str ) {
260 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
261 return FloatToInt( r - l );
267 //========================= End of Class Implementations===================
270 // Constructs a HUD object and then adds in instruments. At the present
271 // the instruments are hard coded into the routine. Ultimately these need
272 // to be defined by the aircraft's instrumentation records so that the
273 // display for a Piper Cub doesn't show the speed range of a North American
274 // mustange and the engine readouts of a B36!
279 //$$$ begin - added, Neetha, 28 Nov 2k
281 readLadder(const SGPropertyNode * node)
286 name = node->getStringValue("name");
287 x = node->getIntValue("x");
288 y = node->getIntValue("y");
289 width = node->getIntValue("width");
290 height = node->getIntValue("height");
291 factor = node->getFloatValue("compression_factor");
292 span_units = node->getFloatValue("span_units");
293 division_units = node->getFloatValue("division_units");
294 screen_hole = node->getIntValue("screen_hole");
295 lbl_pos = node->getIntValue("lbl_pos");
296 frl_spot = node->getBoolValue("enable_frl",false);
297 target = node->getBoolValue("enable_target_spot",false);
298 vel_vector = node->getBoolValue("enable_velocity_vector",false);
299 drift = node->getBoolValue("enable_drift_marker",false);
300 alpha = node->getBoolValue("enable_alpha_bracket",false);
301 energy = node->getBoolValue("enable_energy_marker",false);
302 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
303 glide = node->getBoolValue("enable_glide_slope_marker",false);
304 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
305 worm_energy = node->getBoolValue("enable_energy_marker",false);
306 waypoint = node->getBoolValue("enable_waypoint_marker",false);
307 working = node->getBoolValue("working");
308 zenith = node->getIntValue("zenith"); //suma
309 nadir = node->getIntValue("nadir"); //suma
310 hat = node->getIntValue("hat");
313 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
316 p = (instr_item *) new HudLadder( name, x, y,
317 width, height, factor,
319 span_units, division_units, minor_division,
320 screen_hole, lbl_pos, frl_spot, target, vel_vector,
321 drift, alpha, energy, climb_dive,
322 glide, glide_slope_val, worm_energy,
323 waypoint, working, zenith, nadir, hat);
330 readCard(const SGPropertyNode * node)
335 name = node->getStringValue("name");
336 x = node->getIntValue("x");
337 y = node->getIntValue("y");
338 width = node->getIntValue("width");
339 height = node->getIntValue("height");
340 loadfn = node->getStringValue("loadfn");
341 options = node->getIntValue("options");
342 maxValue = node->getFloatValue("maxValue");
343 minValue = node->getFloatValue("minValue");
344 scaling = node->getFloatValue("disp_scaling");
345 major_divs = node->getIntValue("major_divs");
346 minor_divs = node->getIntValue("minor_divs");
347 modulator = node->getIntValue("modulator");
348 span_units = node->getFloatValue("value_span");
349 type = node->getStringValue("type");
350 tick_bottom = node->getBoolValue("tick_bottom",false);
351 tick_top = node->getBoolValue("tick_top",false);
352 tick_right = node->getBoolValue("tick_right",false);
353 tick_left = node->getBoolValue("tick_left",false);
354 cap_bottom = node->getBoolValue("cap_bottom",false);
355 cap_top = node->getBoolValue("cap_top",false);
356 cap_right = node->getBoolValue("cap_right",false);
357 cap_left = node->getBoolValue("cap_left",false);
358 marker_off = node->getFloatValue("marker_offset",0.0);
359 enable_pointer = node->getBoolValue("enable_pointer",true);
360 type_pointer = node->getStringValue("pointer_type");
361 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
362 length_tick = node->getStringValue("tick_length");//hud For variable length
363 working = node->getBoolValue("working");
364 radius = node->getFloatValue("radius"); //suma
365 divisions = node->getIntValue("divisions"); //suma
366 zoom = node->getIntValue("zoom"); //suma
368 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
372 span_units = maxValue - minValue;
375 if (loadfn=="anzg") {
377 } else if (loadfn=="heading") {
378 load_fn = get_heading;
379 } else if (loadfn=="aoa") {
381 } else if (loadfn=="climb") {
382 load_fn = get_climb_rate;
383 } else if (loadfn=="altitude") {
384 load_fn = get_altitude;
385 } else if (loadfn=="agl") {
387 } else if (loadfn=="speed") {
389 } else if (loadfn=="view_direction") {
390 load_fn = get_view_direction;
391 } else if (loadfn=="aileronval") {
392 load_fn = get_aileronval;
393 } else if (loadfn=="elevatorval") {
394 load_fn = get_elevatorval;
395 } else if (loadfn=="rudderval") {
396 load_fn = get_rudderval;
397 } else if (loadfn=="throttleval") {
398 load_fn = get_throttleval;
402 if ( (type == "dial") | (type == "tape") ) {
403 p = (instr_item *) new hud_card( x,
411 major_divs, minor_divs,
435 p = (instr_item *) new gauge_instr( x, // x
439 load_fn, // data source
443 major_divs, minor_divs,
453 readLabel(const SGPropertyNode * node)
457 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? LARGE : SMALL;
459 name = node->getStringValue("name");
460 x = node->getIntValue("x");
461 y = node->getIntValue("y");
462 width = node->getIntValue("width");
463 height = node->getIntValue("height");
464 loadfn = node->getStringValue("data_source");
465 label_format = node->getStringValue("label_format");
466 prelabel = node->getStringValue("pre_label_string");
467 postlabel = node->getStringValue("post_label_string");
468 scaling = node->getFloatValue("scale_data");
469 options = node->getIntValue("options");
470 justi = node->getIntValue("justification");
471 blinking = node->getIntValue("blinking");
472 latitude = node->getBoolValue("latitude",false);
473 longitude = node->getBoolValue("longitude",false);
474 label_box = node->getBoolValue("label_box",false);//hud
475 working = node->getBoolValue("working");
476 digits = node->getIntValue("digits"); //suma
479 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
483 justification = LEFT_JUST;
486 justification = CENTER_JUST;
489 justification = RIGHT_JUST;
494 if ( prelabel == "NULL" ) {
495 pre_label_string = NULL;
497 if ( prelabel == "blank" ) {
498 pre_label_string = " ";
500 pre_label_string = prelabel.c_str();
504 if ( postlabel == "blank" ) {
505 post_label_string = " ";
507 if ( postlabel == "NULL" ) {
508 post_label_string = NULL;
510 if ( postlabel == "units" ) {
511 post_label_string = units;
513 post_label_string = postlabel.c_str();
518 if ( loadfn== "aux1" ) {
520 } else if ( loadfn == "aux2" ) {
522 } else if ( loadfn == "aux3" ) {
524 } else if ( loadfn == "aux4" ) {
526 } else if ( loadfn == "aux5" ) {
528 } else if ( loadfn == "aux6" ) {
530 } else if ( loadfn == "aux7" ) {
532 } else if ( loadfn == "aux8" ) {
534 } else if ( loadfn == "aux9" ) {
536 } else if ( loadfn == "aux10" ) {
538 } else if ( loadfn == "aux11" ) {
540 } else if ( loadfn == "aux12" ) {
542 } else if ( loadfn == "aux13" ) {
544 } else if ( loadfn == "aux14" ) {
546 } else if ( loadfn == "aux15" ) {
548 } else if ( loadfn == "aux16" ) {
550 } else if ( loadfn == "aux17" ) {
552 } else if ( loadfn == "aux18" ) {
554 } else if ( loadfn == "ax" ) {
556 } else if ( loadfn == "speed" ) {
558 } else if ( loadfn == "mach" ) {
560 } else if ( loadfn == "altitude" ) {
561 load_fn = get_altitude;
562 } else if ( loadfn == "agl" ) {
564 } else if ( loadfn == "framerate" ) {
565 load_fn = get_frame_rate;
566 } else if ( loadfn == "heading" ) {
567 load_fn = get_heading;
568 } else if ( loadfn == "fov" ) {
570 } else if ( loadfn == "vfc_tris_culled" ) {
571 load_fn = get_vfc_tris_culled;
572 } else if ( loadfn == "vfc_tris_drawn" ) {
573 load_fn = get_vfc_tris_drawn;
574 } else if ( loadfn == "aoa" ) {
576 } else if ( loadfn == "latitude" ) {
577 load_fn = get_latitude;
578 } else if ( loadfn == "anzg" ) {
580 } else if ( loadfn == "longitude" ) {
581 load_fn = get_longitude;
582 } else if (loadfn=="throttleval") {
583 load_fn = get_throttleval;
586 p = (instr_item *) new instr_label ( x,
591 label_format.c_str(),
609 readTBI(const SGPropertyNode * node)
614 name = node->getStringValue("name");
615 x = node->getIntValue("x");
616 y = node->getIntValue("y");
617 width = node->getIntValue("width");
618 height = node->getIntValue("height");
619 maxBankAngle = node->getFloatValue("maxBankAngle");
620 maxSlipAngle = node->getFloatValue("maxSlipAngle");
621 gap_width = node->getIntValue("gap_width");
622 working = node->getBoolValue("working");
623 tsi = node->getBoolValue("tsi"); //suma
624 rad = node->getFloatValue("rad"); //suma
626 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
629 p = (instr_item *) new fgTBI_instr( x,
646 int readInstrument(const SGPropertyNode * node)
651 if ( fgGetString("/sim/startup/units") == "feet" ) {
652 strcpy(units, " ft");
657 const SGPropertyNode * ladder_group = node->getNode("ladders");
659 if (ladder_group != 0) {
660 int nLadders = ladder_group->nChildren();
661 for (int j = 0; j < nLadders; j++) {
663 HIptr = readLadder(ladder_group->getChild(j));
664 HUD_deque.insert( HUD_deque.begin(), HIptr);
669 const SGPropertyNode * card_group = node->getNode("cards");
670 if (card_group != 0) {
671 int nCards = card_group->nChildren();
672 for (int j = 0; j < nCards; j++) {
674 HIptr = readCard(card_group->getChild(j));
675 HUD_deque.insert( HUD_deque.begin(), HIptr);
680 const SGPropertyNode * label_group = node->getNode("labels");
681 if (label_group != 0) {
682 int nLabels = label_group->nChildren();
683 for (int j = 0; j < nLabels; j++) {
685 HIptr = readLabel(label_group->getChild(j));
686 HUD_deque.insert( HUD_deque.begin(), HIptr);
691 const SGPropertyNode * tbi_group = node->getNode("tbis");
692 if (tbi_group != 0) {
693 int nTbis = tbi_group->nChildren();
694 for (int j = 0; j < nTbis; j++) {
696 HIptr = readTBI(tbi_group->getChild(j));
697 HUD_deque.insert( HUD_deque.begin(), HIptr);
702 }//end readinstrument
705 int readHud( istream &input )
711 readProperties(input, &root);
712 } catch (const sg_exception &e) {
713 guiErrorMessage("Error reading HUD: ", e);
718 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
719 root.getStringValue("name"));
722 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
725 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
727 const SGPropertyNode * instrument_group = root.getChild("instruments");
728 int nInstruments = instrument_group->nChildren();
730 for (int i = 0; i < nInstruments; i++) {
732 const SGPropertyNode * node = instrument_group->getChild(i);
734 SGPath path( globals->get_fg_root() );
735 path.append(node->getStringValue("path"));
737 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
743 SGPropertyNode root2;
745 readProperties(path.str(), &root2);
746 } catch (const sg_exception &e) {
747 guiErrorMessage("Error reading HUD instrument: ", e);
750 readInstrument(&root2);
757 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
763 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
766 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
767 SGPath path(globals->get_fg_root());
768 path.append(hud_path);
770 ifstream input(path.c_str());
772 SG_LOG(SG_INPUT, SG_ALERT,
773 "Cannot read Hud configuration from " << path.str());
782 return 0; // For now. Later we may use this for an error code.
786 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
791 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
793 SGPath path(globals->get_fg_root());
794 path.append("Huds/Minimal/default.xml");
797 ifstream input(path.c_str());
799 SG_LOG(SG_INPUT, SG_ALERT,
800 "Cannot read Hud configuration from " << path.str());
806 return 0; // For now. Later we may use this for an error code.
809 //$$$ End - added, Neetha, 28 Nov 2k
811 static int global_day_night_switch = DAY;
813 void HUD_masterswitch( bool incr )
815 if ( fgGetBool("/sim/hud/visibility") ) {
816 if ( global_day_night_switch == DAY ) {
817 global_day_night_switch = NIGHT;
819 fgSetBool("/sim/hud/visibility", false);
822 fgSetBool("/sim/hud/visibility", true);
823 global_day_night_switch = DAY;
827 void HUD_brightkey( bool incr_bright )
829 instr_item *pHUDInstr = HUD_deque[0];
830 int brightness = pHUDInstr->get_brightness();
832 if( fgGetBool("/sim/hud/visibility") ) {
837 brightness = BRT_BLACK;
841 brightness = BRT_LIGHT;
845 brightness = BRT_MEDIUM;
849 brightness = BRT_DARK;
853 brightness = BRT_BLACK;
859 brightness = BRT_MEDIUM;
863 brightness = BRT_DARK;
867 brightness = BRT_BLACK;
871 brightness = BRT_LIGHT;
875 fgSetBool("/sim/hud/visibility", false);
879 fgSetBool("/sim/hud/visibility", true);
882 pHUDInstr->SetBrightness( brightness );
886 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
888 static puDialogBox *HUDalphaDialog;
889 static puText *HUDalphaText;
890 static puSlider *HUDalphaHS0;
891 //static puText *HUDtextText;
892 //static puSlider *HUDalphaHS1;
893 static char SliderText[2][ 8 ];
895 static void alpha_adj( puObject *hs ) {
898 hs-> getValue ( &val ) ;
899 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
900 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
901 hud_trans_alpha = val;
902 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
903 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
906 void fgHUDalphaAdjust( puObject * ) {
907 fgSetBool("/sim/hud/antialiased", true);
908 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
911 static void goAwayHUDalphaAdjust (puObject *)
913 FG_POP_PUI_DIALOG( HUDalphaDialog );
916 static void cancelHUDalphaAdjust (puObject *)
918 fgSetBool("/sim/hud/antialiased", false);
919 FG_POP_PUI_DIALOG( HUDalphaDialog );
922 // Done once at system initialization
923 void fgHUDalphaInit( void ) {
925 // printf("fgHUDalphaInit\n");
926 #define HORIZONTAL FALSE
930 int DialogWidth = 240;
932 char Label[] = "HUD Adjuster";
935 int labelX = (DialogWidth / 2) -
936 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
941 int slider_width = 220;
942 int slider_title_x = 15;
943 int slider_value_x = 160;
944 float slider_delta = 0.05f;
946 puFont HUDalphaLegendFont;
947 puFont HUDalphaLabelFont;
948 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
950 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
951 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
952 HUDalphaLabelFont.getStringDescender() +
953 PUSTR_TGAP + PUSTR_BGAP + 5;
956 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
958 * horiz_slider_height ); */
961 HUDalphaDialogMessage = new puText ( labelX,
963 * horiz_slider_height );
964 HUDalphaDialogMessage -> setDefaultValue ( Label );
965 HUDalphaDialogMessage -> getDefaultValue ( &s );
966 HUDalphaDialogMessage -> setLabel ( s );
968 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
969 slider_width, HORIZONTAL ) ;
970 HUDalphaHS0-> setDelta ( slider_delta ) ;
971 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
972 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
973 HUDalphaHS0-> setCallback ( alpha_adj ) ;
976 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
977 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
978 HUDalphaTitle-> getDefaultValue ( &s ) ;
979 HUDalphaTitle-> setLabel ( s ) ;
981 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
982 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
983 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
986 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
987 HUDalphaOkButton-> setLegend ( gui_msg_OK );
988 HUDalphaOkButton-> makeReturnDefault ( TRUE );
989 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
992 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
993 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
994 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
996 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1002 void fgHUDReshape(void) {
1004 // this chunk of code is not necessarily thread safe if the
1005 // compiler optimizer reorders these statements. Note that
1006 // "delete ptr" does not set "ptr = NULL". We have to do that
1008 fntRenderer *tmp = HUDtext;
1013 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
1015 HUDtext = new fntRenderer();
1016 HUDtext -> setFont ( guiFntHandle ) ;
1017 HUDtext -> setPointSize ( HUD_TextSize ) ;
1018 HUD_TextList.setFont( HUDtext );
1022 static void set_hud_color(float r, float g, float b) {
1023 fgGetBool("/sim/hud/antialiased") ?
1024 glColor4f(r,g,b,hud_trans_alpha) :
1031 // Performs a once around the list of calls to instruments installed in
1032 // the HUD object with requests for redraw. Kinda. It will when this is
1035 void fgUpdateHUD( void ) {
1037 static const float normal_aspect = float(640) / float(480);
1038 // note: aspect_ratio is Y/X
1039 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1040 if( current_aspect > normal_aspect ) {
1041 float aspect_adjust = current_aspect / normal_aspect;
1042 float adjust = 320.0f*aspect_adjust - 320.0f;
1043 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1045 float aspect_adjust = normal_aspect / current_aspect;
1046 float adjust = 240.0f*aspect_adjust - 240.0f;
1047 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1051 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1052 GLfloat x_end, GLfloat y_end )
1055 // int day_night_sw = current_aircraft.controls->day_night_switch;
1056 int day_night_sw = global_day_night_switch;
1057 int hud_displays = HUD_deque.size();
1058 instr_item *pHUDInstr;
1059 // float line_width;
1061 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1065 HUD_TextList.erase();
1066 HUD_LineList.erase();
1067 // HUD_StippleLineList.erase();
1069 pHUDInstr = HUD_deque[0];
1070 brightness = pHUDInstr->get_brightness();
1071 // brightness = HUD_deque.at(0)->get_brightness();
1073 glMatrixMode(GL_PROJECTION);
1077 gluOrtho2D(x_start, x_end, y_start, y_end);
1078 glMatrixMode(GL_MODELVIEW);
1082 glDisable(GL_DEPTH_TEST);
1083 glDisable(GL_LIGHTING);
1085 static const SGPropertyNode * antialiased_node
1086 = fgGetNode("/sim/hud/antialiased");
1088 if( antialiased_node->getBoolValue() ) {
1089 glEnable(GL_LINE_SMOOTH);
1090 // glEnable(GL_BLEND);
1091 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1092 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1098 if( day_night_sw == DAY) {
1102 set_hud_color (0.1f, 0.9f, 0.1f);
1106 set_hud_color (0.1f, 0.7f, 0.0f);
1110 set_hud_color (0.0f, 0.6f, 0.0f);
1114 set_hud_color( 0.0f, 0.0f, 0.0f);
1118 set_hud_color (0.1f, 0.9f, 0.1f);
1121 if( day_night_sw == NIGHT) {
1125 set_hud_color (0.9f, 0.1f, 0.1f);
1129 set_hud_color (0.7f, 0.0f, 0.1f);
1133 set_hud_color (0.6f, 0.0f, 0.0f);
1137 set_hud_color( 0.0f, 0.0f, 0.0f);
1141 set_hud_color (0.6f, 0.0f, 0.0f);
1143 } else { // Just in case default
1144 set_hud_color (0.1f, 0.9f, 0.1f);
1148 deque < instr_item * > :: iterator current = HUD_deque.begin();
1149 deque < instr_item * > :: iterator last = HUD_deque.end();
1151 for ( ; current != last; ++current ) {
1152 pHUDInstr = *current;
1154 if( pHUDInstr->enabled()) {
1155 // fgPrintf( SG_COCKPIT, SG_DEBUG, "HUD Code %d Status %d\n",
1156 // hud->code, hud->status );
1162 char *gmt_str = get_formated_gmt_time();
1163 HUD_TextList.add( fgText(40, 10, gmt_str, 0) );
1165 #ifdef FG_NETWORK_OLK
1166 if ( net_hud_display ) {
1173 // extern bool fgAPAltitudeEnabled( void );
1174 // extern bool fgAPHeadingEnabled( void );
1175 // extern bool fgAPWayPointEnabled( void );
1176 // extern char *fgAPget_TargetDistanceStr( void );
1177 // extern char *fgAPget_TargetHeadingStr( void );
1178 // extern char *fgAPget_TargetAltitudeStr( void );
1179 // extern char *fgAPget_TargetLatLonStr( void );
1182 // char scratch[128];
1183 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1185 if( globals->get_autopilot()->get_HeadingEnabled() ) {
1186 HUD_TextList.add( fgText( 40, apY,
1187 globals->get_autopilot()->get_TargetHeadingStr()) );
1190 if( globals->get_autopilot()->get_AltitudeEnabled() ) {
1191 HUD_TextList.add( fgText( 40, apY,
1192 globals->get_autopilot()->get_TargetAltitudeStr()) );
1195 if( globals->get_autopilot()->get_HeadingMode() ==
1196 FGAutopilot::FG_HEADING_WAYPOINT )
1199 wpstr = globals->get_autopilot()->get_TargetWP1Str();
1200 if ( strlen( wpstr ) ) {
1201 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1204 wpstr = globals->get_autopilot()->get_TargetWP2Str();
1205 if ( strlen( wpstr ) ) {
1206 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1209 wpstr = globals->get_autopilot()->get_TargetWP3Str();
1210 if ( strlen( wpstr ) ) {
1211 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1216 HUD_TextList.draw();
1218 HUD_LineList.draw();
1220 // glEnable(GL_LINE_STIPPLE);
1221 // glLineStipple( 1, 0x00FF );
1222 // HUD_StippleLineList.draw();
1223 // glDisable(GL_LINE_STIPPLE);
1225 if( antialiased_node->getBoolValue() ) {
1226 // glDisable(GL_BLEND);
1227 glDisable(GL_LINE_SMOOTH);
1231 glEnable(GL_DEPTH_TEST);
1232 glEnable(GL_LIGHTING);
1233 glMatrixMode(GL_PROJECTION);
1235 glMatrixMode(GL_MODELVIEW);