10 #include <Aircraft/aircraft.hxx>
12 #include <Include/fg_constants.h>
13 #include <Math/fg_random.h>
14 #include <Math/mat3.h>
15 #include <Math/polar3d.hxx>
16 #include <Scenery/scenery.hxx>
17 #include <Time/fg_timer.hxx>
21 #ifdef USE_HUD_TextList
22 #define textString( x , y, text, font ) TextString( text, x , y )
24 #define textString( x , y, text, font ) puDrawString ( guiFnt, text, x, y );
27 //========== Top of hud_card class member definitions =============
36 float max_value, // 360
45 instr_scale( x,y,width,height,
48 max_value, min_value, disp_scaling,
49 major_divs, minor_divs, modulus,
51 val_span ( value_span)
53 half_width_units = range_to_show() / 2.0;
54 // UINT options = get_options();
55 // huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
56 // huds_right = options & HUDS_RIGHT;
57 // huds_left = options & HUDS_LEFT;
58 // huds_vert = options & HUDS_VERT;
59 // huds_notext = options & HUDS_NOTEXT;
60 // huds_top = options & HUDS_TOP;
61 // huds_bottom = options & HUDS_BOTTOM;
68 hud_card( const hud_card & image):
69 instr_scale( (const instr_scale & ) image),
70 val_span( image.val_span),
71 half_width_units (image.half_width_units)
73 // UINT options = get_options();
74 // huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
75 // huds_right = options & HUDS_RIGHT;
76 // huds_left = options & HUDS_LEFT;
77 // huds_vert = options & HUDS_VERT;
78 // huds_notext = options & HUDS_NOTEXT;
79 // huds_top = options & HUDS_TOP;
80 // huds_bottom = options & HUDS_BOTTOM;
83 hud_card & hud_card ::
84 operator = (const hud_card & rhs )
86 if( !( this == &rhs)){
87 instr_scale::operator = (rhs);
88 val_span = rhs.val_span;
89 half_width_units = rhs.half_width_units;
95 draw( void ) // (HUD_scale * pscale )
108 POINT mid_scr = get_centroid();
109 float cur_value = get_value();
110 RECT scrn_rect = get_location();
111 UINT options = get_options();
113 height = scrn_rect.top + scrn_rect.bottom;
114 width = scrn_rect.left + scrn_rect.right;
116 vmin = cur_value - half_width_units; // width units == needle travel
117 vmax = cur_value + half_width_units; // or picture unit span.
119 // Draw the basic markings for the scale...
121 if( huds_vert(options) ) { // Vertical scale
122 drawOneLine( scrn_rect.left, // Bottom tick bar
127 drawOneLine( scrn_rect.left, // Top tick bar
132 marker_xs = scrn_rect.left; // x start
133 marker_xe = width; // x extent
136 // glBegin(GL_LINES);
139 // glVertex2f( marker_xs, scrn_rect.top);
140 // glVertex2f( marker_xe, scrn_rect.top);
143 // glVertex2f( marker_xs, marker_ye);
144 // glVertex2f( marker_xe, marker_ye );
147 // We do not use else in the following so that combining the two
148 // options produces a "caged" display with double carrots. The
149 // same is done for horizontal card indicators.
151 if( huds_left(options) ) { // Calculate x marker offset
152 drawOneLine( marker_xe, scrn_rect.top,
153 marker_xe, marker_ye); // Cap right side
155 marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
157 // drawOneLine( marker_xs, mid_scr.y,
158 // marker_xe, mid_scr.y + scrn_rect.right / 6);
159 // drawOneLine( marker_xs, mid_scr.y,
160 // marker_xe, mid_scr.y - scrn_rect.right / 6);
162 glBegin(GL_LINE_STRIP);
163 glVertex2f( marker_xe, mid_scr.y + scrn_rect.right / 6);
164 glVertex2f( marker_xs, mid_scr.y);
165 glVertex2f( marker_xe, mid_scr.y - scrn_rect.right / 6);
168 if( huds_right(options) ) { // We'll default this for now.
169 drawOneLine( scrn_rect.left, scrn_rect.top,
170 scrn_rect.left, marker_ye ); // Cap left side
172 marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
174 // drawOneLine( scrn_rect.left, mid_scr.y + scrn_rect.right / 6,
175 // marker_xe, mid_scr.y );
176 // drawOneLine( scrn_rect.left, mid_scr.y - scrn_rect.right / 6,
177 // marker_xe, mid_scr.y);
178 glBegin(GL_LINE_STRIP);
179 glVertex2f( scrn_rect.left, mid_scr.y + scrn_rect.right / 6);
180 glVertex2f( marker_xe, mid_scr.y );
181 glVertex2f( scrn_rect.left, mid_scr.y - scrn_rect.right / 6);
185 // At this point marker x_start and x_end values are transposed.
186 // To keep this from confusing things they are now interchanged.
187 if(huds_both(options)) {
188 marker_ye = marker_xs;
189 marker_xs = marker_xe;
190 marker_xe = marker_ye;
193 // Work through from bottom to top of scale. Calculating where to put
194 // minor and major ticks.
196 // last = FloatToInt(vmax)+1;
197 // i = FloatToInt(vmin);
198 last = (int)vmax + 1;
200 for( ; i <last ; i++ )
209 if( condition ) { // Show a tick if necessary
210 // Calculate the location of this tick
211 marker_ys = scrn_rect.top + FloatToInt(((i - vmin) * factor()/*+.5f*/));
212 // marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
213 // Block calculation artifact from drawing ticks below min coordinate.
214 // Calculation here accounts for text height.
216 if(( marker_ys < (scrn_rect.top + 4)) |
217 ( marker_ys > (height - 4))) {
222 // if( (i%div_min()) == 0) {
223 if( !(i%(int)div_min())) {
224 if((( marker_ys - 5) > scrn_rect.top ) &&
225 (( marker_ys + 5) < (height))){
226 if( huds_both(options) ) {
227 drawOneLine( scrn_rect.left, marker_ys,
228 marker_xs, marker_ys );
229 drawOneLine( marker_xe, marker_ys,
231 // glBegin(GL_LINES);
232 // glVertex2f( scrn_rect.left, marker_ys );
233 // glVertex2f( marker_xs, marker_ys );
234 // glVertex2f( marker_xe, marker_ys);
235 // glVertex2f( scrn_rect.left + scrn_rect.right, marker_ys );
239 if( huds_left(options) ) {
240 drawOneLine( marker_xs + 4, marker_ys,
241 marker_xe, marker_ys );
244 drawOneLine( marker_xs, marker_ys,
245 marker_xe - 4, marker_ys );
252 if( !(i%(int)div_max()) )
257 disp_val += modulo();
259 // disp_val = i % (int)modulo();
261 disp_val = i % (int) modulo(); // ?????????
266 lenstr = sprintf( TextScale, "%d",
267 FloatToInt(disp_val * data_scaling()/*+.5*/));
268 // (int)(disp_val * data_scaling() +.5));
269 if(( (marker_ys - 8 ) > scrn_rect.top ) &&
270 ( (marker_ys + 8) < (height))){
271 if( huds_both(options) ) {
272 // drawOneLine( scrn_rect.left, marker_ys,
273 // marker_xs, marker_ys);
274 // drawOneLine( marker_xs, marker_ys,
275 // scrn_rect.left + scrn_rect.right,
277 glBegin(GL_LINE_STRIP);
278 glVertex2f( scrn_rect.left, marker_ys );
279 glVertex2f( marker_xs, marker_ys);
280 glVertex2f( width, marker_ys);
282 if( !huds_notext(options)) {
283 textString ( marker_xs + 2, marker_ys,
284 TextScale, GLUT_BITMAP_8_BY_13 );
288 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
289 if( !huds_notext(options) ) {
290 if( huds_left(options) ) {
291 textString( marker_xs - 8 * lenstr - 2,
293 TextScale, GLUT_BITMAP_8_BY_13 );
296 textString( marker_xe + 3 * lenstr,
298 TextScale, GLUT_BITMAP_8_BY_13 );
302 } // Else read oriented right
303 } // End if modulo division by major interval is zero
304 } // End if major interval divisor non-zero
305 } // End if condition
306 } // End for range of i from vmin to vmax
307 } // End if VERTICAL SCALE TYPE
308 else { // Horizontal scale by default
310 drawOneLine( scrn_rect.left, scrn_rect.top,
311 scrn_rect.left, height);
314 drawOneLine( width, scrn_rect.top,
318 marker_ys = scrn_rect.top; // Starting point for
319 marker_ye = height; // tick y location calcs
322 // glBegin(GL_LINES);
324 // glVertex2f( scrn_rect.left, scrn_rect.top);
325 // glVertex2f( scrn_rect.left, marker_ye);
328 // glVertex2f( marker_xe, scrn_rect.top);
329 // glVertex2f( marker_xe, marker_ye );
332 if( huds_top(options) ) {
334 drawOneLine( scrn_rect.left,
340 marker_ye = scrn_rect.top + scrn_rect.bottom / 2;
343 // drawOneLine( mid_scr.x, marker_ye,
344 // mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
345 // drawOneLine( mid_scr.x, marker_ye,
346 // mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
348 glBegin(GL_LINE_STRIP);
349 glVertex2f( mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
350 glVertex2f( mid_scr.x, marker_ye);
351 glVertex2f( mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
354 if( huds_bottom(options) ) {
356 drawOneLine( scrn_rect.left, height,
359 marker_ys = height - scrn_rect.bottom / 2;
362 // drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
363 // scrn_rect.top + scrn_rect.bottom,
364 // mid_scr.x, marker_ys );
365 // drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
366 // scrn_rect.top + scrn_rect.bottom,
367 // mid_scr.x , marker_ys );
368 glBegin(GL_LINE_STRIP);
369 glVertex2f( mid_scr.x + scrn_rect.bottom / 4,
371 glVertex2f( mid_scr.x , marker_ys );
372 glVertex2f( mid_scr.x - scrn_rect.bottom / 4,
377 // if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
378 // marker_xe = marker_ys;
379 // marker_ys = marker_ye;
380 // marker_ye = marker_xe;
383 // printf("vmin = %d vmax = %d\n", (int)vmin, (int)vmax);
385 // last = FloatToInt(vmax)+1;
386 // i = FloatToInt(vmin);
387 last = (int)vmax + 1;
389 for(; i <last ; i++ ) {
390 // for( i = (int)vmin; i <= (int)vmax; i++ ) {
391 // printf("<*> i = %d\n", i);
398 // printf("<**> i = %d\n", i);
400 // marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
401 marker_xs = scrn_rect.left + FloatToInt(((i - vmin) * factor()/*+ .5f*/));
403 // if( (i%(int)div_min()) == 0 ) {
404 if( !(i%(int)div_min() )) {
405 // draw in ticks only if they aren't too close to the edge.
406 if((( marker_xs - 5) > scrn_rect.left ) &&
407 (( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
409 if( huds_both(options) ) {
410 drawOneLine( marker_xs, scrn_rect.top,
411 marker_xs, marker_ys - 4);
412 drawOneLine( marker_xs, marker_ye + 4,
414 // glBegin(GL_LINES);
415 // glVertex2f( marker_xs, scrn_rect.top);
416 // glVertex2f( marker_xs, marker_ys - 4);
417 // glVertex2f( marker_xs, marker_ye + 4);
418 // glVertex2f( marker_xs, scrn_rect.top + scrn_rect.bottom);
422 if( huds_top(options)) {
423 drawOneLine( marker_xs, marker_ys,
424 marker_xs, marker_ye - 4);
427 drawOneLine( marker_xs, marker_ys + 4,
428 marker_xs, marker_ye);
434 // printf("<***> i = %d\n", i);
436 // printf("i = %d\n", i);
437 // if( (i%(int)div_max())==0 ) {
438 if( !(i%(int)div_max()) ) {
442 disp_val += modulo();
444 disp_val = i % (int) modulo(); // ?????????
448 // printf("disp_val = %d\n", disp_val);
449 // printf("%d\n", (int)(disp_val * (double)data_scaling() + 0.5));
450 lenstr = sprintf( TextScale, "%d",
451 // (int)(disp_val * data_scaling() +.5));
452 FloatToInt(disp_val * data_scaling()/*+.5*/));
453 // Draw major ticks and text only if far enough from the edge.
454 if(( (marker_xs - 10)> scrn_rect.left ) &&
455 ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
456 if( huds_both(options) ) {
457 // drawOneLine( marker_xs, scrn_rect.top,
458 // marker_xs, marker_ys);
459 // drawOneLine( marker_xs, marker_ye,
460 // marker_xs, scrn_rect.top + scrn_rect.bottom);
461 glBegin(GL_LINE_STRIP);
462 glVertex2f( marker_xs, scrn_rect.top);
463 glVertex2f( marker_xs, marker_ye);
464 glVertex2f( marker_xs, height);
466 if( !huds_notext(options) ) {
467 textString ( marker_xs - 4 * lenstr,
469 TextScale, GLUT_BITMAP_8_BY_13 );
473 drawOneLine( marker_xs, marker_ys,
474 marker_xs, marker_ye );
475 if( !huds_notext(options)) {
476 if( huds_top(options) ) {
477 textString ( marker_xs - 4 * lenstr,
479 TextScale, GLUT_BITMAP_8_BY_13 );
482 textString( marker_xs - 4 * lenstr,
484 TextScale, GLUT_BITMAP_8_BY_13 );
491 // printf("<****> i = %d\n", i);