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
42 #include <string.h> // strcmp()
46 #include <simgear/constants.h>
47 #include <simgear/debug/logstream.hxx>
48 #include <simgear/misc/props.hxx>
49 #include <simgear/misc/sg_path.hxx>
50 //#include <simgear/math/fg_random.h>
51 //#include <simgear/math/polar3d.hxx>
53 #include <Aircraft/aircraft.hxx>
54 #include <Autopilot/newauto.hxx>
56 #include <Main/globals.hxx>
57 #include <Main/fg_props.hxx>
59 #include <NetworkOLK/network.h>
61 #include <Scenery/scenery.hxx>
62 //#include <Time/fg_timer.hxx>
64 #if defined ( __sun__ ) || defined ( __sgi )
66 extern void *memmove(void *, const void *, size_t);
74 // The following routines obtain information concerning the aircraft's
75 // current state and return it to calling instrument display routines.
76 // They should eventually be member functions of the aircraft.
79 deque< instr_item * > HUD_deque;
81 fgTextList HUD_TextList;
82 fgLineList HUD_LineList;
83 fgLineList HUD_StippleLineList;
85 fntRenderer *HUDtext = 0;
86 float HUD_TextSize = 0;
90 static float hud_trans_alpha = 0.67f;
93 //$$$ begin - added, Neetha, 28 Nov 2k
101 static float span_units;
102 static float division_units;
103 static float minor_division = 0;
104 static UINT screen_hole;
107 static string loadfn;
109 static float maxValue;
110 static float minValue;
111 static float scaling;
112 static UINT major_divs;
113 static UINT minor_divs;
114 static UINT modulator;
115 static int dp_showing = 0;
116 static string label_format;
117 static string prelabel;
118 static string postlabel;
121 static float maxBankAngle;
122 static float maxSlipAngle;
123 static UINT gap_width;
124 static bool latitude;
125 static bool longitude;
126 static bool tick_bottom;
127 static bool tick_top;
128 static bool tick_right;
129 static bool tick_left;
130 static bool cap_bottom;
132 static bool cap_right;
133 static bool cap_left;
134 static float marker_off;
136 static bool enable_pointer;
137 static string type_pointer;
138 static bool frl_spot;
140 static bool vel_vector;
144 static bool climb_dive;
146 static float glide_slope_val;
147 static bool worm_energy;
148 static bool waypoint;
149 static string type_tick;//hud
150 static string length_tick;//hud
151 static bool label_box;//hud
152 static int digits; //suma
153 static float radius; //suma
154 static int divisions; //suma
155 static int zoom; //suma
156 static int zenith; //suma
157 static int nadir ; //suma
158 static int hat; //suma
159 static bool tsi; //suma
160 static float rad; //suma
163 static FLTFNPTR load_fn;
164 static fgLabelJust justification;
165 static const char *pre_label_string = 0;
166 static const char *post_label_string = 0;
168 int readHud( istream &input );
169 int readInstrument ( const SGPropertyNode * node);
170 static instr_item * readLadder ( const SGPropertyNode * node);
171 static instr_item * readCard ( const SGPropertyNode * node);
172 static instr_item * readLabel( const SGPropertyNode * node);
173 static instr_item * readTBI( const SGPropertyNode * node);
174 //$$$ end - added, Neetha, 28 Nov 2k
176 void fgHUDalphaInit( void );
182 locRECT( UINT left, UINT top, UINT right, UINT bottom);
183 RECT get_rect(void) { return rect;}
186 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
191 rect.bottom = bottom;
197 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
205 void drawOneLine( RECT &rect)
208 glVertex2f(rect.left, rect.top);
209 glVertex2f(rect.right, rect.bottom);
214 // The following code deals with painting the "instrument" on the display
216 /* textString - Bitmap font string */
218 void textString( int x, int y, char *msg, void *font,int digit) //suma
222 // puDrawString ( NULL, msg, x, y );
225 glutBitmapCharacter(font, *msg);
232 /* strokeString - Stroke font string */
233 void strokeString(int x, int y, char *msg, void *font, float theta)
238 float sintheta,costheta;
243 glRotatef(theta * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
244 sintheta = sin(theta);
245 costheta = cos(theta);
246 xx = (int)(x * costheta + y * sintheta);
247 yy = (int)(y * costheta - x * sintheta);
248 glTranslatef( xx, yy, 0);
249 glScalef(.1, .1, 0.0);
250 while( (c=*msg++) ) {
251 glutStrokeCharacter(font, c);
257 int getStringWidth ( char *str )
259 if ( HUDtext && str ) {
261 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
262 return FloatToInt( r - l );
268 //========================= End of Class Implementations===================
271 // Constructs a HUD object and then adds in instruments. At the present
272 // the instruments are hard coded into the routine. Ultimately these need
273 // to be defined by the aircraft's instrumentation records so that the
274 // display for a Piper Cub doesn't show the speed range of a North American
275 // mustange and the engine readouts of a B36!
280 //$$$ begin - added, Neetha, 28 Nov 2k
282 readLadder(const SGPropertyNode * node)
287 name = node->getStringValue("name");
288 x = node->getIntValue("x");
289 y = node->getIntValue("y");
290 width = node->getIntValue("width");
291 height = node->getIntValue("height");
292 factor = node->getFloatValue("compression_factor");
293 span_units = node->getFloatValue("span_units");
294 division_units = node->getFloatValue("division_units");
295 screen_hole = node->getIntValue("screen_hole");
296 lbl_pos = node->getIntValue("lbl_pos");
297 frl_spot = node->getBoolValue("enable_frl",false);
298 target = node->getBoolValue("enable_target_spot",false);
299 vel_vector = node->getBoolValue("enable_velocity_vector",false);
300 drift = node->getBoolValue("enable_drift_marker",false);
301 alpha = node->getBoolValue("enable_alpha_bracket",false);
302 energy = node->getBoolValue("enable_energy_marker",false);
303 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
304 glide = node->getBoolValue("enable_glide_slope_marker",false);
305 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
306 worm_energy = node->getBoolValue("enable_energy_marker",false);
307 waypoint = node->getBoolValue("enable_waypoint_marker",false);
308 working = node->getBoolValue("working");
309 zenith = node->getIntValue("zenith"); //suma
310 nadir = node->getIntValue("nadir"); //suma
311 hat = node->getIntValue("hat");
314 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
317 p = (instr_item *) new HudLadder( name, x, y,
318 width, height, factor,
320 span_units, division_units, minor_division,
321 screen_hole, lbl_pos, frl_spot, target, vel_vector,
322 drift, alpha, energy, climb_dive,
323 glide, glide_slope_val, worm_energy,
324 waypoint, working, zenith, nadir, hat);
331 readCard(const SGPropertyNode * node)
336 name = node->getStringValue("name");
337 x = node->getIntValue("x");
338 y = node->getIntValue("y");
339 width = node->getIntValue("width");
340 height = node->getIntValue("height");
341 loadfn = node->getStringValue("loadfn");
342 options = node->getIntValue("options");
343 maxValue = node->getFloatValue("maxValue");
344 minValue = node->getFloatValue("minValue");
345 scaling = node->getFloatValue("disp_scaling");
346 major_divs = node->getIntValue("major_divs");
347 minor_divs = node->getIntValue("minor_divs");
348 modulator = node->getIntValue("modulator");
349 span_units = node->getFloatValue("value_span");
350 type = node->getStringValue("type");
351 tick_bottom = node->getBoolValue("tick_bottom",false);
352 tick_top = node->getBoolValue("tick_top",false);
353 tick_right = node->getBoolValue("tick_right",false);
354 tick_left = node->getBoolValue("tick_left",false);
355 cap_bottom = node->getBoolValue("cap_bottom",false);
356 cap_top = node->getBoolValue("cap_top",false);
357 cap_right = node->getBoolValue("cap_right",false);
358 cap_left = node->getBoolValue("cap_left",false);
359 marker_off = node->getFloatValue("marker_offset",0.0);
360 enable_pointer = node->getBoolValue("enable_pointer",true);
361 type_pointer = node->getStringValue("pointer_type");
362 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
363 length_tick = node->getStringValue("tick_length");//hud For variable length
364 working = node->getBoolValue("working");
365 radius = node->getFloatValue("radius"); //suma
366 divisions = node->getIntValue("divisions"); //suma
367 zoom = node->getIntValue("zoom"); //suma
369 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
373 span_units = maxValue - minValue;
376 if (loadfn=="anzg") {
378 } else if (loadfn=="heading") {
379 load_fn = get_heading;
380 } else if (loadfn=="aoa") {
382 } else if (loadfn=="climb") {
383 load_fn = get_climb_rate;
384 } else if (loadfn=="altitude") {
385 load_fn = get_altitude;
386 } else if (loadfn=="agl") {
388 } else if (loadfn=="speed") {
390 } else if (loadfn=="view_direction") {
391 load_fn = get_view_direction;
392 } else if (loadfn=="aileronval") {
393 load_fn = get_aileronval;
394 } else if (loadfn=="elevatorval") {
395 load_fn = get_elevatorval;
396 } else if (loadfn=="elevatortrimval") {
397 load_fn = get_elev_trimval;
398 } else if (loadfn=="rudderval") {
399 load_fn = get_rudderval;
400 } else if (loadfn=="throttleval") {
401 load_fn = get_throttleval;
405 if ( (type == "dial") | (type == "tape") ) {
406 p = (instr_item *) new hud_card( x,
414 major_divs, minor_divs,
438 p = (instr_item *) new gauge_instr( x, // x
442 load_fn, // data source
446 major_divs, minor_divs,
456 readLabel(const SGPropertyNode * node)
460 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? HUD_FONT_LARGE : HUD_FONT_SMALL;
462 name = node->getStringValue("name");
463 x = node->getIntValue("x");
464 y = node->getIntValue("y");
465 width = node->getIntValue("width");
466 height = node->getIntValue("height");
467 loadfn = node->getStringValue("data_source");
468 label_format = node->getStringValue("label_format");
469 prelabel = node->getStringValue("pre_label_string");
470 postlabel = node->getStringValue("post_label_string");
471 scaling = node->getFloatValue("scale_data");
472 options = node->getIntValue("options");
473 justi = node->getIntValue("justification");
474 blinking = node->getIntValue("blinking");
475 latitude = node->getBoolValue("latitude",false);
476 longitude = node->getBoolValue("longitude",false);
477 label_box = node->getBoolValue("label_box",false);//hud
478 working = node->getBoolValue("working");
479 digits = node->getIntValue("digits"); //suma
482 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
486 justification = LEFT_JUST;
489 justification = CENTER_JUST;
492 justification = RIGHT_JUST;
497 if ( prelabel == "NULL" ) {
498 pre_label_string = NULL;
500 if ( prelabel == "blank" ) {
501 pre_label_string = " ";
503 pre_label_string = prelabel.c_str();
507 if ( postlabel == "blank" ) {
508 post_label_string = " ";
510 if ( postlabel == "NULL" ) {
511 post_label_string = NULL;
513 if ( postlabel == "units" ) {
514 post_label_string = units;
516 post_label_string = postlabel.c_str();
521 if ( loadfn== "aux1" ) {
523 } else if ( loadfn == "aux2" ) {
525 } else if ( loadfn == "aux3" ) {
527 } else if ( loadfn == "aux4" ) {
529 } else if ( loadfn == "aux5" ) {
531 } else if ( loadfn == "aux6" ) {
533 } else if ( loadfn == "aux7" ) {
535 } else if ( loadfn == "aux8" ) {
537 } else if ( loadfn == "aux9" ) {
539 } else if ( loadfn == "aux10" ) {
541 } else if ( loadfn == "aux11" ) {
543 } else if ( loadfn == "aux12" ) {
545 } else if ( loadfn == "aux13" ) {
547 } else if ( loadfn == "aux14" ) {
549 } else if ( loadfn == "aux15" ) {
551 } else if ( loadfn == "aux16" ) {
553 } else if ( loadfn == "aux17" ) {
555 } else if ( loadfn == "aux18" ) {
557 } else if ( loadfn == "ax" ) {
559 } else if ( loadfn == "speed" ) {
561 } else if ( loadfn == "mach" ) {
563 } else if ( loadfn == "altitude" ) {
564 load_fn = get_altitude;
565 } else if ( loadfn == "agl" ) {
567 } else if ( loadfn == "framerate" ) {
568 load_fn = get_frame_rate;
569 } else if ( loadfn == "heading" ) {
570 load_fn = get_heading;
571 } else if ( loadfn == "fov" ) {
573 } else if ( loadfn == "vfc_tris_culled" ) {
574 load_fn = get_vfc_tris_culled;
575 } else if ( loadfn == "vfc_tris_drawn" ) {
576 load_fn = get_vfc_tris_drawn;
577 } else if ( loadfn == "aoa" ) {
579 } else if ( loadfn == "latitude" ) {
580 load_fn = get_latitude;
581 } else if ( loadfn == "anzg" ) {
583 } else if ( loadfn == "longitude" ) {
584 load_fn = get_longitude;
585 } else if (loadfn=="throttleval") {
586 load_fn = get_throttleval;
589 p = (instr_item *) new instr_label ( x,
594 label_format.c_str(),
612 readTBI(const SGPropertyNode * node)
617 name = node->getStringValue("name");
618 x = node->getIntValue("x");
619 y = node->getIntValue("y");
620 width = node->getIntValue("width");
621 height = node->getIntValue("height");
622 maxBankAngle = node->getFloatValue("maxBankAngle");
623 maxSlipAngle = node->getFloatValue("maxSlipAngle");
624 gap_width = node->getIntValue("gap_width");
625 working = node->getBoolValue("working");
626 tsi = node->getBoolValue("tsi"); //suma
627 rad = node->getFloatValue("rad"); //suma
629 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
632 p = (instr_item *) new fgTBI_instr( x,
649 int readInstrument(const SGPropertyNode * node)
651 static const SGPropertyNode *startup_units_node
652 = fgGetNode("/sim/startup/units");
656 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
657 strcpy(units, " ft");
662 const SGPropertyNode * ladder_group = node->getNode("ladders");
664 if (ladder_group != 0) {
665 int nLadders = ladder_group->nChildren();
666 for (int j = 0; j < nLadders; j++) {
668 HIptr = readLadder(ladder_group->getChild(j));
669 HUD_deque.insert( HUD_deque.begin(), HIptr);
674 const SGPropertyNode * card_group = node->getNode("cards");
675 if (card_group != 0) {
676 int nCards = card_group->nChildren();
677 for (int j = 0; j < nCards; j++) {
679 HIptr = readCard(card_group->getChild(j));
680 HUD_deque.insert( HUD_deque.begin(), HIptr);
685 const SGPropertyNode * label_group = node->getNode("labels");
686 if (label_group != 0) {
687 int nLabels = label_group->nChildren();
688 for (int j = 0; j < nLabels; j++) {
690 HIptr = readLabel(label_group->getChild(j));
691 HUD_deque.insert( HUD_deque.begin(), HIptr);
696 const SGPropertyNode * tbi_group = node->getNode("tbis");
697 if (tbi_group != 0) {
698 int nTbis = tbi_group->nChildren();
699 for (int j = 0; j < nTbis; j++) {
701 HIptr = readTBI(tbi_group->getChild(j));
702 HUD_deque.insert( HUD_deque.begin(), HIptr);
707 }//end readinstrument
710 int readHud( istream &input )
716 readProperties(input, &root);
717 } catch (const sg_exception &e) {
718 guiErrorMessage("Error reading HUD: ", e);
723 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
724 root.getStringValue("name"));
727 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
730 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
732 const SGPropertyNode * instrument_group = root.getChild("instruments");
733 int nInstruments = instrument_group->nChildren();
735 for (int i = 0; i < nInstruments; i++) {
737 const SGPropertyNode * node = instrument_group->getChild(i);
739 SGPath path( globals->get_fg_root() );
740 path.append(node->getStringValue("path"));
742 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
748 SGPropertyNode root2;
750 readProperties(path.str(), &root2);
751 } catch (const sg_exception &e) {
752 guiErrorMessage("Error reading HUD instrument: ", e);
755 readInstrument(&root2);
762 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
768 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
771 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
772 SGPath path(globals->get_fg_root());
773 path.append(hud_path);
775 ifstream input(path.c_str());
777 SG_LOG(SG_INPUT, SG_ALERT,
778 "Cannot read Hud configuration from " << path.str());
787 return 0; // For now. Later we may use this for an error code.
791 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
796 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
798 SGPath path(globals->get_fg_root());
799 path.append("Huds/Minimal/default.xml");
802 ifstream input(path.c_str());
804 SG_LOG(SG_INPUT, SG_ALERT,
805 "Cannot read Hud configuration from " << path.str());
811 return 0; // For now. Later we may use this for an error code.
814 //$$$ End - added, Neetha, 28 Nov 2k
816 static int global_day_night_switch = HUD_DAY;
818 void HUD_masterswitch( bool incr )
820 if ( fgGetBool("/sim/hud/visibility") ) {
821 if ( global_day_night_switch == HUD_DAY ) {
822 global_day_night_switch = HUD_NIGHT;
824 fgSetBool("/sim/hud/visibility", false);
827 fgSetBool("/sim/hud/visibility", true);
828 global_day_night_switch = HUD_DAY;
832 void HUD_brightkey( bool incr_bright )
834 instr_item *pHUDInstr = HUD_deque[0];
835 int brightness = pHUDInstr->get_brightness();
837 if( fgGetBool("/sim/hud/visibility") ) {
842 brightness = HUD_BRT_BLACK;
846 brightness = HUD_BRT_LIGHT;
850 brightness = HUD_BRT_MEDIUM;
854 brightness = HUD_BRT_DARK;
858 brightness = HUD_BRT_BLACK;
864 brightness = HUD_BRT_MEDIUM;
868 brightness = HUD_BRT_DARK;
872 brightness = HUD_BRT_BLACK;
876 brightness = HUD_BRT_LIGHT;
880 fgSetBool("/sim/hud/visibility", false);
884 fgSetBool("/sim/hud/visibility", true);
887 pHUDInstr->SetBrightness( brightness );
891 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
893 static puDialogBox *HUDalphaDialog;
894 static puText *HUDalphaText;
895 static puSlider *HUDalphaHS0;
896 //static puText *HUDtextText;
897 //static puSlider *HUDalphaHS1;
898 static char SliderText[2][ 8 ];
900 static void alpha_adj( puObject *hs ) {
903 hs-> getValue ( &val ) ;
904 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
905 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
906 hud_trans_alpha = val;
907 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
908 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
911 void fgHUDalphaAdjust( puObject * ) {
912 fgSetBool("/sim/hud/antialiased", true);
913 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
916 static void goAwayHUDalphaAdjust (puObject *)
918 FG_POP_PUI_DIALOG( HUDalphaDialog );
921 static void cancelHUDalphaAdjust (puObject *)
923 fgSetBool("/sim/hud/antialiased", false);
924 FG_POP_PUI_DIALOG( HUDalphaDialog );
927 // Done once at system initialization
928 void fgHUDalphaInit( void ) {
930 // printf("fgHUDalphaInit\n");
931 #define HORIZONTAL FALSE
935 int DialogWidth = 240;
937 char Label[] = "HUD Adjuster";
940 int labelX = (DialogWidth / 2) -
941 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
946 int slider_width = 220;
947 int slider_title_x = 15;
948 int slider_value_x = 160;
949 float slider_delta = 0.05f;
951 puFont HUDalphaLegendFont;
952 puFont HUDalphaLabelFont;
953 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
955 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
956 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
957 HUDalphaLabelFont.getStringDescender() +
958 PUSTR_TGAP + PUSTR_BGAP + 5;
961 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
963 * horiz_slider_height ); */
966 HUDalphaDialogMessage = new puText ( labelX,
968 * horiz_slider_height );
969 HUDalphaDialogMessage -> setDefaultValue ( Label );
970 HUDalphaDialogMessage -> getDefaultValue ( &s );
971 HUDalphaDialogMessage -> setLabel ( s );
973 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
974 slider_width, HORIZONTAL ) ;
975 HUDalphaHS0-> setDelta ( slider_delta ) ;
976 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
977 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
978 HUDalphaHS0-> setCallback ( alpha_adj ) ;
981 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
982 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
983 HUDalphaTitle-> getDefaultValue ( &s ) ;
984 HUDalphaTitle-> setLabel ( s ) ;
986 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
987 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
988 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
991 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
992 HUDalphaOkButton-> setLegend ( gui_msg_OK );
993 HUDalphaOkButton-> makeReturnDefault ( TRUE );
994 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
997 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
998 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
999 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
1001 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1007 void fgHUDReshape(void) {
1009 // this chunk of code is not necessarily thread safe if the
1010 // compiler optimizer reorders these statements. Note that
1011 // "delete ptr" does not set "ptr = NULL". We have to do that
1013 fntRenderer *tmp = HUDtext;
1018 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
1020 HUDtext = new fntRenderer();
1021 HUDtext -> setFont ( guiFntHandle ) ;
1022 HUDtext -> setPointSize ( HUD_TextSize ) ;
1023 HUD_TextList.setFont( HUDtext );
1027 static void set_hud_color(float r, float g, float b) {
1028 fgGetBool("/sim/hud/antialiased") ?
1029 glColor4f(r,g,b,hud_trans_alpha) :
1036 // Performs a once around the list of calls to instruments installed in
1037 // the HUD object with requests for redraw. Kinda. It will when this is
1040 void fgUpdateHUD( void ) {
1042 static const float normal_aspect = float(640) / float(480);
1043 // note: aspect_ratio is Y/X
1044 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1045 if( current_aspect > normal_aspect ) {
1046 float aspect_adjust = current_aspect / normal_aspect;
1047 float adjust = 320.0f*aspect_adjust - 320.0f;
1048 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1050 float aspect_adjust = normal_aspect / current_aspect;
1051 float adjust = 240.0f*aspect_adjust - 240.0f;
1052 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1056 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1057 GLfloat x_end, GLfloat y_end )
1060 // int day_night_sw = current_aircraft.controls->day_night_switch;
1061 int day_night_sw = global_day_night_switch;
1062 int hud_displays = HUD_deque.size();
1063 instr_item *pHUDInstr;
1064 // float line_width;
1066 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1070 HUD_TextList.erase();
1071 HUD_LineList.erase();
1072 // HUD_StippleLineList.erase();
1074 pHUDInstr = HUD_deque[0];
1075 brightness = pHUDInstr->get_brightness();
1076 // brightness = HUD_deque.at(0)->get_brightness();
1078 glMatrixMode(GL_PROJECTION);
1082 gluOrtho2D(x_start, x_end, y_start, y_end);
1083 glMatrixMode(GL_MODELVIEW);
1087 glDisable(GL_DEPTH_TEST);
1088 glDisable(GL_LIGHTING);
1090 static const SGPropertyNode * antialiased_node
1091 = fgGetNode("/sim/hud/antialiased");
1093 if( antialiased_node->getBoolValue() ) {
1094 glEnable(GL_LINE_SMOOTH);
1095 // glEnable(GL_BLEND);
1096 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1097 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1103 if( day_night_sw == HUD_DAY) {
1107 set_hud_color (0.1f, 0.9f, 0.1f);
1110 case HUD_BRT_MEDIUM:
1111 set_hud_color (0.1f, 0.7f, 0.0f);
1115 set_hud_color (0.0f, 0.6f, 0.0f);
1119 set_hud_color( 0.0f, 0.0f, 0.0f);
1123 set_hud_color (0.1f, 0.9f, 0.1f);
1126 if( day_night_sw == HUD_NIGHT) {
1130 set_hud_color (0.9f, 0.1f, 0.1f);
1133 case HUD_BRT_MEDIUM:
1134 set_hud_color (0.7f, 0.0f, 0.1f);
1138 set_hud_color (0.6f, 0.0f, 0.0f);
1142 set_hud_color( 0.0f, 0.0f, 0.0f);
1146 set_hud_color (0.6f, 0.0f, 0.0f);
1148 } else { // Just in case default
1149 set_hud_color (0.1f, 0.9f, 0.1f);
1153 deque < instr_item * > :: iterator current = HUD_deque.begin();
1154 deque < instr_item * > :: iterator last = HUD_deque.end();
1156 for ( ; current != last; ++current ) {
1157 pHUDInstr = *current;
1159 if( pHUDInstr->enabled()) {
1160 // fgPrintf( SG_COCKPIT, SG_DEBUG, "HUD Code %d Status %d\n",
1161 // hud->code, hud->status );
1167 char *gmt_str = get_formated_gmt_time();
1168 HUD_TextList.add( fgText(40, 10, gmt_str, 0) );
1170 #ifdef FG_NETWORK_OLK
1171 if ( net_hud_display ) {
1178 // extern bool fgAPAltitudeEnabled( void );
1179 // extern bool fgAPHeadingEnabled( void );
1180 // extern bool fgAPWayPointEnabled( void );
1181 // extern char *fgAPget_TargetDistanceStr( void );
1182 // extern char *fgAPget_TargetHeadingStr( void );
1183 // extern char *fgAPget_TargetAltitudeStr( void );
1184 // extern char *fgAPget_TargetLatLonStr( void );
1187 // char scratch[128];
1188 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1190 if( globals->get_autopilot()->get_HeadingEnabled() ) {
1191 HUD_TextList.add( fgText( 40, apY,
1192 globals->get_autopilot()->get_TargetHeadingStr()) );
1195 if( globals->get_autopilot()->get_AltitudeEnabled() ) {
1196 HUD_TextList.add( fgText( 40, apY,
1197 globals->get_autopilot()->get_TargetAltitudeStr()) );
1200 if( globals->get_autopilot()->get_HeadingMode() ==
1201 FGAutopilot::FG_HEADING_WAYPOINT )
1204 wpstr = globals->get_autopilot()->get_TargetWP1Str();
1205 if ( strlen( wpstr ) ) {
1206 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1209 wpstr = globals->get_autopilot()->get_TargetWP2Str();
1210 if ( strlen( wpstr ) ) {
1211 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1214 wpstr = globals->get_autopilot()->get_TargetWP3Str();
1215 if ( strlen( wpstr ) ) {
1216 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1221 HUD_TextList.draw();
1223 HUD_LineList.draw();
1225 // glEnable(GL_LINE_STIPPLE);
1226 // glLineStipple( 1, 0x00FF );
1227 // HUD_StippleLineList.draw();
1228 // glDisable(GL_LINE_STIPPLE);
1230 if( antialiased_node->getBoolValue() ) {
1231 // glDisable(GL_BLEND);
1232 glDisable(GL_LINE_SMOOTH);
1236 glEnable(GL_DEPTH_TEST);
1237 glEnable(GL_LIGHTING);
1238 glMatrixMode(GL_PROJECTION);
1240 glMatrixMode(GL_MODELVIEW);