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 guage_instr class member definitions ==============
37 instr_scale( x, y, width, height,
39 (maxValue - minValue), // Always shows span?
42 major_divs, minor_divs,
54 guage_instr( const guage_instr & image):
55 instr_scale( (instr_scale &) image)
59 guage_instr & guage_instr ::
60 operator = (const guage_instr & rhs )
62 if( !(this == &rhs)) {
63 instr_scale::operator = (rhs);
68 // As implemented, draw only correctly draws a horizontal or vertical
69 // scale. It should contain a variation that permits clock type displays.
70 // Now is supports "tickless" displays such as control surface indicators.
71 // This routine should be worked over before using. Current value would be
72 // fetched and not used if not commented out. Clearly that is intollerable.
74 void guage_instr :: draw (void)
76 int marker_xs, marker_xe;
77 int marker_ys, marker_ye;
83 double vmin = min_val();
84 double vmax = max_val();
85 POINT mid_scr = get_centroid();
86 double cur_value = get_value();
87 RECT scrn_rect = get_location();
88 UINT options = get_options();
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 if( options & HUDS_LEFT ) { // Read left, so line down right side
107 drawOneLine( scrn_rect.left + scrn_rect.right,
109 scrn_rect.left + scrn_rect.right,
110 scrn_rect.top + scrn_rect.bottom);
112 marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
114 if( options & HUDS_RIGHT ) { // Read right, so down left sides
115 drawOneLine( scrn_rect.left,
118 scrn_rect.top + scrn_rect.bottom);
119 marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
122 // At this point marker x_start and x_end values are transposed.
123 // To keep this from confusing things they are now interchanged.
124 if(( options & HUDS_BOTH) == HUDS_BOTH) {
125 marker_ye = marker_xs;
126 marker_xs = marker_xe;
127 marker_xe = marker_ye;
130 // Work through from bottom to top of scale. Calculating where to put
131 // minor and major ticks.
133 if( !(options & HUDS_NOTICKS )) { // If not no ticks...:)
134 // Calculate x marker offsets
135 for( i = (int)vmin; i <= (int)vmax; i++ ) {
137 // Calculate the location of this tick
138 marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
140 // We compute marker_ys even though we don't know if we will use
141 // either major or minor divisions. Simpler.
143 if( div_min()) { // Minor tick marks
144 if( (i%div_min()) == 0) {
145 if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
146 drawOneLine( scrn_rect.left, marker_ys,
147 marker_xs - 3, marker_ys );
148 drawOneLine( marker_xe + 3, marker_ys,
149 scrn_rect.left + scrn_rect.right, marker_ys );
152 if( options & HUDS_LEFT) {
153 drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
156 drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
162 // Now we work on the major divisions. Since these are also labeled
163 // and no labels are drawn otherwise, we label inside this if
166 if( div_max()) { // Major tick mark
167 if( (i%div_max()) == 0 ) {
168 if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
170 drawOneLine( scrn_rect.left, marker_ys,
171 marker_xs, marker_ys );
172 drawOneLine( marker_xe, marker_ys,
173 scrn_rect.left + scrn_rect.right, marker_ys );
176 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
179 if( !(options & HUDS_NOTEXT)) {
181 sprintf( TextScale, "%d",disp_val * (int)(data_scaling() +.5));
183 if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
184 text_x = mid_scr.x - 2 - ((3 * strlen( TextScale ))>>1);
187 if( options & HUDS_LEFT ) {
188 text_x = marker_xs - 2 - 3 * strlen( TextScale);
191 text_x = marker_xe + 10 - strlen( TextScale );
194 // Now we know where to put the text.
196 textString( text_x, text_y, TextScale, GLUT_BITMAP_8_BY_13 );
202 // Now that the scale is drawn, we draw in the pointer(s). Since labels
203 // have been drawn, text_x and text_y may be recycled. This is used
204 // with the marker start stops to produce a pointer for each side reading
206 text_y = scrn_rect.top + (int)((cur_value - vmin) * factor() + .5);
207 // text_x = marker_xs - scrn_rect.left;
209 if( options & HUDS_RIGHT ) {
210 drawOneLine(scrn_rect.left, text_y + 5,
212 drawOneLine(scrn_rect.left, text_y - 5,
215 if( options & HUDS_LEFT ) {
216 drawOneLine(scrn_rect.left + scrn_rect.right, text_y + 5,
218 drawOneLine(scrn_rect.left + scrn_rect.right, text_y - 5,
221 } // End if VERTICAL SCALE TYPE
222 else { // Horizontal scale by default
223 drawOneLine( scrn_rect.left, // left tick bar
226 scrn_rect.top + scrn_rect.bottom);
228 drawOneLine( scrn_rect.left + scrn_rect.right, // right tick bar
230 scrn_rect.left + scrn_rect.right,
231 scrn_rect.top + scrn_rect.bottom );
233 marker_ys = scrn_rect.top; // Starting point for
234 marker_ye = scrn_rect.top + scrn_rect.bottom; // tick y location calcs
235 marker_xs = scrn_rect.left + (int)((cur_value - vmin) * factor() + .5);
237 if( options & HUDS_TOP ) {
238 drawOneLine( scrn_rect.left,
240 scrn_rect.left + scrn_rect.right,
241 scrn_rect.top); // Bottom box line
243 marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
245 drawOneLine( marker_xs, marker_ye,
246 marker_xs - scrn_rect.bottom / 4, scrn_rect.top);
247 drawOneLine( marker_xs, marker_ye,
248 marker_xs + scrn_rect.bottom / 4, scrn_rect.top);
250 if( options & HUDS_BOTTOM) {
251 drawOneLine( scrn_rect.left,
252 scrn_rect.top + scrn_rect.bottom,
253 scrn_rect.left + scrn_rect.right,
254 scrn_rect.top + scrn_rect.bottom); // Top box line
256 marker_ys = scrn_rect.top +
257 scrn_rect.bottom - scrn_rect.bottom / 2;
259 drawOneLine( marker_xs + scrn_rect.bottom / 4,
260 scrn_rect.top + scrn_rect.bottom,
263 drawOneLine( marker_xs - scrn_rect.bottom / 4,
264 scrn_rect.top + scrn_rect.bottom,
269 for( i = (int)vmin; i <= (int)vmax; i++ ) {
277 marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
279 if( (i%(int)div_min()) == 0 ) {
280 // draw in ticks only if they aren't too close to the edge.
281 if((( marker_xs + 5) > scrn_rect.left ) ||
282 (( marker_xs - 5 )< (scrn_rect.left + scrn_rect.right))){
284 if( (options & HUDS_BOTH) == HUDS_BOTH ) {
285 drawOneLine( marker_xs, scrn_rect.top,
286 marker_xs, marker_ys - 4);
287 drawOneLine( marker_xs, marker_ye + 4,
288 marker_xs, scrn_rect.top + scrn_rect.bottom);
291 if( options & HUDS_TOP) {
292 drawOneLine( marker_xs, marker_ys,
293 marker_xs, marker_ye - 4);
296 drawOneLine( marker_xs, marker_ys + 4,
297 marker_xs, marker_ye);
304 if( (i%(int)div_max())==0 ) {
307 disp_val += modulo();
310 disp_val = i % modulo();
316 sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
317 // Draw major ticks and text only if far enough from the edge.
318 if(( (marker_xs - 10)> scrn_rect.left ) &&
319 ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
320 if( (options & HUDS_BOTH) == HUDS_BOTH) {
321 drawOneLine( marker_xs, scrn_rect.top,
322 marker_xs, marker_ys);
323 drawOneLine( marker_xs, marker_ye,
324 marker_xs, scrn_rect.top + scrn_rect.bottom);
326 if( !(options & HUDS_NOTEXT)) {
327 textString ( marker_xs - 4 * strlen(TextScale),
329 TextScale, GLUT_BITMAP_8_BY_13 );
333 drawOneLine( marker_xs, marker_ys,
334 marker_xs, marker_ye );
335 if( !(options & HUDS_NOTEXT)) {
336 if( options & HUDS_TOP ) {
337 textString ( marker_xs - 4 * strlen(TextScale),
338 scrn_rect.top + scrn_rect.bottom - 10,
339 TextScale, GLUT_BITMAP_8_BY_13 );
342 textString( marker_xs - 4 * strlen(TextScale),
344 TextScale, GLUT_BITMAP_8_BY_13 );