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
44 #include <simgear/constants.h>
45 #include <simgear/debug/logstream.hxx>
46 #include <simgear/misc/props.hxx>
47 //#include <simgear/math/fg_random.h>
48 //#include <simgear/math/polar3d.hxx>
50 #include <Aircraft/aircraft.hxx>
51 #include <Autopilot/newauto.hxx>
53 #include <Main/globals.hxx>
54 #include <Main/fg_props.hxx>
56 #include <NetworkOLK/network.h>
58 #include <Scenery/scenery.hxx>
59 //#include <Time/fg_timer.hxx>
61 #if defined ( __sun__ ) || defined ( __sgi )
63 extern void *memmove(void *, const void *, size_t);
71 // The following routines obtain information concerning the aircraft's
72 // current state and return it to calling instrument display routines.
73 // They should eventually be member functions of the aircraft.
76 deque< instr_item * > HUD_deque;
78 fgTextList HUD_TextList;
79 fgLineList HUD_LineList;
80 fgLineList HUD_StippleLineList;
82 fntRenderer *HUDtext = 0;
83 float HUD_TextSize = 0;
87 static float hud_trans_alpha = 0.67f;
90 //$$$ begin - added, Neetha, 28 Nov 2k
98 static float span_units;
99 static float division_units;
100 static float minor_division = 0;
101 static UINT screen_hole;
104 static string loadfn;
106 static float maxValue;
107 static float minValue;
108 static float scaling;
109 static UINT major_divs;
110 static UINT minor_divs;
111 static UINT modulator;
112 static int dp_showing = 0;
113 static string label_format;
114 static string prelabel;
115 static string postlabel;
118 static float maxBankAngle;
119 static float maxSlipAngle;
120 static UINT gap_width;
121 static bool latitude;
122 static bool longitude;
123 static bool tick_bottom;
124 static bool tick_top;
125 static bool tick_right;
126 static bool tick_left;
127 static bool cap_bottom;
129 static bool cap_right;
130 static bool cap_left;
131 static float marker_off;
133 static bool enable_pointer;
134 static string type_pointer;
135 static bool frl_spot;
137 static bool vel_vector;
141 static bool climb_dive;
143 static float glide_slope_val;
144 static bool worm_energy;
145 static bool waypoint;
146 static string type_tick;//hud
147 static string length_tick;//hud
148 static bool label_box;//hud
149 static int digits; //suma
150 static float radius; //suma
151 static int divisions; //suma
152 static int zoom; //suma
153 static int zenith; //suma
154 static int nadir ; //suma
155 static int hat; //suma
156 static bool tsi; //suma
157 static float rad; //suma
160 static FLTFNPTR load_fn;
161 static fgLabelJust justification;
162 static const char *pre_label_string = 0;
163 static const char *post_label_string = 0;
165 int readHud( istream &input );
166 int readInstrument ( const SGPropertyNode * node);
167 static instr_item * readLadder ( const SGPropertyNode * node);
168 static instr_item * readCard ( const SGPropertyNode * node);
169 static instr_item * readLabel( const SGPropertyNode * node);
170 static instr_item * readTBI( const SGPropertyNode * node);
171 //$$$ end - added, Neetha, 28 Nov 2k
173 void fgHUDalphaInit( void );
179 locRECT( UINT left, UINT top, UINT right, UINT bottom);
180 RECT get_rect(void) { return rect;}
183 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
188 rect.bottom = bottom;
194 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
202 void drawOneLine( RECT &rect)
205 glVertex2f(rect.left, rect.top);
206 glVertex2f(rect.right, rect.bottom);
211 // The following code deals with painting the "instrument" on the display
213 /* textString - Bitmap font string */
215 void textString( int x, int y, char *msg, void *font,int digit) //suma
219 // puDrawString ( NULL, msg, x, y );
222 glutBitmapCharacter(font, *msg);
229 /* strokeString - Stroke font string */
230 void strokeString(int x, int y, char *msg, void *font, float theta)
235 float sintheta,costheta;
240 glRotatef(theta * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
241 sintheta = sin(theta);
242 costheta = cos(theta);
243 xx = (int)(x * costheta + y * sintheta);
244 yy = (int)(y * costheta - x * sintheta);
245 glTranslatef( xx, yy, 0);
246 glScalef(.1, .1, 0.0);
247 while( (c=*msg++) ) {
248 glutStrokeCharacter(font, c);
254 int getStringWidth ( char *str )
256 if ( HUDtext && str ) {
258 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
259 return FloatToInt( r - l );
265 //========================= End of Class Implementations===================
268 // Constructs a HUD object and then adds in instruments. At the present
269 // the instruments are hard coded into the routine. Ultimately these need
270 // to be defined by the aircraft's instrumentation records so that the
271 // display for a Piper Cub doesn't show the speed range of a North American
272 // mustange and the engine readouts of a B36!
277 //$$$ begin - added, Neetha, 28 Nov 2k
279 readLadder(const SGPropertyNode * node)
284 name = node->getStringValue("name");
285 x = node->getIntValue("x");
286 y = node->getIntValue("y");
287 width = node->getIntValue("width");
288 height = node->getIntValue("height");
289 factor = node->getFloatValue("compression_factor");
290 span_units = node->getFloatValue("span_units");
291 division_units = node->getFloatValue("division_units");
292 screen_hole = node->getIntValue("screen_hole");
293 lbl_pos = node->getIntValue("lbl_pos");
294 frl_spot = node->getBoolValue("enable_frl",false);
295 target = node->getBoolValue("enable_target_spot",false);
296 vel_vector = node->getBoolValue("enable_velocity_vector",false);
297 drift = node->getBoolValue("enable_drift_marker",false);
298 alpha = node->getBoolValue("enable_alpha_bracket",false);
299 energy = node->getBoolValue("enable_energy_marker",false);
300 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
301 glide = node->getBoolValue("enable_glide_slope_marker",false);
302 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
303 worm_energy = node->getBoolValue("enable_energy_marker",false);
304 waypoint = node->getBoolValue("enable_waypoint_marker",false);
305 working = node->getBoolValue("working");
306 zenith = node->getIntValue("zenith"); //suma
307 nadir = node->getIntValue("nadir"); //suma
308 hat = node->getIntValue("hat");
311 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
314 p = (instr_item *) new HudLadder( name, x, y,
315 width, height, factor,
317 span_units, division_units, minor_division,
318 screen_hole, lbl_pos, frl_spot, target, vel_vector,
319 drift, alpha, energy, climb_dive,
320 glide, glide_slope_val, worm_energy,
321 waypoint, working, zenith, nadir, hat);
328 readCard(const SGPropertyNode * node)
333 name = node->getStringValue("name");
334 x = node->getIntValue("x");
335 y = node->getIntValue("y");
336 width = node->getIntValue("width");
337 height = node->getIntValue("height");
338 loadfn = node->getStringValue("loadfn");
339 options = node->getIntValue("options");
340 maxValue = node->getFloatValue("maxValue");
341 minValue = node->getFloatValue("minValue");
342 scaling = node->getFloatValue("disp_scaling");
343 major_divs = node->getIntValue("major_divs");
344 minor_divs = node->getIntValue("minor_divs");
345 modulator = node->getIntValue("modulator");
346 span_units = node->getFloatValue("value_span");
347 type = node->getStringValue("type");
348 tick_bottom = node->getBoolValue("tick_bottom",false);
349 tick_top = node->getBoolValue("tick_top",false);
350 tick_right = node->getBoolValue("tick_right",false);
351 tick_left = node->getBoolValue("tick_left",false);
352 cap_bottom = node->getBoolValue("cap_bottom",false);
353 cap_top = node->getBoolValue("cap_top",false);
354 cap_right = node->getBoolValue("cap_right",false);
355 cap_left = node->getBoolValue("cap_left",false);
356 marker_off = node->getFloatValue("marker_offset",0.0);
357 enable_pointer = node->getBoolValue("enable_pointer",true);
358 type_pointer = node->getStringValue("pointer_type");
359 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
360 length_tick = node->getStringValue("tick_length");//hud For variable length
361 working = node->getBoolValue("working");
362 radius = node->getFloatValue("radius"); //suma
363 divisions = node->getIntValue("divisions"); //suma
364 zoom = node->getIntValue("zoom"); //suma
366 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
370 span_units = maxValue - minValue;
373 if (loadfn=="anzg") {
375 } else if (loadfn=="heading") {
376 load_fn = get_heading;
377 } else if (loadfn=="aoa") {
379 } else if (loadfn=="climb") {
380 load_fn = get_climb_rate;
381 } else if (loadfn=="altitude") {
382 load_fn = get_altitude;
383 } else if (loadfn=="agl") {
385 } else if (loadfn=="speed") {
387 } else if (loadfn=="view_direction") {
388 load_fn = get_view_direction;
389 } else if (loadfn=="aileronval") {
390 load_fn = get_aileronval;
391 } else if (loadfn=="elevatorval") {
392 load_fn = get_elevatorval;
393 } else if (loadfn=="rudderval") {
394 load_fn = get_rudderval;
395 } else if (loadfn=="throttleval") {
396 load_fn = get_throttleval;
400 if ( (type == "dial") | (type == "tape") ) {
401 p = (instr_item *) new hud_card( x,
409 major_divs, minor_divs,
433 p = (instr_item *) new gauge_instr( x, // x
437 load_fn, // data source
441 major_divs, minor_divs,
451 readLabel(const SGPropertyNode * node)
455 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? LARGE : SMALL;
457 name = node->getStringValue("name");
458 x = node->getIntValue("x");
459 y = node->getIntValue("y");
460 width = node->getIntValue("width");
461 height = node->getIntValue("height");
462 loadfn = node->getStringValue("data_source");
463 label_format = node->getStringValue("label_format");
464 prelabel = node->getStringValue("pre_label_string");
465 postlabel = node->getStringValue("post_label_string");
466 scaling = node->getFloatValue("scale_data");
467 options = node->getIntValue("options");
468 justi = node->getIntValue("justification");
469 blinking = node->getIntValue("blinking");
470 latitude = node->getBoolValue("latitude",false);
471 longitude = node->getBoolValue("longitude",false);
472 label_box = node->getBoolValue("label_box",false);//hud
473 working = node->getBoolValue("working");
474 digits = node->getIntValue("digits"); //suma
477 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
481 justification = LEFT_JUST;
484 justification = CENTER_JUST;
487 justification = RIGHT_JUST;
492 if ( prelabel == "NULL" ) {
493 pre_label_string = NULL;
495 if ( prelabel == "blank" ) {
496 pre_label_string = " ";
498 pre_label_string = prelabel.c_str();
502 if ( postlabel == "blank" ) {
503 post_label_string = " ";
505 if ( postlabel == "NULL" ) {
506 post_label_string = NULL;
508 if ( postlabel == "units" ) {
509 post_label_string = units;
511 post_label_string = postlabel.c_str();
516 if ( loadfn== "aux1" ) {
518 } else if ( loadfn == "aux2" ) {
520 } else if ( loadfn == "aux3" ) {
522 } else if ( loadfn == "aux4" ) {
524 } else if ( loadfn == "aux5" ) {
526 } else if ( loadfn == "aux6" ) {
528 } else if ( loadfn == "aux7" ) {
530 } else if ( loadfn == "aux8" ) {
532 } else if ( loadfn == "aux9" ) {
534 } else if ( loadfn == "aux10" ) {
536 } else if ( loadfn == "aux11" ) {
538 } else if ( loadfn == "aux12" ) {
540 } else if ( loadfn == "aux13" ) {
542 } else if ( loadfn == "aux14" ) {
544 } else if ( loadfn == "aux15" ) {
546 } else if ( loadfn == "aux16" ) {
548 } else if ( loadfn == "aux17" ) {
550 } else if ( loadfn == "aux18" ) {
552 } else if ( loadfn == "ax" ) {
554 } else if ( loadfn == "speed" ) {
556 } else if ( loadfn == "mach" ) {
558 } else if ( loadfn == "altitude" ) {
559 load_fn = get_altitude;
560 } else if ( loadfn == "agl" ) {
562 } else if ( loadfn == "framerate" ) {
563 load_fn = get_frame_rate;
564 } else if ( loadfn == "heading" ) {
565 load_fn = get_heading;
566 } else if ( loadfn == "fov" ) {
568 } else if ( loadfn == "vfc_tris_culled" ) {
569 load_fn = get_vfc_tris_culled;
570 } else if ( loadfn == "vfc_tris_drawn" ) {
571 load_fn = get_vfc_tris_drawn;
572 } else if ( loadfn == "aoa" ) {
574 } else if ( loadfn == "latitude" ) {
575 load_fn = get_latitude;
576 } else if ( loadfn == "anzg" ) {
578 } else if ( loadfn == "longitude" ) {
579 load_fn = get_longitude;
580 } else if (loadfn=="throttleval") {
581 load_fn = get_throttleval;
584 p = (instr_item *) new instr_label ( x,
589 label_format.c_str(),
607 readTBI(const SGPropertyNode * node)
612 name = node->getStringValue("name");
613 x = node->getIntValue("x");
614 y = node->getIntValue("y");
615 width = node->getIntValue("width");
616 height = node->getIntValue("height");
617 maxBankAngle = node->getFloatValue("maxBankAngle");
618 maxSlipAngle = node->getFloatValue("maxSlipAngle");
619 gap_width = node->getIntValue("gap_width");
620 working = node->getBoolValue("working");
621 tsi = node->getBoolValue("tsi"); //suma
622 rad = node->getFloatValue("rad"); //suma
624 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
627 p = (instr_item *) new fgTBI_instr( x,
644 int readInstrument(const SGPropertyNode * node)
649 if ( fgGetString("/sim/startup/units") == "feet" ) {
650 strcpy(units, " ft");
655 const SGPropertyNode * ladder_group = node->getNode("ladders");
657 if (ladder_group != 0) {
658 int nLadders = ladder_group->nChildren();
659 for (int j = 0; j < nLadders; j++) {
661 HIptr = readLadder(ladder_group->getChild(j));
662 HUD_deque.insert( HUD_deque.begin(), HIptr);
667 const SGPropertyNode * card_group = node->getNode("cards");
668 if (card_group != 0) {
669 int nCards = card_group->nChildren();
670 for (int j = 0; j < nCards; j++) {
672 HIptr = readCard(card_group->getChild(j));
673 HUD_deque.insert( HUD_deque.begin(), HIptr);
678 const SGPropertyNode * label_group = node->getNode("labels");
679 if (label_group != 0) {
680 int nLabels = label_group->nChildren();
681 for (int j = 0; j < nLabels; j++) {
683 HIptr = readLabel(label_group->getChild(j));
684 HUD_deque.insert( HUD_deque.begin(), HIptr);
689 const SGPropertyNode * tbi_group = node->getNode("tbis");
690 if (tbi_group != 0) {
691 int nTbis = tbi_group->nChildren();
692 for (int j = 0; j < nTbis; j++) {
694 HIptr = readTBI(tbi_group->getChild(j));
695 HUD_deque.insert( HUD_deque.begin(), HIptr);
700 }//end readinstrument
703 int readHud( istream &input )
709 readProperties(input, &root);
710 } catch (const sg_exception &e) {
711 guiErrorMessage("Error reading HUD: ", e);
716 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
717 root.getStringValue("name"));
720 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
723 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
725 const SGPropertyNode * instrument_group = root.getChild("instruments");
726 int nInstruments = instrument_group->nChildren();
728 for (int i = 0; i < nInstruments; i++) {
730 const SGPropertyNode * node = instrument_group->getChild(i);
732 SGPath path( globals->get_fg_root() );
733 path.append(node->getStringValue("path"));
735 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
741 SGPropertyNode root2;
743 readProperties(path.str(), &root2);
744 } catch (const sg_exception &e) {
745 guiErrorMessage("Error reading HUD instrument: ", e);
748 readInstrument(&root2);
755 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
761 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
764 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
765 SGPath path(globals->get_fg_root());
766 path.append(hud_path);
768 ifstream input(path.c_str());
770 SG_LOG(SG_INPUT, SG_ALERT,
771 "Cannot read Hud configuration from " << path.str());
780 return 0; // For now. Later we may use this for an error code.
784 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
789 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
791 SGPath path(globals->get_fg_root());
792 path.append("Huds/Minimal/default.xml");
795 ifstream input(path.c_str());
797 SG_LOG(SG_INPUT, SG_ALERT,
798 "Cannot read Hud configuration from " << path.str());
804 return 0; // For now. Later we may use this for an error code.
807 //$$$ End - added, Neetha, 28 Nov 2k
809 static int global_day_night_switch = DAY;
811 void HUD_masterswitch( bool incr )
813 if ( fgGetBool("/sim/hud/visibility") ) {
814 if ( global_day_night_switch == DAY ) {
815 global_day_night_switch = NIGHT;
817 fgSetBool("/sim/hud/visibility", false);
820 fgSetBool("/sim/hud/visibility", true);
821 global_day_night_switch = DAY;
825 void HUD_brightkey( bool incr_bright )
827 instr_item *pHUDInstr = HUD_deque[0];
828 int brightness = pHUDInstr->get_brightness();
830 if( fgGetBool("/sim/hud/visibility") ) {
835 brightness = BRT_BLACK;
839 brightness = BRT_LIGHT;
843 brightness = BRT_MEDIUM;
847 brightness = BRT_DARK;
851 brightness = BRT_BLACK;
857 brightness = BRT_MEDIUM;
861 brightness = BRT_DARK;
865 brightness = BRT_BLACK;
869 brightness = BRT_LIGHT;
873 fgSetBool("/sim/hud/visibility", false);
877 fgSetBool("/sim/hud/visibility", true);
880 pHUDInstr->SetBrightness( brightness );
884 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
886 static puDialogBox *HUDalphaDialog;
887 static puText *HUDalphaText;
888 static puSlider *HUDalphaHS0;
889 //static puText *HUDtextText;
890 //static puSlider *HUDalphaHS1;
891 static char SliderText[2][ 8 ];
893 static void alpha_adj( puObject *hs ) {
896 hs-> getValue ( &val ) ;
897 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
898 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
899 hud_trans_alpha = val;
900 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
901 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
904 void fgHUDalphaAdjust( puObject * ) {
905 fgSetBool("/sim/hud/antialiased", true);
906 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
909 static void goAwayHUDalphaAdjust (puObject *)
911 FG_POP_PUI_DIALOG( HUDalphaDialog );
914 static void cancelHUDalphaAdjust (puObject *)
916 fgSetBool("/sim/hud/antialiased", false);
917 FG_POP_PUI_DIALOG( HUDalphaDialog );
920 // Done once at system initialization
921 void fgHUDalphaInit( void ) {
923 // printf("fgHUDalphaInit\n");
924 #define HORIZONTAL FALSE
928 int DialogWidth = 240;
930 char Label[] = "HUD Adjuster";
933 int labelX = (DialogWidth / 2) -
934 (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
939 int slider_width = 220;
940 int slider_title_x = 15;
941 int slider_value_x = 160;
942 float slider_delta = 0.05f;
944 puFont HUDalphaLegendFont;
945 puFont HUDalphaLabelFont;
946 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
948 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
949 int horiz_slider_height = puGetStringHeight (HUDalphaLabelFont) +
950 puGetStringDescender (HUDalphaLabelFont) +
951 PUSTR_TGAP + PUSTR_BGAP + 5;
954 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
956 * horiz_slider_height ); */
959 HUDalphaDialogMessage = new puText ( labelX,
961 * horiz_slider_height );
962 HUDalphaDialogMessage -> setDefaultValue ( Label );
963 HUDalphaDialogMessage -> getDefaultValue ( &s );
964 HUDalphaDialogMessage -> setLabel ( s );
966 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
967 slider_width, HORIZONTAL ) ;
968 HUDalphaHS0-> setDelta ( slider_delta ) ;
969 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
970 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
971 HUDalphaHS0-> setCallback ( alpha_adj ) ;
974 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
975 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
976 HUDalphaTitle-> getDefaultValue ( &s ) ;
977 HUDalphaTitle-> setLabel ( s ) ;
979 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
980 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
981 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
984 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
985 HUDalphaOkButton-> setLegend ( gui_msg_OK );
986 HUDalphaOkButton-> makeReturnDefault ( TRUE );
987 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
990 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
991 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
992 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
994 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1000 void fgHUDReshape(void) {
1002 // this chunk of code is not necessarily thread safe if the
1003 // compiler optimizer reorders these statements. Note that
1004 // "delete ptr" does not set "ptr = NULL". We have to do that
1006 fntRenderer *tmp = HUDtext;
1011 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
1013 HUDtext = new fntRenderer();
1014 HUDtext -> setFont ( guiFntHandle ) ;
1015 HUDtext -> setPointSize ( HUD_TextSize ) ;
1016 HUD_TextList.setFont( HUDtext );
1020 static void set_hud_color(float r, float g, float b) {
1021 fgGetBool("/sim/hud/antialiased") ?
1022 glColor4f(r,g,b,hud_trans_alpha) :
1029 // Performs a once around the list of calls to instruments installed in
1030 // the HUD object with requests for redraw. Kinda. It will when this is
1033 void fgUpdateHUD( void ) {
1035 static const float normal_aspect = float(640) / float(480);
1036 // note: win_ratio is Y/X
1037 float current_aspect = 1.0f/globals->get_current_view()->get_win_ratio();
1038 if( current_aspect > normal_aspect ) {
1039 float aspect_adjust = current_aspect / normal_aspect;
1040 float adjust = 320.0f*aspect_adjust - 320.0f;
1041 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1043 float aspect_adjust = normal_aspect / current_aspect;
1044 float adjust = 240.0f*aspect_adjust - 240.0f;
1045 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1049 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1050 GLfloat x_end, GLfloat y_end )
1053 // int day_night_sw = current_aircraft.controls->day_night_switch;
1054 int day_night_sw = global_day_night_switch;
1055 int hud_displays = HUD_deque.size();
1056 instr_item *pHUDInstr;
1057 // float line_width;
1059 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1063 HUD_TextList.erase();
1064 HUD_LineList.erase();
1065 // HUD_StippleLineList.erase();
1067 pHUDInstr = HUD_deque[0];
1068 brightness = pHUDInstr->get_brightness();
1069 // brightness = HUD_deque.at(0)->get_brightness();
1071 glMatrixMode(GL_PROJECTION);
1075 gluOrtho2D(x_start, x_end, y_start, y_end);
1076 glMatrixMode(GL_MODELVIEW);
1080 glDisable(GL_DEPTH_TEST);
1081 glDisable(GL_LIGHTING);
1083 static const SGPropertyNode * antialiased_node
1084 = fgGetNode("/sim/hud/antialiased");
1086 if( antialiased_node->getBoolValue() ) {
1087 glEnable(GL_LINE_SMOOTH);
1088 // glEnable(GL_BLEND);
1089 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1090 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1096 if( day_night_sw == DAY) {
1100 set_hud_color (0.1f, 0.9f, 0.1f);
1104 set_hud_color (0.1f, 0.7f, 0.0f);
1108 set_hud_color (0.0f, 0.6f, 0.0f);
1112 set_hud_color( 0.0f, 0.0f, 0.0f);
1116 set_hud_color (0.1f, 0.9f, 0.1f);
1119 if( day_night_sw == NIGHT) {
1123 set_hud_color (0.9f, 0.1f, 0.1f);
1127 set_hud_color (0.7f, 0.0f, 0.1f);
1131 set_hud_color (0.6f, 0.0f, 0.0f);
1135 set_hud_color( 0.0f, 0.0f, 0.0f);
1139 set_hud_color (0.6f, 0.0f, 0.0f);
1141 } else { // Just in case default
1142 set_hud_color (0.1f, 0.9f, 0.1f);
1146 deque < instr_item * > :: iterator current = HUD_deque.begin();
1147 deque < instr_item * > :: iterator last = HUD_deque.end();
1149 for ( ; current != last; ++current ) {
1150 pHUDInstr = *current;
1152 if( pHUDInstr->enabled()) {
1153 // fgPrintf( SG_COCKPIT, SG_DEBUG, "HUD Code %d Status %d\n",
1154 // hud->code, hud->status );
1160 char *gmt_str = get_formated_gmt_time();
1161 HUD_TextList.add( fgText(40, 10, gmt_str, 0) );
1163 #ifdef FG_NETWORK_OLK
1164 if ( net_hud_display ) {
1171 // extern bool fgAPAltitudeEnabled( void );
1172 // extern bool fgAPHeadingEnabled( void );
1173 // extern bool fgAPWayPointEnabled( void );
1174 // extern char *fgAPget_TargetDistanceStr( void );
1175 // extern char *fgAPget_TargetHeadingStr( void );
1176 // extern char *fgAPget_TargetAltitudeStr( void );
1177 // extern char *fgAPget_TargetLatLonStr( void );
1180 // char scratch[128];
1181 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1183 if( current_autopilot->get_HeadingEnabled() ) {
1184 HUD_TextList.add( fgText( 40, apY,
1185 current_autopilot->get_TargetHeadingStr()) );
1188 if( current_autopilot->get_AltitudeEnabled() ) {
1189 HUD_TextList.add( fgText( 40, apY,
1190 current_autopilot->get_TargetAltitudeStr()) );
1193 if( current_autopilot->get_HeadingMode() ==
1194 FGAutopilot::FG_HEADING_WAYPOINT )
1197 wpstr = current_autopilot->get_TargetWP1Str();
1198 if ( strlen( wpstr ) ) {
1199 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1202 wpstr = current_autopilot->get_TargetWP2Str();
1203 if ( strlen( wpstr ) ) {
1204 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1207 wpstr = current_autopilot->get_TargetWP3Str();
1208 if ( strlen( wpstr ) ) {
1209 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1214 HUD_TextList.draw();
1216 HUD_LineList.draw();
1218 // glEnable(GL_LINE_STIPPLE);
1219 // glLineStipple( 1, 0x00FF );
1220 // HUD_StippleLineList.draw();
1221 // glDisable(GL_LINE_STIPPLE);
1223 if( antialiased_node->getBoolValue() ) {
1224 // glDisable(GL_BLEND);
1225 glDisable(GL_LINE_SMOOTH);
1229 glEnable(GL_DEPTH_TEST);
1230 glEnable(GL_LIGHTING);
1231 glMatrixMode(GL_PROJECTION);
1233 glMatrixMode(GL_MODELVIEW);