]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_card.cxx
894aaf3841e041444cd2d04366fc8949fed9ea3e
[flightgear.git] / src / Cockpit / hud_card.cxx
1
2 #include "hud.hxx"
3
4 #ifdef USE_HUD_TextList
5 #define textString( x , y, text, font )  TextString( text, x , y )
6 #else
7 #define textString( x , y, text, font )  puDrawString ( guiFnt, text, x, y );
8 #endif
9
10 //========== Top of hud_card class member definitions =============
11
12 hud_card ::
13 hud_card( int       x,
14           int       y,
15           UINT      width,
16           UINT      height,
17           FLTFNPTR  data_source,
18           UINT      options,
19           float    max_value, // 360
20           float    min_value, // 0
21           float    disp_scaling,
22           UINT      major_divs,
23           UINT      minor_divs,
24           UINT      modulus,  // 360
25           int       dp_showing,
26           float    value_span,
27           bool      working) :
28                 instr_scale( x,y,width,height,
29                              data_source, options,
30                              value_span,
31                              max_value, min_value, disp_scaling,
32                              major_divs, minor_divs, modulus,
33                              working),
34                 val_span   ( value_span)
35 {
36   half_width_units = range_to_show() / 2.0;
37 //  UINT options     = get_options();
38 //  huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
39 //  huds_right = options & HUDS_RIGHT;
40 //  huds_left = options & HUDS_LEFT;
41 //  huds_vert = options & HUDS_VERT;
42 //  huds_notext = options & HUDS_NOTEXT;
43 //  huds_top = options & HUDS_TOP;
44 //  huds_bottom = options & HUDS_BOTTOM;
45 }
46
47 hud_card ::
48 ~hud_card() { }
49
50 hud_card ::
51 hud_card( const hud_card & image):
52       instr_scale( (const instr_scale & ) image),
53       val_span( image.val_span),
54       half_width_units (image.half_width_units)
55 {
56 //  UINT options     = get_options();
57 //  huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
58 //  huds_right = options & HUDS_RIGHT;
59 //  huds_left = options & HUDS_LEFT;
60 //  huds_vert = options & HUDS_VERT;
61 //  huds_notext = options & HUDS_NOTEXT;
62 //  huds_top = options & HUDS_TOP;
63 //  huds_bottom = options & HUDS_BOTTOM;
64 }
65
66 hud_card & hud_card ::
67 operator = (const hud_card & rhs )
68 {
69   if( !( this == &rhs)){
70     instr_scale::operator = (rhs);
71     val_span = rhs.val_span;
72     half_width_units = rhs.half_width_units;
73     }
74   return *this;
75 }
76
77 void hud_card ::
78 draw( void ) //  (HUD_scale * pscale )
79 {
80   float vmin, vmax;
81   int marker_xs;
82   int marker_xe;
83   int marker_ys;
84   int marker_ye;
85   int lenstr;
86   int height, width;
87   int i, last;
88   char TextScale[80];
89   bool condition;
90   int disp_val = 0;
91   POINT mid_scr    = get_centroid();
92   float cur_value  = get_value();
93   RECT   scrn_rect = get_location();
94   UINT options     = get_options();
95
96   height = scrn_rect.top  + scrn_rect.bottom;
97   width = scrn_rect.left + scrn_rect.right;
98
99   vmin = cur_value - half_width_units; // width units == needle travel
100   vmax = cur_value + half_width_units; // or picture unit span.
101   
102   // Draw the basic markings for the scale...
103   
104   if( huds_vert(options) ) { // Vertical scale
105     drawOneLine( scrn_rect.left,     // Bottom tick bar
106                  scrn_rect.top,
107                  width,
108                  scrn_rect.top);
109
110     drawOneLine( scrn_rect.left,    // Top tick bar
111                  height,
112                  width,
113                  height );
114       
115       marker_xs = scrn_rect.left;  // x start
116       marker_xe = width;  // x extent
117       marker_ye = height;
118
119 //    glBegin(GL_LINES);
120       
121       // Bottom tick bar
122 //    glVertex2f( marker_xs, scrn_rect.top);
123 //    glVertex2f( marker_xe, scrn_rect.top);
124
125       // Top tick bar
126 //    glVertex2f( marker_xs, marker_ye);
127 //    glVertex2f( marker_xe, marker_ye );
128 //    glEnd();
129
130     // We do not use else in the following so that combining the two
131     // options produces a "caged" display with double carrots. The
132     // same is done for horizontal card indicators.
133
134       if( huds_left(options) ) {    // Calculate x marker offset
135           drawOneLine( marker_xe, scrn_rect.top,
136                        marker_xe, marker_ye); // Cap right side
137
138         marker_xs  = marker_xe - scrn_rect.right / 3;   // Adjust tick xs
139                                                       // Indicator carrot
140 //      drawOneLine( marker_xs, mid_scr.y,
141 //                   marker_xe, mid_scr.y + scrn_rect.right / 6);
142 //      drawOneLine( marker_xs, mid_scr.y,
143 //                   marker_xe, mid_scr.y - scrn_rect.right / 6);
144
145         glBegin(GL_LINE_STRIP);
146         glVertex2f( marker_xe, mid_scr.y + scrn_rect.right / 6);
147         glVertex2f( marker_xs, mid_scr.y);
148         glVertex2f( marker_xe, mid_scr.y - scrn_rect.right / 6);
149         glEnd();
150     }
151     if( huds_right(options) ) {  // We'll default this for now.
152         drawOneLine( scrn_rect.left, scrn_rect.top,
153                      scrn_rect.left, marker_ye );  // Cap left side
154
155         marker_xe = scrn_rect.left + scrn_rect.right / 3;     // Adjust tick xe
156                                                        // Indicator carrot
157 //      drawOneLine( scrn_rect.left, mid_scr.y +  scrn_rect.right / 6,
158 //                   marker_xe, mid_scr.y );
159 //      drawOneLine( scrn_rect.left, mid_scr.y -  scrn_rect.right / 6,
160 //                   marker_xe, mid_scr.y);
161         glBegin(GL_LINE_STRIP);
162         glVertex2f( scrn_rect.left, mid_scr.y +  scrn_rect.right / 6);
163         glVertex2f( marker_xe, mid_scr.y );
164         glVertex2f( scrn_rect.left, mid_scr.y -  scrn_rect.right / 6);
165         glEnd();
166     }
167
168     // At this point marker x_start and x_end values are transposed.
169     // To keep this from confusing things they are now interchanged.
170     if(huds_both(options)) {
171       marker_ye = marker_xs;
172       marker_xs = marker_xe;
173       marker_xe = marker_ye;
174       }
175
176     // Work through from bottom to top of scale. Calculating where to put
177     // minor and major ticks.
178
179 //  last = FloatToInt(vmax)+1;
180 //  i = FloatToInt(vmin);
181     last = (int)vmax + 1;
182     i = (int)vmin;
183     for( ; i <last ; i++ )
184     {
185       condition = true;
186       if( !modulo()) {
187         if( i < min_val()) {
188           condition = false;
189           }
190         }
191
192       if( condition ) {  // Show a tick if necessary
193                          // Calculate the location of this tick
194         marker_ys = scrn_rect.top + FloatToInt(((i - vmin) * factor()/*+.5f*/));
195 //        marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
196         // Block calculation artifact from drawing ticks below min coordinate.
197         // Calculation here accounts for text height.
198
199         if(( marker_ys < (scrn_rect.top + 4)) |
200            ( marker_ys > (height - 4))) {
201             // Magic numbers!!!
202           continue;
203           }
204         if( div_min()) {
205 //          if( (i%div_min()) == 0) {
206           if( !(i%(int)div_min())) {            
207             if((( marker_ys - 5) > scrn_rect.top ) &&
208                (( marker_ys + 5) < (height))){
209               if( huds_both(options) ) {
210                 drawOneLine( scrn_rect.left, marker_ys,
211                              marker_xs,      marker_ys );
212                 drawOneLine( marker_xe,      marker_ys,
213                              width,  marker_ys );
214 //                glBegin(GL_LINES);
215 //                glVertex2f( scrn_rect.left, marker_ys );
216 //                glVertex2f( marker_xs,      marker_ys );
217 //                glVertex2f( marker_xe,      marker_ys);
218 //                glVertex2f( scrn_rect.left + scrn_rect.right,  marker_ys );
219 //                glEnd();
220                   }
221               else {
222                 if( huds_left(options) ) {
223                   drawOneLine( marker_xs + 4, marker_ys,
224                                marker_xe,     marker_ys );
225                   }
226                 else {
227                   drawOneLine( marker_xs,     marker_ys,
228                                marker_xe - 4, marker_ys );
229                   }
230                 }
231               }
232             }
233           }
234         if( div_max() ) {
235           if( !(i%(int)div_max()) )         
236           {
237             if(modulo()) {
238                 if( disp_val < 0) {
239                     while(disp_val < 0)
240                         disp_val += modulo();
241 //              } else {
242 //                  disp_val = i % (int)modulo();
243                 }
244                 disp_val = i % (int) modulo(); // ?????????
245             } else {
246                 disp_val = i;
247             }
248
249             lenstr = sprintf( TextScale, "%d",
250                               FloatToInt(disp_val * data_scaling()/*+.5*/));
251 //                            (int)(disp_val  * data_scaling() +.5));
252             if(( (marker_ys - 8 ) > scrn_rect.top ) &&
253                ( (marker_ys + 8) < (height))){
254               if( huds_both(options) ) {
255 //                drawOneLine( scrn_rect.left, marker_ys,
256 //                             marker_xs,      marker_ys);
257 //                drawOneLine( marker_xs, marker_ys,
258 //                             scrn_rect.left + scrn_rect.right,
259 //                             marker_ys);
260                   glBegin(GL_LINE_STRIP);
261                   glVertex2f( scrn_rect.left, marker_ys );
262                   glVertex2f( marker_xs, marker_ys);
263                   glVertex2f( width, marker_ys);
264                   glEnd();
265                   if( !huds_notext(options)) {
266                       textString ( marker_xs + 2,  marker_ys,
267                                    TextScale,  GLUT_BITMAP_8_BY_13 );
268                   }
269               }
270               else {
271                 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
272                 if( !huds_notext(options) ) {
273                   if( huds_left(options) )              {
274                       textString( marker_xs -  8 * lenstr - 2,
275                                   marker_ys - 4,
276                                   TextScale, GLUT_BITMAP_8_BY_13 );
277                     }
278                   else  {
279                       textString( marker_xe + 3 * lenstr,
280                                   marker_ys - 4,
281                                   TextScale, GLUT_BITMAP_8_BY_13 );
282                   }
283                   }
284                 }
285               } // Else read oriented right
286             } // End if modulo division by major interval is zero
287           }  // End if major interval divisor non-zero
288         } // End if condition
289       } // End for range of i from vmin to vmax
290     }  // End if VERTICAL SCALE TYPE
291   else {                                // Horizontal scale by default
292       // left tick bar
293       drawOneLine( scrn_rect.left, scrn_rect.top,
294                    scrn_rect.left, height);
295
296       // right tick bar
297       drawOneLine( width, scrn_rect.top,
298                  width,
299                  height );
300       
301       marker_ys = scrn_rect.top;           // Starting point for
302       marker_ye = height;                  // tick y location calcs
303       marker_xe = width;
304
305 //    glBegin(GL_LINES);
306       // left tick bar
307 //    glVertex2f( scrn_rect.left, scrn_rect.top);
308 //    glVertex2f( scrn_rect.left, marker_ye);
309
310       // right tick bar
311 //    glVertex2f( marker_xe, scrn_rect.top);
312 //    glVertex2f( marker_xe, marker_ye );
313 //    glEnd();
314
315     if( huds_top(options) ) {
316         // Bottom box line
317         drawOneLine( scrn_rect.left,
318                      scrn_rect.top,
319                      width,
320                      scrn_rect.top);
321
322         // Tick point adjust
323         marker_ye  = scrn_rect.top + scrn_rect.bottom / 2;
324         
325         // Bottom arrow
326 //      drawOneLine( mid_scr.x, marker_ye,
327 //                   mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
328 //      drawOneLine( mid_scr.x, marker_ye,
329 //                   mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
330
331         glBegin(GL_LINE_STRIP);
332         glVertex2f( mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
333         glVertex2f( mid_scr.x, marker_ye);
334         glVertex2f( mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
335         glEnd();
336     }
337     if( huds_bottom(options) ) {
338         // Top box line
339         drawOneLine( scrn_rect.left, height,
340                      width, height);
341         // Tick point adjust
342         marker_ys = height - scrn_rect.bottom  / 2;
343         
344         // Top arrow
345 //      drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
346 //                   scrn_rect.top + scrn_rect.bottom,
347 //                   mid_scr.x, marker_ys );
348 //      drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
349 //                   scrn_rect.top + scrn_rect.bottom,
350 //                   mid_scr.x , marker_ys );
351         glBegin(GL_LINE_STRIP);
352         glVertex2f( mid_scr.x + scrn_rect.bottom / 4,
353                     height);
354         glVertex2f( mid_scr.x , marker_ys );
355         glVertex2f( mid_scr.x - scrn_rect.bottom / 4,
356                     height);
357         glEnd();
358     }
359
360 //    if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
361 //      marker_xe = marker_ys;
362 //      marker_ys = marker_ye;
363 //      marker_ye = marker_xe;
364 //      }
365
366     // printf("vmin = %d  vmax = %d\n", (int)vmin, (int)vmax);
367
368 //  last = FloatToInt(vmax)+1;
369 //  i    = FloatToInt(vmin);
370     last = (int)vmax + 1;
371     i = (int)vmin;
372     for(; i <last ; i++ )      {
373 //    for( i = (int)vmin; i <= (int)vmax; i++ )     {
374       // printf("<*> i = %d\n", i);
375       condition = true;
376       if( !modulo()) {
377         if( i < min_val()) {
378           condition = false;
379           }
380         }
381       // printf("<**> i = %d\n", i);
382       if( condition )        {
383 //        marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
384         marker_xs = scrn_rect.left + FloatToInt(((i - vmin) * factor()/*+ .5f*/));
385         if( div_min()){
386 //          if( (i%(int)div_min()) == 0 ) {
387           if( !(i%(int)div_min() )) {           
388             // draw in ticks only if they aren't too close to the edge.
389             if((( marker_xs - 5) > scrn_rect.left ) &&
390                (( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
391
392               if( huds_both(options) ) {
393                 drawOneLine( marker_xs, scrn_rect.top,
394                              marker_xs, marker_ys - 4);
395                 drawOneLine( marker_xs, marker_ye + 4,
396                              marker_xs, height);
397 //                glBegin(GL_LINES);
398 //                glVertex2f( marker_xs, scrn_rect.top);
399 //                glVertex2f( marker_xs, marker_ys - 4);
400 //                glVertex2f( marker_xs, marker_ye + 4);
401 //                glVertex2f( marker_xs, scrn_rect.top + scrn_rect.bottom);
402 //                glEnd();
403               }
404               else {
405                 if( huds_top(options)) {
406                   drawOneLine( marker_xs, marker_ys,
407                                marker_xs, marker_ye - 4);
408                   }
409                 else {
410                   drawOneLine( marker_xs, marker_ys + 4,
411                                marker_xs, marker_ye);
412                   }
413                 }
414               }
415             }
416           }
417     // printf("<***> i = %d\n", i);
418         if( div_max()) {
419       // printf("i = %d\n", i);
420 //          if( (i%(int)div_max())==0 ) {
421           if( !(i%(int)div_max()) ) {           
422             if(modulo()) {
423               if( disp_val < 0) {
424                   while(disp_val<0)
425                       disp_val += modulo();
426               }
427               disp_val = i % (int) modulo(); // ?????????
428             } else {
429               disp_val = i;
430             }
431         // printf("disp_val = %d\n", disp_val);
432         // printf("%d\n", (int)(disp_val  * (double)data_scaling() + 0.5));
433             lenstr = sprintf( TextScale, "%d",
434 //                            (int)(disp_val  * data_scaling() +.5));
435                               FloatToInt(disp_val * data_scaling()/*+.5*/));
436             // Draw major ticks and text only if far enough from the edge.
437             if(( (marker_xs - 10)> scrn_rect.left ) &&
438                ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
439               if( huds_both(options) ) {
440 //                drawOneLine( marker_xs, scrn_rect.top,
441 //                             marker_xs, marker_ys);
442 //                drawOneLine( marker_xs, marker_ye,
443 //                             marker_xs, scrn_rect.top + scrn_rect.bottom);
444                   glBegin(GL_LINE_STRIP);
445                   glVertex2f( marker_xs, scrn_rect.top);
446                   glVertex2f( marker_xs, marker_ye);
447                   glVertex2f( marker_xs, height);
448                   glEnd();
449                 if( !huds_notext(options) ) {
450                   textString ( marker_xs - 4 * lenstr,
451                                marker_ys + 4,
452                                TextScale,  GLUT_BITMAP_8_BY_13 );
453                   }
454                 }
455               else {
456                 drawOneLine( marker_xs, marker_ys,
457                              marker_xs, marker_ye );
458                 if( !huds_notext(options)) {
459                   if( huds_top(options) )              {
460                     textString ( marker_xs - 4 * lenstr,
461                                  height - 10,
462                                  TextScale, GLUT_BITMAP_8_BY_13 );
463                     }
464                   else  {
465                     textString( marker_xs - 4 * lenstr,
466                                 scrn_rect.top,
467                                 TextScale, GLUT_BITMAP_8_BY_13 );
468                     }
469                   }
470                 }
471               }
472             }
473       }
474     // printf("<****> i = %d\n", i);
475         }
476       }
477     }
478 }
479