12 #include <simgear/constants.h>
13 #include <simgear/math/fg_random.h>
14 #include <simgear/math/polar3d.hxx>
16 #include <Aircraft/aircraft.hxx>
18 #include <Scenery/scenery.hxx>
19 #include <Time/fg_timer.hxx>
24 #ifdef USE_HUD_TextList
25 #define textString( x , y, text, font ) TextString( text, x , y )
27 #define textString( x , y, text, font ) puDrawString ( guiFnt, text, x, y );
30 //======================= Top of instr_label class =========================
37 // DBLFNPTR data_source,
38 const char *label_format,
39 const char *pre_label_string,
40 const char *post_label_string,
44 fgLabelJust justification,
48 instr_item( x, y, width, height,
49 data_source, scale_data,options, working ),
50 pformat ( label_format ),
51 pre_str ( pre_label_string ),
52 post_str ( post_label_string ),
53 justify ( justification ),
54 fontSize ( font_size ),
57 if( pre_str != NULL) {
58 if( post_str != NULL ) {
59 sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
62 sprintf( format_buffer, "%s%s", pre_str, pformat );
66 if( post_str != NULL ) {
67 sprintf( format_buffer, "%s%s", pformat, post_str );
69 } // else do nothing if both pre and post strings are nulls. Interesting.
73 // I put this in to make it easy to construct a class member using the current
77 lon_label :: ~lon_label()
82 lon_label :: lon_label( const lon_label & image) :
83 instr_item((const instr_item &)image),
84 pformat ( image.pformat ),
85 pre_str ( image.pre_str ),
86 post_str ( image.post_str ),
89 if( pre_str != NULL) {
90 if( post_str != NULL ) {
91 sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
94 sprintf( format_buffer, "%s%s", pre_str, pformat );
98 if( post_str != NULL ) {
99 sprintf( format_buffer, "%s%s", pformat, post_str );
101 } // else do nothing if both pre and post strings are nulls. Interesting.
105 lon_label & lon_label ::operator = (const lon_label & rhs )
107 if( !(this == &rhs)) {
108 instr_item::operator = (rhs);
109 pformat = rhs.pformat;
110 fontSize = rhs.fontSize;
112 justify = rhs.justify;
113 pre_str = rhs.pre_str;
114 post_str = rhs.post_str;
115 strcpy(format_buffer,rhs.format_buffer);
121 // draw Draws a label anywhere in the HUD
125 draw( void ) // Required method in base class
127 // char format_buffer[80];
128 char label_buffer[80];
131 RECT scrn_rect = get_location();
132 float lon = get_value();
133 // double lon = get_value();
134 if( data_available() ) {
135 // char *lonstring = coord_format_lon(lon);
136 lenstr = sprintf( label_buffer, format_buffer, coord_format_lon(lon) );
139 lenstr = sprintf( label_buffer, format_buffer );
143 fgPrintf( FG_COCKPIT, FG_DEBUG, format_buffer );
144 fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
145 fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
146 fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
149 lenstr = getStringWidth(label_buffer);
151 if( justify == RIGHT_JUST ) {
152 posincr = scrn_rect.right - lenstr;
153 }else if( justify == CENTER_JUST ) {
154 posincr = get_span() - (lenstr/2); // -lenstr*4;
156 // justify == LEFT_JUST
160 if( fontSize == SMALL ) {
161 textString( scrn_rect.left + posincr, scrn_rect.top,
162 label_buffer, GLUT_BITMAP_8_BY_13);
165 if( fontSize == LARGE ) {
166 textString( scrn_rect.left + posincr, scrn_rect.top,
167 label_buffer, GLUT_BITMAP_9_BY_15);