10 #include <Aircraft/aircraft.hxx>
11 #include <Debug/fg_debug.h>
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 //========== Top of hud_card class member definitions =============
39 instr_scale( x,y,width,height,
42 max_value, min_value, disp_scaling,
43 major_divs, minor_divs, modulus,
45 val_span ( value_span)
47 half_width_units = range_to_show() / 2.0;
54 hud_card( const hud_card & image):
55 instr_scale( (const instr_scale & ) image),
56 val_span( image.val_span),
57 half_width_units (image.half_width_units)
61 hud_card & hud_card ::
62 operator = (const hud_card & rhs )
64 if( !( this == &rhs)){
65 instr_scale::operator = (rhs);
66 val_span = rhs.val_span;
67 half_width_units = rhs.half_width_units;
73 draw( void ) // (HUD_scale * pscale )
84 POINT mid_scr = get_centroid();
85 double cur_value = get_value();
86 RECT scrn_rect = get_location();
87 UINT options = get_options();
89 vmin = cur_value - half_width_units; // width units == needle travel
90 vmax = cur_value + half_width_units; // or picture unit span.
91 // Draw the basic markings for the scale...
93 if( options & HUDS_VERT ) { // Vertical scale
94 drawOneLine( scrn_rect.left, // Bottom tick bar
96 scrn_rect.left + scrn_rect.right,
99 drawOneLine( scrn_rect.left, // Top tick bar
100 scrn_rect.top + scrn_rect.bottom,
101 scrn_rect.left + scrn_rect.right,
102 scrn_rect.top + scrn_rect.bottom );
104 marker_xs = scrn_rect.left;
105 marker_xe = scrn_rect.left + scrn_rect.right;
107 // We do not use else in the following so that combining the two
108 // options produces a "caged" display with double carrots. The
109 // same is done for horizontal card indicators.
111 if( options & HUDS_LEFT ) { // Calculate x marker offset
112 drawOneLine( scrn_rect.left + scrn_rect.right,
114 scrn_rect.left + scrn_rect.right,
115 scrn_rect.top + scrn_rect.bottom); // Cap right side
117 marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
119 drawOneLine( marker_xs, mid_scr.y,
120 marker_xe, mid_scr.y + scrn_rect.right / 6);
121 drawOneLine( marker_xs, mid_scr.y,
122 marker_xe, mid_scr.y - scrn_rect.right / 6);
125 if( options & HUDS_RIGHT ) { // We'll default this for now.
126 drawOneLine( scrn_rect.left,
129 scrn_rect.top + scrn_rect.bottom); // Cap left side
131 marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
133 drawOneLine( scrn_rect.left, mid_scr.y + scrn_rect.right / 6,
134 marker_xe, mid_scr.y );
135 drawOneLine( scrn_rect.left, mid_scr.y - scrn_rect.right / 6,
136 marker_xe, mid_scr.y);
139 // At this point marker x_start and x_end values are transposed.
140 // To keep this from confusing things they are now interchanged.
141 if(( options & HUDS_BOTH) == HUDS_BOTH) {
142 marker_ye = marker_xs;
143 marker_xs = marker_xe;
144 marker_xe = marker_ye;
147 // Work through from bottom to top of scale. Calculating where to put
148 // minor and major ticks.
150 for( i = (int)vmin; i <= (int)vmax; i++ ) {
158 if( condition ) { // Show a tick if necessary
159 // Calculate the location of this tick
160 marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
162 // Block calculation artifact from drawing ticks below min coordinate.
163 // Calculation here accounts for text height.
165 if(( marker_ys < (scrn_rect.top + 4)) |
166 ( marker_ys > (scrn_rect.top + scrn_rect.bottom - 4))) {
171 if( (i%div_min()) == 0) {
172 if((( marker_ys - 5) > scrn_rect.top ) &&
173 (( marker_ys + 5) < (scrn_rect.top + scrn_rect.bottom))){
174 if( (options & HUDS_BOTH) == HUDS_BOTH ) {
175 drawOneLine( scrn_rect.left, marker_ys,
176 marker_xs, marker_ys );
177 drawOneLine( marker_xe, marker_ys,
178 scrn_rect.left + scrn_rect.right, marker_ys );
181 if( options & HUDS_LEFT ) {
182 drawOneLine( marker_xs + 4, marker_ys,
183 marker_xe, marker_ys );
186 drawOneLine( marker_xs, marker_ys,
187 marker_xe - 4, marker_ys );
194 if( !(i%(int)div_max())){
197 disp_val += modulo();
200 disp_val = i % modulo();
206 sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
207 if(( (marker_ys - 8 ) > scrn_rect.top ) &&
208 ( (marker_ys + 8) < (scrn_rect.top + scrn_rect.bottom))){
209 if( (options & HUDS_BOTH) == HUDS_BOTH) {
210 drawOneLine( scrn_rect.left, marker_ys,
211 marker_xs, marker_ys);
212 drawOneLine( marker_xs, marker_ys,
213 scrn_rect.left + scrn_rect.right,
215 if( !(options & HUDS_NOTEXT)) {
216 textString ( marker_xs + 2, marker_ys,
217 TextScale, GLUT_BITMAP_8_BY_13 );
221 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
222 if( !(options & HUDS_NOTEXT)) {
223 if( options & HUDS_LEFT ) {
224 textString( marker_xs - 8 * strlen(TextScale) - 2,
226 TextScale, GLUT_BITMAP_8_BY_13 );
229 textString( marker_xe + 3 * strlen(TextScale),
231 TextScale, GLUT_BITMAP_8_BY_13 );
235 } // Else read oriented right
236 } // End if modulo division by major interval is zero
237 } // End if major interval divisor non-zero
238 } // End if condition
239 } // End for range of i from vmin to vmax
240 } // End if VERTICAL SCALE TYPE
241 else { // Horizontal scale by default
242 drawOneLine( scrn_rect.left, // left tick bar
245 scrn_rect.top + scrn_rect.bottom);
247 drawOneLine( scrn_rect.left + scrn_rect.right, // right tick bar
249 scrn_rect.left + scrn_rect.right,
250 scrn_rect.top + scrn_rect.bottom );
252 marker_ys = scrn_rect.top; // Starting point for
253 marker_ye = scrn_rect.top + scrn_rect.bottom; // tick y location calcs
255 if( options & HUDS_TOP ) {
256 drawOneLine( scrn_rect.left,
258 scrn_rect.left + scrn_rect.right,
259 scrn_rect.top); // Bottom box line
261 marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
263 drawOneLine( mid_scr.x, marker_ye,
264 mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
265 drawOneLine( mid_scr.x, marker_ye,
266 mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
268 if( options & HUDS_BOTTOM) {
269 drawOneLine( scrn_rect.left,
270 scrn_rect.top + scrn_rect.bottom,
271 scrn_rect.left + scrn_rect.right,
272 scrn_rect.top + scrn_rect.bottom); // Top box line
274 marker_ys = scrn_rect.top +
275 scrn_rect.bottom - scrn_rect.bottom / 2;
277 drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
278 scrn_rect.top + scrn_rect.bottom,
281 drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
282 scrn_rect.top + scrn_rect.bottom,
287 // if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
288 // marker_xe = marker_ys;
289 // marker_ys = marker_ye;
290 // marker_ye = marker_xe;
293 // printf("vmin = %d vmax = %d\n", (int)vmin, (int)vmax);
294 for( i = (int)vmin; i <= (int)vmax; i++ ) {
295 // printf("<*> i = %d\n", i);
302 // printf("<**> i = %d\n", i);
304 marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
306 if( (i%(int)div_min()) == 0 ) {
307 // draw in ticks only if they aren't too close to the edge.
308 if((( marker_xs - 5) > scrn_rect.left ) &&
309 (( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
311 if( (options & HUDS_BOTH) == HUDS_BOTH ) {
312 drawOneLine( marker_xs, scrn_rect.top,
313 marker_xs, marker_ys - 4);
314 drawOneLine( marker_xs, marker_ye + 4,
315 marker_xs, scrn_rect.top + scrn_rect.bottom);
318 if( options & HUDS_TOP) {
319 drawOneLine( marker_xs, marker_ys,
320 marker_xs, marker_ye - 4);
323 drawOneLine( marker_xs, marker_ys + 4,
324 marker_xs, marker_ye);
330 // printf("<***> i = %d\n", i);
332 // printf("i = %d\n", i);
333 if( (i%(int)div_max())==0 ) {
336 disp_val += modulo();
339 disp_val = i % modulo();
345 // printf("disp_val = %d\n", disp_val);
346 // printf("%d\n", (int)(disp_val * (double)data_scaling() + 0.5));
347 sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
348 // Draw major ticks and text only if far enough from the edge.
349 if(( (marker_xs - 10)> scrn_rect.left ) &&
350 ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
351 if( (options & HUDS_BOTH) == HUDS_BOTH) {
352 drawOneLine( marker_xs, scrn_rect.top,
353 marker_xs, marker_ys);
354 drawOneLine( marker_xs, marker_ye,
355 marker_xs, scrn_rect.top + scrn_rect.bottom);
357 if( !(options & HUDS_NOTEXT)) {
358 textString ( marker_xs - 4 * strlen(TextScale),
360 TextScale, GLUT_BITMAP_8_BY_13 );
364 drawOneLine( marker_xs, marker_ys,
365 marker_xs, marker_ye );
366 if( !(options & HUDS_NOTEXT)) {
367 if( options & HUDS_TOP ) {
368 textString ( marker_xs - 4 * strlen(TextScale),
369 scrn_rect.top + scrn_rect.bottom - 10,
370 TextScale, GLUT_BITMAP_8_BY_13 );
373 textString( marker_xs - 4 * strlen(TextScale),
375 TextScale, GLUT_BITMAP_8_BY_13 );
382 // printf("<****> i = %d\n", i);