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>
18 #include <Weather/weather.h>
22 //============== Top of guage_instr class member definitions ==============
39 instr_scale( x, y, width, height,
41 (maxValue - minValue), // Always shows span?
44 major_divs, minor_divs,
56 guage_instr( const guage_instr & image):
57 instr_scale( (instr_scale &) image)
61 guage_instr & guage_instr ::
62 operator = (const guage_instr & rhs )
64 if( !(this == &rhs)) {
65 instr_scale::operator = (rhs);
70 // As implemented, draw only correctly draws a horizontal or vertical
71 // scale. It should contain a variation that permits clock type displays.
72 // Now is supports "tickless" displays such as control surface indicators.
73 // This routine should be worked over before using. Current value would be
74 // fetched and not used if not commented out. Clearly that is intollerable.
76 void guage_instr :: draw (void)
78 int marker_xs, marker_xe;
79 int marker_ys, marker_ye;
85 double vmin = min_val();
86 double vmax = max_val();
87 POINT mid_scr = get_centroid();
88 double cur_value = get_value();
89 RECT scrn_rect = get_location();
90 UINT options = get_options();
92 // Draw the basic markings for the scale...
94 if( options & HUDS_VERT ) { // Vertical scale
95 drawOneLine( scrn_rect.left, // Bottom tick bar
97 scrn_rect.left + scrn_rect.right,
100 drawOneLine( scrn_rect.left, // Top tick bar
101 scrn_rect.top + scrn_rect.bottom,
102 scrn_rect.left + scrn_rect.right,
103 scrn_rect.top + scrn_rect.bottom );
105 marker_xs = scrn_rect.left;
106 marker_xe = scrn_rect.left + scrn_rect.right;
108 if( options & HUDS_LEFT ) { // Read left, so line down right side
109 drawOneLine( scrn_rect.left + scrn_rect.right,
111 scrn_rect.left + scrn_rect.right,
112 scrn_rect.top + scrn_rect.bottom);
114 marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
116 if( options & HUDS_RIGHT ) { // Read right, so down left sides
117 drawOneLine( scrn_rect.left,
120 scrn_rect.top + scrn_rect.bottom);
121 marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
124 // At this point marker x_start and x_end values are transposed.
125 // To keep this from confusing things they are now interchanged.
126 if(( options & HUDS_BOTH) == HUDS_BOTH) {
127 marker_ye = marker_xs;
128 marker_xs = marker_xe;
129 marker_xe = marker_ye;
132 // Work through from bottom to top of scale. Calculating where to put
133 // minor and major ticks.
135 if( !(options & HUDS_NOTICKS )) { // If not no ticks...:)
136 // Calculate x marker offsets
137 for( i = (int)vmin; i <= (int)vmax; i++ ) {
139 // Calculate the location of this tick
140 marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
142 // We compute marker_ys even though we don't know if we will use
143 // either major or minor divisions. Simpler.
145 if( div_min()) { // Minor tick marks
146 if( (i%div_min()) == 0) {
147 if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
148 drawOneLine( scrn_rect.left, marker_ys,
149 marker_xs - 3, marker_ys );
150 drawOneLine( marker_xe + 3, marker_ys,
151 scrn_rect.left + scrn_rect.right, marker_ys );
154 if( options & HUDS_LEFT) {
155 drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
158 drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
164 // Now we work on the major divisions. Since these are also labeled
165 // and no labels are drawn otherwise, we label inside this if
168 if( div_max()) { // Major tick mark
169 if( (i%div_max()) == 0 ) {
170 if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
172 drawOneLine( scrn_rect.left, marker_ys,
173 marker_xs, marker_ys );
174 drawOneLine( marker_xe, marker_ys,
175 scrn_rect.left + scrn_rect.right, marker_ys );
178 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
181 if( !(options & HUDS_NOTEXT)) {
183 sprintf( TextScale, "%d",disp_val * (int)(data_scaling() +.5));
185 if((options & HUDS_LEFT) && (options && HUDS_RIGHT)) {
186 text_x = mid_scr.x - 2 - ((3 * strlen( TextScale ))>>1);
189 if( options & HUDS_LEFT ) {
190 text_x = marker_xs - 2 - 3 * strlen( TextScale);
193 text_x = marker_xe + 10 - strlen( TextScale );
196 // Now we know where to put the text.
198 textString( text_x, text_y, TextScale, GLUT_BITMAP_8_BY_13 );
204 // Now that the scale is drawn, we draw in the pointer(s). Since labels
205 // have been drawn, text_x and text_y may be recycled. This is used
206 // with the marker start stops to produce a pointer for each side reading
208 text_y = scrn_rect.top + (int)((cur_value - vmin) * factor() + .5);
209 // text_x = marker_xs - scrn_rect.left;
211 if( options & HUDS_RIGHT ) {
212 drawOneLine(scrn_rect.left, text_y + 5,
214 drawOneLine(scrn_rect.left, text_y - 5,
217 if( options & HUDS_LEFT ) {
218 drawOneLine(scrn_rect.left + scrn_rect.right, text_y + 5,
220 drawOneLine(scrn_rect.left + scrn_rect.right, text_y - 5,
223 } // End if VERTICAL SCALE TYPE
224 else { // Horizontal scale by default
225 drawOneLine( scrn_rect.left, // left tick bar
228 scrn_rect.top + scrn_rect.bottom);
230 drawOneLine( scrn_rect.left + scrn_rect.right, // right tick bar
232 scrn_rect.left + scrn_rect.right,
233 scrn_rect.top + scrn_rect.bottom );
235 marker_ys = scrn_rect.top; // Starting point for
236 marker_ye = scrn_rect.top + scrn_rect.bottom; // tick y location calcs
237 marker_xs = scrn_rect.left + (int)((cur_value - vmin) * factor() + .5);
239 if( options & HUDS_TOP ) {
240 drawOneLine( scrn_rect.left,
242 scrn_rect.left + scrn_rect.right,
243 scrn_rect.top); // Bottom box line
245 marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
247 drawOneLine( marker_xs, marker_ye,
248 marker_xs - scrn_rect.bottom / 4, scrn_rect.top);
249 drawOneLine( marker_xs, marker_ye,
250 marker_xs + scrn_rect.bottom / 4, scrn_rect.top);
252 if( options & HUDS_BOTTOM) {
253 drawOneLine( scrn_rect.left,
254 scrn_rect.top + scrn_rect.bottom,
255 scrn_rect.left + scrn_rect.right,
256 scrn_rect.top + scrn_rect.bottom); // Top box line
258 marker_ys = scrn_rect.top +
259 scrn_rect.bottom - scrn_rect.bottom / 2;
261 drawOneLine( marker_xs + scrn_rect.bottom / 4,
262 scrn_rect.top + scrn_rect.bottom,
265 drawOneLine( marker_xs - scrn_rect.bottom / 4,
266 scrn_rect.top + scrn_rect.bottom,
271 for( i = (int)vmin; i <= (int)vmax; i++ ) {
279 marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
281 if( (i%(int)div_min()) == 0 ) {
282 // draw in ticks only if they aren't too close to the edge.
283 if((( marker_xs + 5) > scrn_rect.left ) ||
284 (( marker_xs - 5 )< (scrn_rect.left + scrn_rect.right))){
286 if( (options & HUDS_BOTH) == HUDS_BOTH ) {
287 drawOneLine( marker_xs, scrn_rect.top,
288 marker_xs, marker_ys - 4);
289 drawOneLine( marker_xs, marker_ye + 4,
290 marker_xs, scrn_rect.top + scrn_rect.bottom);
293 if( options & HUDS_TOP) {
294 drawOneLine( marker_xs, marker_ys,
295 marker_xs, marker_ye - 4);
298 drawOneLine( marker_xs, marker_ys + 4,
299 marker_xs, marker_ye);
306 if( (i%(int)div_max())==0 ) {
309 disp_val += modulo();
312 disp_val = i % modulo();
318 sprintf( TextScale, "%d", (int)(disp_val * data_scaling() +.5));
319 // Draw major ticks and text only if far enough from the edge.
320 if(( (marker_xs - 10)> scrn_rect.left ) &&
321 ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
322 if( (options & HUDS_BOTH) == HUDS_BOTH) {
323 drawOneLine( marker_xs, scrn_rect.top,
324 marker_xs, marker_ys);
325 drawOneLine( marker_xs, marker_ye,
326 marker_xs, scrn_rect.top + scrn_rect.bottom);
328 if( !(options & HUDS_NOTEXT)) {
329 textString ( marker_xs - 4 * strlen(TextScale),
331 TextScale, GLUT_BITMAP_8_BY_13 );
335 drawOneLine( marker_xs, marker_ys,
336 marker_xs, marker_ye );
337 if( !(options & HUDS_NOTEXT)) {
338 if( options & HUDS_TOP ) {
339 textString ( marker_xs - 4 * strlen(TextScale),
340 scrn_rect.top + scrn_rect.bottom - 10,
341 TextScale, GLUT_BITMAP_8_BY_13 );
344 textString( marker_xs - 4 * strlen(TextScale),
346 TextScale, GLUT_BITMAP_8_BY_13 );