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 guage_instr class member definitions ==============
44 instr_scale( x, y, width, height,
46 (maxValue - minValue), // Always shows span?
49 major_divs, minor_divs,
53 // UINT options = get_options();
54 // huds_vert = options & HUDS_VERT;
55 // huds_left = options & HUDS_LEFT;
56 // huds_right = options & HUDS_RIGHT;
57 // huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
58 // huds_noticks = options & HUDS_NOTICKS;
59 // huds_notext = options & HUDS_NOTEXT;
60 // huds_top = options & HUDS_TOP;
61 // huds_bottom = options & HUDS_BOTTOM;
70 guage_instr( const guage_instr & image):
71 instr_scale( (instr_scale &) image)
73 // UINT options = get_options();
74 // huds_vert = options & HUDS_VERT;
75 // huds_left = options & HUDS_LEFT;
76 // huds_right = options & HUDS_RIGHT;
77 // huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
78 // huds_noticks = options & HUDS_NOTICKS;
79 // huds_notext = options & HUDS_NOTEXT;
80 // huds_top = options & HUDS_TOP;
81 // huds_bottom = options & HUDS_BOTTOM;
84 guage_instr & guage_instr ::
85 operator = (const guage_instr & rhs )
87 if( !(this == &rhs)) {
88 instr_scale::operator = (rhs);
93 // As implemented, draw only correctly draws a horizontal or vertical
94 // scale. It should contain a variation that permits clock type displays.
95 // Now is supports "tickless" displays such as control surface indicators.
96 // This routine should be worked over before using. Current value would be
97 // fetched and not used if not commented out. Clearly that is intollerable.
99 void guage_instr :: draw (void)
101 int marker_xs, marker_xe;
102 int marker_ys, marker_ye;
104 int width, height, bottom_4;
110 float vmin = min_val();
111 float vmax = max_val();
112 POINT mid_scr = get_centroid();
113 float cur_value = get_value();
114 RECT scrn_rect = get_location();
115 UINT options = get_options();
117 width = scrn_rect.left + scrn_rect.right;
118 height = scrn_rect.top + scrn_rect.bottom,
119 bottom_4 = scrn_rect.bottom / 4;
120 // Draw the basic markings for the scale...
122 if( huds_vert(options) ) { // Vertical scale
123 drawOneLine( scrn_rect.left, // Bottom tick bar
128 drawOneLine( scrn_rect.left, // Top tick bar
133 marker_xs = scrn_rect.left;
136 if( huds_left(options) ) { // Read left, so line down right side
142 marker_xs = marker_xe - scrn_rect.right / 3; // Adjust tick xs
145 if( huds_right(options) ) { // Read right, so down left sides
146 drawOneLine( scrn_rect.left,
151 marker_xe = scrn_rect.left + scrn_rect.right / 3; // Adjust tick xe
154 // At this point marker x_start and x_end values are transposed.
155 // To keep this from confusing things they are now interchanged.
156 if( huds_both(options) ) {
157 marker_ye = marker_xs;
158 marker_xs = marker_xe;
159 marker_xe = marker_ye;
162 // Work through from bottom to top of scale. Calculating where to put
163 // minor and major ticks.
165 if( !huds_noticks(options)) { // If not no ticks...:)
166 // Calculate x marker offsets
167 int last = (int)vmax + 1; //FloatToInt(vmax)+1;
168 i = (int)vmin; //FloatToInt(vmin);
169 for(; i <last ; i++ ) {
170 // for( i = (int)vmin; i <= (int)vmax; i++ ) {
172 // Calculate the location of this tick
173 marker_ys = scrn_rect.top + FloatToInt((i - vmin) * factor()/* +.5f*/);
175 // We compute marker_ys even though we don't know if we will use
176 // either major or minor divisions. Simpler.
178 if( div_min()) { // Minor tick marks
179 if( !(i%(int)div_min()) ) {
180 if( huds_left(options) && huds_right(options) ) {
181 drawOneLine( scrn_rect.left, marker_ys,
182 marker_xs - 3, marker_ys );
183 drawOneLine( marker_xe + 3, marker_ys,
187 if( huds_left(options) ) {
188 drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
191 drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
197 // Now we work on the major divisions. Since these are also labeled
198 // and no labels are drawn otherwise, we label inside this if
201 if( div_max()) { // Major tick mark
202 if( !(i%(int)div_max()) ) {
203 if( huds_left(options) && huds_right(options) ) {
204 drawOneLine( scrn_rect.left, marker_ys,
205 marker_xs, marker_ys );
206 drawOneLine( marker_xe, marker_ys,
210 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
213 if( !huds_notext(options) ) {
215 sprintf( TextScale, "%d",
216 FloatToInt(disp_val * data_scaling()/*+.5*/ ));
218 lenstr = getStringWidth( TextScale );
220 if( huds_left(options) && huds_right(options) ) {
221 text_x = mid_scr.x - lenstr/2 ;
224 if( huds_left(options) ) {
225 text_x = marker_xs - lenstr;
228 text_x = marker_xe - lenstr;
231 // Now we know where to put the text.
233 textString( text_x, text_y, TextScale, GLUT_BITMAP_8_BY_13 );
239 // Now that the scale is drawn, we draw in the pointer(s). Since labels
240 // have been drawn, text_x and text_y may be recycled. This is used
241 // with the marker start stops to produce a pointer for each side reading
243 text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
244 // text_x = marker_xs - scrn_rect.left;
246 if( huds_right(options) ) {
247 glBegin(GL_LINE_STRIP);
248 glVertex2f( scrn_rect.left, text_y + 5);
249 glVertex2f( marker_xe, text_y);
250 glVertex2f( scrn_rect.left, text_y - 5);
253 if( huds_left(options) ) {
254 glBegin(GL_LINE_STRIP);
255 glVertex2f( width, text_y + 5);
256 glVertex2f( marker_xs, text_y);
257 glVertex2f( width, text_y - 5);
260 } // End if VERTICAL SCALE TYPE
261 else { // Horizontal scale by default
262 drawOneLine( scrn_rect.left, // left tick bar
267 drawOneLine( width, // right tick bar
272 marker_ys = scrn_rect.top; // Starting point for
273 marker_ye = height; // tick y location calcs
274 marker_xs = scrn_rect.left + FloatToInt((cur_value - vmin) * factor() /*+ .5f*/);
276 if( huds_top(options) ) {
277 drawOneLine( scrn_rect.left,
280 scrn_rect.top); // Bottom box line
282 marker_ye = scrn_rect.top + scrn_rect.bottom / 2; // Tick point adjust
284 glBegin(GL_LINE_STRIP);
285 glVertex2f( marker_xs - bottom_4, scrn_rect.top);
286 glVertex2f( marker_xs, marker_ye);
287 glVertex2f( marker_xs + bottom_4, scrn_rect.top);
290 if( huds_bottom(options) ) {
292 drawOneLine( scrn_rect.left, height, width, height);
294 marker_ys = height - scrn_rect.bottom / 2;
297 glBegin(GL_LINE_STRIP);
298 glVertex2f( marker_xs + bottom_4, height);
299 glVertex2f( marker_xs, marker_ys );
300 glVertex2f( marker_xs - bottom_4, height);
305 int last = (int)vmax + 1; //FloatToInt(vmax)+1;
306 i = (int)vmin; //FloatToInt(vmin);
307 for( ; i <last ; i++ ) {
315 marker_xs = scrn_rect.left + FloatToInt((i - vmin) * factor()/* +.5f*/);
316 // marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
318 if( !(i%(int)div_min()) ) {
319 // draw in ticks only if they aren't too close to the edge.
320 if((( marker_xs + 5) > scrn_rect.left ) ||
321 (( marker_xs - 5 )< (width))){
323 if( huds_both(options) ) {
324 drawOneLine( marker_xs, scrn_rect.top,
325 marker_xs, marker_ys - 4);
326 drawOneLine( marker_xs, marker_ye + 4,
330 if( huds_top(options) ) {
331 drawOneLine( marker_xs, marker_ys,
332 marker_xs, marker_ye - 4);
335 drawOneLine( marker_xs, marker_ys + 4,
336 marker_xs, marker_ye);
343 if( !(i%(int)div_max()) ) {
346 while( disp_val < 0 ) {
347 disp_val += modulo();
350 disp_val = i % (int)modulo();
354 sprintf( TextScale, "%d",
355 FloatToInt(disp_val * data_scaling()/* +.5*/ ));
356 lenstr = getStringWidth( TextScale);
358 // Draw major ticks and text only if far enough from the edge.
359 if(( (marker_xs - 10)> scrn_rect.left ) &&
360 ( (marker_xs + 10) < width )){
361 if( huds_both(options) ) {
362 drawOneLine( marker_xs, scrn_rect.top,
363 marker_xs, marker_ys);
364 drawOneLine( marker_xs, marker_ye,
367 if( !huds_notext(options) ) {
368 textString ( marker_xs - lenstr, marker_ys + 4,
369 TextScale, GLUT_BITMAP_8_BY_13 );
373 drawOneLine( marker_xs, marker_ys,
374 marker_xs, marker_ye );
376 if( !huds_notext(options) ) {
377 if( huds_top(options) ) {
378 textString ( marker_xs - lenstr,
380 TextScale, GLUT_BITMAP_8_BY_13 );
383 textString( marker_xs - lenstr, scrn_rect.top,
384 TextScale, GLUT_BITMAP_8_BY_13 );