10 #include <Aircraft/aircraft.hxx>
11 #include <Include/fg_constants.h>
12 #include <Math/fg_random.h>
13 #include <Math/mat3.h>
14 #include <Math/polar3d.hxx>
15 #include <Scenery/scenery.hxx>
16 #include <Time/fg_timer.hxx>
20 //========== Top of hud_card class member definitions =============
38 instr_scale( x,y,width,height,
41 max_value, min_value, disp_scaling,
42 major_divs, minor_divs, modulus,
44 val_span ( value_span)
46 half_width_units = range_to_show() / 2.0;
53 hud_card( const hud_card & image):
54 instr_scale( (const instr_scale & ) image),
55 val_span( image.val_span),
56 half_width_units (image.half_width_units)
60 hud_card & hud_card ::
61 operator = (const hud_card & rhs )
63 if( !( this == &rhs)){
64 instr_scale::operator = (rhs);
65 val_span = rhs.val_span;
66 half_width_units = rhs.half_width_units;
72 draw( void ) // (HUD_scale * pscale )
83 POINT mid_scr = get_centroid();
84 double cur_value = get_value();
85 RECT scrn_rect = get_location();
86 UINT options = get_options();
88 vmin = cur_value - half_width_units; // width units == needle travel
89 vmax = cur_value + half_width_units; // or picture unit span.
90 // Draw the basic markings for the scale...
92 if( options & HUDS_VERT ) { // Vertical scale
93 drawOneLine( scrn_rect.left, // Bottom tick bar
95 scrn_rect.left + scrn_rect.right,
98 drawOneLine( scrn_rect.left, // Top tick bar
99 scrn_rect.top + scrn_rect.bottom,
100 scrn_rect.left + scrn_rect.right,
101 scrn_rect.top + scrn_rect.bottom );
103 marker_xs = scrn_rect.left;
104 marker_xe = scrn_rect.left + scrn_rect.right;
106 // We do not use else in the following so that combining the two
107 // options produces a "caged" display with double carrots. The
108 // same is done for horizontal card indicators.
110 if( options & HUDS_LEFT ) { // Calculate x marker offset
111 drawOneLine( scrn_rect.left + scrn_rect.right,
113 scrn_rect.left + scrn_rect.right,
114 scrn_rect.top + scrn_rect.bottom); // Cap right side
116 marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
118 drawOneLine( marker_xs, mid_scr.y,
119 marker_xe, mid_scr.y + scrn_rect.right / 6);
120 drawOneLine( marker_xs, mid_scr.y,
121 marker_xe, mid_scr.y - scrn_rect.right / 6);
124 if( options & HUDS_RIGHT ) { // We'll default this for now.
125 drawOneLine( scrn_rect.left,
128 scrn_rect.top + scrn_rect.bottom); // Cap left side
130 marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
132 drawOneLine( scrn_rect.left, mid_scr.y + scrn_rect.right / 6,
133 marker_xe, mid_scr.y );
134 drawOneLine( scrn_rect.left, mid_scr.y - scrn_rect.right / 6,
135 marker_xe, mid_scr.y);
138 // At this point marker x_start and x_end values are transposed.
139 // To keep this from confusing things they are now interchanged.
140 if(( options & HUDS_BOTH) == HUDS_BOTH) {
141 marker_ye = marker_xs;
142 marker_xs = marker_xe;
143 marker_xe = marker_ye;
146 // Work through from bottom to top of scale. Calculating where to put
147 // minor and major ticks.
149 for( i = (int)vmin; i <= (int)vmax; i++ ) {
157 if( condition ) { // Show a tick if necessary
158 // Calculate the location of this tick
159 marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
161 // Block calculation artifact from drawing ticks below min coordinate.
162 // Calculation here accounts for text height.
164 if(( marker_ys < (scrn_rect.top + 4)) |
165 ( marker_ys > (scrn_rect.top + scrn_rect.bottom - 4))) {
170 if( (i%div_min()) == 0) {
171 if((( marker_ys - 5) > scrn_rect.top ) &&
172 (( marker_ys + 5) < (scrn_rect.top + scrn_rect.bottom))){
173 if( (options & HUDS_BOTH) == HUDS_BOTH ) {
174 drawOneLine( scrn_rect.left, marker_ys,
175 marker_xs, marker_ys );
176 drawOneLine( marker_xe, marker_ys,
177 scrn_rect.left + scrn_rect.right, marker_ys );
180 if( options & HUDS_LEFT ) {
181 drawOneLine( marker_xs + 4, marker_ys,
182 marker_xe, marker_ys );
185 drawOneLine( marker_xs, marker_ys,
186 marker_xe - 4, marker_ys );
193 if( !(i%(int)div_max())){
196 disp_val += modulo();
199 disp_val = i % modulo();
205 sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
206 if(( (marker_ys - 8 ) > scrn_rect.top ) &&
207 ( (marker_ys + 8) < (scrn_rect.top + scrn_rect.bottom))){
208 if( (options & HUDS_BOTH) == HUDS_BOTH) {
209 drawOneLine( scrn_rect.left, marker_ys,
210 marker_xs, marker_ys);
211 drawOneLine( marker_xs, marker_ys,
212 scrn_rect.left + scrn_rect.right,
214 if( !(options & HUDS_NOTEXT)) {
215 textString ( marker_xs + 2, marker_ys,
216 TextScale, GLUT_BITMAP_8_BY_13 );
220 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
221 if( !(options & HUDS_NOTEXT)) {
222 if( options & HUDS_LEFT ) {
223 textString( marker_xs - 8 * strlen(TextScale) - 2,
225 TextScale, GLUT_BITMAP_8_BY_13 );
228 textString( marker_xe + 3 * strlen(TextScale),
230 TextScale, GLUT_BITMAP_8_BY_13 );
234 } // Else read oriented right
235 } // End if modulo division by major interval is zero
236 } // End if major interval divisor non-zero
237 } // End if condition
238 } // End for range of i from vmin to vmax
239 } // End if VERTICAL SCALE TYPE
240 else { // Horizontal scale by default
241 drawOneLine( scrn_rect.left, // left tick bar
244 scrn_rect.top + scrn_rect.bottom);
246 drawOneLine( scrn_rect.left + scrn_rect.right, // right tick bar
248 scrn_rect.left + scrn_rect.right,
249 scrn_rect.top + scrn_rect.bottom );
251 marker_ys = scrn_rect.top; // Starting point for
252 marker_ye = scrn_rect.top + scrn_rect.bottom; // tick y location calcs
254 if( options & HUDS_TOP ) {
255 drawOneLine( scrn_rect.left,
257 scrn_rect.left + scrn_rect.right,
258 scrn_rect.top); // Bottom box line
260 marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
262 drawOneLine( mid_scr.x, marker_ye,
263 mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
264 drawOneLine( mid_scr.x, marker_ye,
265 mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
267 if( options & HUDS_BOTTOM) {
268 drawOneLine( scrn_rect.left,
269 scrn_rect.top + scrn_rect.bottom,
270 scrn_rect.left + scrn_rect.right,
271 scrn_rect.top + scrn_rect.bottom); // Top box line
273 marker_ys = scrn_rect.top +
274 scrn_rect.bottom - scrn_rect.bottom / 2;
276 drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
277 scrn_rect.top + scrn_rect.bottom,
280 drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
281 scrn_rect.top + scrn_rect.bottom,
286 // if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
287 // marker_xe = marker_ys;
288 // marker_ys = marker_ye;
289 // marker_ye = marker_xe;
292 // printf("vmin = %d vmax = %d\n", (int)vmin, (int)vmax);
293 for( i = (int)vmin; i <= (int)vmax; i++ ) {
294 // printf("<*> i = %d\n", i);
301 // printf("<**> i = %d\n", i);
303 marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
305 if( (i%(int)div_min()) == 0 ) {
306 // draw in ticks only if they aren't too close to the edge.
307 if((( marker_xs - 5) > scrn_rect.left ) &&
308 (( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
310 if( (options & HUDS_BOTH) == HUDS_BOTH ) {
311 drawOneLine( marker_xs, scrn_rect.top,
312 marker_xs, marker_ys - 4);
313 drawOneLine( marker_xs, marker_ye + 4,
314 marker_xs, scrn_rect.top + scrn_rect.bottom);
317 if( options & HUDS_TOP) {
318 drawOneLine( marker_xs, marker_ys,
319 marker_xs, marker_ye - 4);
322 drawOneLine( marker_xs, marker_ys + 4,
323 marker_xs, marker_ye);
329 // printf("<***> i = %d\n", i);
331 // printf("i = %d\n", i);
332 if( (i%(int)div_max())==0 ) {
335 disp_val += modulo();
338 disp_val = i % modulo();
344 // printf("disp_val = %d\n", disp_val);
345 // printf("%d\n", (int)(disp_val * (double)data_scaling() + 0.5));
346 sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
347 // Draw major ticks and text only if far enough from the edge.
348 if(( (marker_xs - 10)> scrn_rect.left ) &&
349 ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
350 if( (options & HUDS_BOTH) == HUDS_BOTH) {
351 drawOneLine( marker_xs, scrn_rect.top,
352 marker_xs, marker_ys);
353 drawOneLine( marker_xs, marker_ye,
354 marker_xs, scrn_rect.top + scrn_rect.bottom);
356 if( !(options & HUDS_NOTEXT)) {
357 textString ( marker_xs - 4 * strlen(TextScale),
359 TextScale, GLUT_BITMAP_8_BY_13 );
363 drawOneLine( marker_xs, marker_ys,
364 marker_xs, marker_ye );
365 if( !(options & HUDS_NOTEXT)) {
366 if( options & HUDS_TOP ) {
367 textString ( marker_xs - 4 * strlen(TextScale),
368 scrn_rect.top + scrn_rect.bottom - 10,
369 TextScale, GLUT_BITMAP_8_BY_13 );
372 textString( marker_xs - 4 * strlen(TextScale),
374 TextScale, GLUT_BITMAP_8_BY_13 );
381 // printf("<****> i = %d\n", i);