]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_card.cxx
Fixed gauge spelling error.
[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           string    card_type,
28           bool      tick_bottom,
29           bool      tick_top,
30           bool      tick_right,
31           bool      tick_left,
32           bool      cap_bottom,
33           bool      cap_top,
34           bool      cap_right,
35           bool      cap_left,
36           float     mark_offset,
37           bool      pointer_enable,
38           string    type_pointer,
39           bool      working) :
40                 instr_scale( x,y,width,height,
41                              data_source, options,
42                              value_span,
43                              max_value, min_value, disp_scaling,
44                              major_divs, minor_divs, modulus,
45                              working),
46                 val_span                 ( value_span),
47                 type             ( card_type),
48                                 draw_tick_bottom (tick_bottom),
49                                 draw_tick_top    (tick_top),
50                                 draw_tick_right  (tick_right),
51                                 draw_tick_left   (tick_left),
52                                 draw_cap_bottom  (cap_bottom),
53                                 draw_cap_top     (cap_top),
54                                 draw_cap_right   (cap_right),
55                                 draw_cap_left    (cap_left),
56                                 marker_offset    (mark_offset),
57                                 pointer          (pointer_enable),
58                                 pointer_type     (type_pointer)
59
60 {
61   half_width_units = range_to_show() / 2.0;
62 //  UINT options     = get_options();
63 //  huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
64 //  huds_right = options & HUDS_RIGHT;
65 //  huds_left = options & HUDS_LEFT;
66 //  huds_vert = options & HUDS_VERT;
67 //  huds_notext = options & HUDS_NOTEXT;
68 //  huds_top = options & HUDS_TOP;
69 //  huds_bottom = options & HUDS_BOTTOM;
70 }
71
72 hud_card ::
73 ~hud_card() { }
74
75 hud_card ::
76 hud_card( const hud_card & image):
77     instr_scale( (const instr_scale & ) image),
78     val_span( image.val_span),
79     type(image.type),
80     half_width_units (image.half_width_units),
81     draw_tick_bottom (image.draw_tick_bottom),
82     draw_tick_top (image.draw_tick_top),
83     draw_tick_right (image.draw_tick_right),
84     draw_tick_left (image.draw_tick_left),
85     draw_cap_bottom (image.draw_cap_bottom),
86     draw_cap_top (image.draw_cap_top),
87     draw_cap_right (image.draw_cap_right),
88     draw_cap_left (image.draw_cap_left),
89     marker_offset (image.marker_offset),
90     pointer (image.pointer),
91     pointer_type (image.pointer_type)
92
93 {
94 //  UINT options     = get_options();
95 //  huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
96 //  huds_right = options & HUDS_RIGHT;
97 //  huds_left = options & HUDS_LEFT;
98 //  huds_vert = options & HUDS_VERT;
99 //  huds_notext = options & HUDS_NOTEXT;
100 //  huds_top = options & HUDS_TOP;
101 //  huds_bottom = options & HUDS_BOTTOM;
102 }
103
104 hud_card & hud_card ::
105 operator = (const hud_card & rhs )
106 {
107     if( !( this == &rhs)){
108         instr_scale::operator = (rhs);
109         val_span = rhs.val_span;
110         half_width_units = rhs.half_width_units;
111         draw_tick_bottom = rhs.draw_tick_bottom;
112         draw_tick_top    = rhs.draw_tick_top;
113         draw_tick_right  = rhs.draw_tick_right;
114         draw_tick_left   = rhs.draw_tick_left;
115         draw_cap_bottom  = rhs.draw_cap_bottom;
116         draw_cap_top     = rhs.draw_cap_top;
117         draw_cap_right   = rhs.draw_cap_right;
118         draw_cap_left    = rhs.draw_cap_left;
119         marker_offset    = rhs.marker_offset;
120         type             = rhs.type;
121         pointer                  = rhs.pointer;
122         pointer_type     = rhs.pointer_type;
123     }
124
125     return *this;
126 }
127
128 void hud_card ::
129 draw( void ) //  (HUD_scale * pscale )
130 {
131
132     float vmin = 0.0, vmax = 0.0;
133     int marker_xs;
134     int marker_xe;
135     int marker_ys;
136     int marker_ye;
137     int text_x = 0, text_y = 0;
138     int lenstr;
139     int height, width;
140     int i, last;
141     char TextScale[80];
142     bool condition;
143     int disp_val = 0;
144
145     POINT mid_scr    = get_centroid();
146     float cur_value  = get_value();
147     RECT   scrn_rect = get_location();
148     UINT options     = get_options();
149
150     height = scrn_rect.top  + scrn_rect.bottom;
151     width = scrn_rect.left + scrn_rect.right;
152     marker_xs = scrn_rect.left;  // x start
153
154     if(type=="gauge") {
155
156         vmin   = min_val();
157         vmax   = max_val();
158         text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
159         text_x = marker_xs;
160     } else {
161         if(type=="tape") {
162                 
163             vmin   = cur_value - half_width_units; // width units == needle travel
164             vmax   = cur_value + half_width_units; // or picture unit span.
165             text_x = mid_scr.x;
166             text_y = mid_scr.y;
167         }
168     }
169   
170     // Draw the basic markings for the scale...
171   
172     if( huds_vert(options) ) { // Vertical scale
173         if (draw_tick_bottom) {
174             drawOneLine( scrn_rect.left,     // Bottom tick bar
175                          scrn_rect.top,
176                          width,
177                          scrn_rect.top);
178         } // endif draw_tick_bottom
179         if (draw_tick_top) {
180             drawOneLine( scrn_rect.left,    // Top tick bar
181                          height,
182                          width,
183                          height );
184         } // endif draw_tick_top
185       
186         marker_xs = scrn_rect.left;  // x start
187         marker_xe = width;  // x extent
188         marker_ye = height;
189
190         //    glBegin(GL_LINES);
191       
192         // Bottom tick bar
193         //    glVertex2f( marker_xs, scrn_rect.top);
194         //    glVertex2f( marker_xe, scrn_rect.top);
195
196                   // Top tick bar
197         //    glVertex2f( marker_xs, marker_ye);
198         //    glVertex2f( marker_xe, marker_ye );
199         //    glEnd();
200
201
202         // We do not use else in the following so that combining the
203         // two options produces a "caged" display with double
204         // carrots. The same is done for horizontal card indicators.
205
206         if( huds_left(options) ) {    // Calculate x marker offset
207                         
208             if (draw_cap_right) {
209                           
210                 drawOneLine( marker_xe, scrn_rect.top,
211                              marker_xe, marker_ye); // Cap right side
212             } //endif cap_right
213
214             marker_xs  = marker_xe - scrn_rect.right / 3;   // Adjust tick xs
215
216             // drawOneLine( marker_xs, mid_scr.y,
217             //              marker_xe, mid_scr.y + scrn_rect.right / 6);
218             // drawOneLine( marker_xs, mid_scr.y,
219             //              marker_xe, mid_scr.y - scrn_rect.right / 6);
220
221             // draw pointer
222             if(pointer) {
223                 if(pointer_type=="fixed")       {
224                     glBegin(GL_LINE_STRIP);
225                     glVertex2f( marker_offset+marker_xe, text_y + scrn_rect.right / 6);
226                     glVertex2f( marker_offset+marker_xs, text_y);
227                     glVertex2f( marker_offset+marker_xe, text_y - scrn_rect.right / 6);
228                     glEnd();
229                 } else {
230                     if(pointer_type=="moving")  {
231                         //Code for Moving Type Pointer to be included.
232                     }
233                 }
234             }
235         }
236                 
237         if( huds_right(options) ) {  // We'll default this for now.
238             if (draw_cap_left) {
239                 drawOneLine( scrn_rect.left, scrn_rect.top,
240                              scrn_rect.left, marker_ye );  // Cap left side
241             } //endif cap_left
242
243             marker_xe = scrn_rect.left + scrn_rect.right / 3;     // Adjust tick xe
244             // Indicator carrot
245             // drawOneLine( scrn_rect.left, mid_scr.y +  scrn_rect.right / 6,
246             //              marker_xe, mid_scr.y );
247             // drawOneLine( scrn_rect.left, mid_scr.y -  scrn_rect.right / 6,
248             //              marker_xe, mid_scr.y);
249                         
250             // draw pointer
251             if(pointer) {
252                 if(pointer_type=="fixed")       {
253                     glBegin(GL_LINE_STRIP);
254                     glVertex2f( -marker_offset+scrn_rect.left, text_y +  scrn_rect.right / 6);
255                     glVertex2f( -marker_offset+marker_xe, text_y );
256                     glVertex2f( -marker_offset+scrn_rect.left, text_y -  scrn_rect.right / 6);
257                     glEnd();
258                 }
259                 else {
260                     if(pointer_type=="moving")  {
261                         // Code for Moving Type Pointer to be included.
262                     }
263                 }
264             }
265         }
266
267         // At this point marker x_start and x_end values are transposed.
268         // To keep this from confusing things they are now interchanged.
269         if(huds_both(options)) {
270             marker_ye = marker_xs;
271             marker_xs = marker_xe;
272             marker_xe = marker_ye;
273         }
274
275         // Work through from bottom to top of scale. Calculating where to put
276         // minor and major ticks.
277
278         // draw scale or tape
279         //  last = FloatToInt(vmax)+1;
280         //  i = FloatToInt(vmin);
281         last = (int)vmax + 1;
282         i = (int)vmin;
283         for( ; i <last ; i++ ) {
284             condition = true;
285             if( !modulo()) {
286                 if( i < min_val()) {
287                     condition = false;
288                 }
289             }
290
291             if( condition ) {  // Show a tick if necessary
292                 // Calculate the location of this tick
293                 marker_ys = scrn_rect.top + FloatToInt(((i - vmin) * factor()/*+.5f*/));
294                 // marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
295                 // Block calculation artifact from drawing ticks below min coordinate.
296                 // Calculation here accounts for text height.
297
298                 if(( marker_ys < (scrn_rect.top + 4)) |
299                    ( marker_ys > (height - 4)))
300                 {
301                     // Magic numbers!!!
302                     continue;
303                 }
304                 if( div_min()) {
305                     // if( (i%div_min()) == 0) {
306                     if( !(i%(int)div_min())) {            
307                         if((( marker_ys - 5) > scrn_rect.top ) &&
308                            (( marker_ys + 5) < (height))){
309                             if( huds_both(options) ) {
310                                 drawOneLine( scrn_rect.left, marker_ys,
311                                              marker_xs,      marker_ys );
312                                 drawOneLine( marker_xe,      marker_ys,
313                                              width,  marker_ys );
314                                 // glBegin(GL_LINES);
315                                 // glVertex2f( scrn_rect.left, marker_ys );
316                                 // glVertex2f( marker_xs,      marker_ys );
317                                 // glVertex2f( marker_xe,      marker_ys);
318                                 // glVertex2f( scrn_rect.left + scrn_rect.right,  marker_ys );
319                                 // glEnd();
320                             } else {
321                                 if( huds_left(options) ) {
322                                     drawOneLine( marker_xs + 4, marker_ys,
323                                                  marker_xe,     marker_ys );
324                                 } else {
325                                     drawOneLine( marker_xs,     marker_ys,
326                                                  marker_xe - 4, marker_ys );
327                                 }
328                             }
329                         }
330                     }
331                 }
332
333                 if( div_max() ) {
334                     if( !(i%(int)div_max()) ) {
335                         if(modulo()) {
336                             if( disp_val < 0) {
337                                 while(disp_val < 0)
338                                     disp_val += modulo();
339                             // } else {
340                             //   disp_val = i % (int)modulo();
341                             }
342                             disp_val = i % (int) modulo(); // ?????????
343                         } else {
344                             disp_val = i;
345                         }
346
347                         lenstr = sprintf( TextScale, "%d",
348                                           FloatToInt(disp_val * data_scaling()/*+.5*/));
349                         // (int)(disp_val  * data_scaling() +.5));
350                         if(( (marker_ys - 8 ) > scrn_rect.top ) &&
351                            ( (marker_ys + 8) < (height))){
352                             if( huds_both(options) ) {
353                                 // drawOneLine( scrn_rect.left, marker_ys,
354                                 //              marker_xs,      marker_ys);
355                                 // drawOneLine( marker_xs, marker_ys,
356                                 //              scrn_rect.left + scrn_rect.right,
357                                 //              marker_ys);
358                                 glBegin(GL_LINE_STRIP);
359                                 glVertex2f( scrn_rect.left, marker_ys );
360                                 glVertex2f( marker_xs, marker_ys);
361                                 glVertex2f( width, marker_ys);
362                                 glEnd();
363                                 if( !huds_notext(options)) {
364                                     textString ( marker_xs + 2,  marker_ys,
365                                                  TextScale,  GLUT_BITMAP_8_BY_13 );
366                                 }
367                             } else {
368                                 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
369                                 if( !huds_notext(options) ) {
370                                     if( huds_left(options) )              {
371                                         textString( marker_xs -  8 * lenstr - 2,
372                                                     marker_ys - 4,
373                                                     TextScale, GLUT_BITMAP_8_BY_13 );
374                                     } else  {
375                                         textString( marker_xe + 3 * lenstr,
376                                                     marker_ys - 4,
377                                                     TextScale, GLUT_BITMAP_8_BY_13 );
378                                     }
379                                 }
380                             }
381                         } // Else read oriented right
382                     } // End if modulo division by major interval is zero
383                 }  // End if major interval divisor non-zero
384             } // End if condition
385         } // End for range of i from vmin to vmax
386     }  // End if VERTICAL SCALE TYPE
387     else {                                // Horizontal scale by default
388         // left tick bar
389         if (draw_tick_left) {
390             drawOneLine( scrn_rect.left, scrn_rect.top,
391                          scrn_rect.left, height);
392         } // endif draw_tick_left
393         // right tick bar
394         if (draw_tick_right) {
395             drawOneLine( width, scrn_rect.top,
396                          width,
397                          height );
398         } // endif draw_tick_right
399       
400         marker_ys = scrn_rect.top;           // Starting point for
401         marker_ye = height;                  // tick y location calcs
402         marker_xe = width;
403         marker_xs = scrn_rect.left + FloatToInt((cur_value - vmin) * factor() /*+ .5f*/);
404                   
405
406         //    glBegin(GL_LINES);
407                   // left tick bar
408         //    glVertex2f( scrn_rect.left, scrn_rect.top);
409         //    glVertex2f( scrn_rect.left, marker_ye);
410
411                   // right tick bar
412         //    glVertex2f( marker_xe, scrn_rect.top);
413         //    glVertex2f( marker_xe, marker_ye );
414         //    glEnd();
415
416         if( huds_top(options) ) {
417             if (draw_cap_bottom) {
418                 // Bottom box line
419                 drawOneLine( scrn_rect.left,
420                              scrn_rect.top,
421                              width,
422                              scrn_rect.top);
423             } //endif cap_bottom
424
425             // Tick point adjust
426             marker_ye  = scrn_rect.top + scrn_rect.bottom / 2;
427             // Bottom arrow
428             // drawOneLine( mid_scr.x, marker_ye,
429             //              mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
430             // drawOneLine( mid_scr.x, marker_ye,
431             //              mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
432             // draw pointer
433             if(pointer) {
434                 if(pointer_type=="fixed")       {
435                     glBegin(GL_LINE_STRIP);
436                     glVertex2f( marker_xs - scrn_rect.bottom / 4, scrn_rect.top);
437                     glVertex2f( marker_xs, marker_ye);
438                     glVertex2f( marker_xs + scrn_rect.bottom / 4, scrn_rect.top);
439                     glEnd();
440                 } else {
441                     if(pointer_type=="moving")  {
442                         // Code for Moving type Pointer to be included.
443                     }
444                 }
445             }
446         }
447
448         if( huds_bottom(options) ) {
449             // Top box line
450             if (draw_cap_top) {
451                 drawOneLine( scrn_rect.left, height,
452                              width, height);
453             } //endif cap_top
454
455             // Tick point adjust
456             marker_ys = height - scrn_rect.bottom  / 2;
457             // Top arrow
458             //      drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
459             //                   scrn_rect.top + scrn_rect.bottom,
460             //                   mid_scr.x, marker_ys );
461             //      drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
462             //                   scrn_rect.top + scrn_rect.bottom,
463             //                   mid_scr.x , marker_ys );
464             
465             // draw pointer
466             if(pointer) {
467                 if(pointer_type=="fixed")       {
468                     glBegin(GL_LINE_STRIP);
469                     glVertex2f( marker_xs + scrn_rect.bottom / 4, height);
470                     glVertex2f( marker_xs, marker_ys );
471                     glVertex2f( marker_xs - scrn_rect.bottom / 4, height);
472                     glEnd();
473                 } else {
474                     if(pointer_type=="moving")  {
475                         // Code for Moving Type Pointer to be included.
476                     }
477                 }
478             }//if pointer
479
480         }
481
482         //    if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
483         //      marker_xe = marker_ys;
484         //      marker_ys = marker_ye;
485         //      marker_ye = marker_xe;
486         //      }
487
488                 // printf("vmin = %d  vmax = %d\n", (int)vmin, (int)vmax);
489
490         //  last = FloatToInt(vmax)+1;
491         //  i    = FloatToInt(vmin);
492         last = (int)vmax + 1;
493         i = (int)vmin;
494         for(; i <last ; i++ ) {
495             // for( i = (int)vmin; i <= (int)vmax; i++ )     {
496             // printf("<*> i = %d\n", i);
497             condition = true;
498             if( !modulo()) {
499                 if( i < min_val()) {
500                     condition = false;
501                 }
502             }
503             // printf("<**> i = %d\n", i);
504             if( condition )        {
505                 // marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
506                 marker_xs = scrn_rect.left + FloatToInt(((i - vmin) * factor()/*+ .5f*/));
507                 if( div_min()){
508                     //          if( (i%(int)div_min()) == 0 ) {
509                     if( !(i%(int)div_min() )) {           
510                         // draw in ticks only if they aren't too close to the edge.
511                         if((( marker_xs - 5) > scrn_rect.left ) &&
512                            (( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
513                             
514                             if( huds_both(options) ) {
515                                 drawOneLine( marker_xs, scrn_rect.top,
516                                              marker_xs, marker_ys - 4);
517                                 drawOneLine( marker_xs, marker_ye + 4,
518                                              marker_xs, height);
519                                 // glBegin(GL_LINES);
520                                 // glVertex2f( marker_xs, scrn_rect.top);
521                                 // glVertex2f( marker_xs, marker_ys - 4);
522                                 // glVertex2f( marker_xs, marker_ye + 4);
523                                 // glVertex2f( marker_xs, scrn_rect.top + scrn_rect.bottom);
524                                 // glEnd();
525                             } else {
526                                 if( huds_top(options)) {
527                                     // draw minor ticks
528                                     drawOneLine( marker_xs, marker_ys,
529                                                  marker_xs, marker_ye - 4);
530                                 } else {
531                                     drawOneLine( marker_xs, marker_ys + 4,
532                                                  marker_xs, marker_ye);
533                                 }
534                             }
535                         }
536                     }
537                 }
538                 // printf("<***> i = %d\n", i);
539                 if( div_max()) {
540                     // printf("i = %d\n", i);
541                     //          if( (i%(int)div_max())==0 ) {
542                     if( !(i%(int)div_max()) ) {           
543                         if(modulo()) {
544                             if( disp_val < 0) {
545                                 while(disp_val<0)
546                                     disp_val += modulo();
547                             }
548                             disp_val = i % (int) modulo(); // ?????????
549                         } else {
550                             disp_val = i;
551                         }
552                         // printf("disp_val = %d\n", disp_val);
553                         // printf("%d\n", (int)(disp_val  * (double)data_scaling() + 0.5));
554                         lenstr = sprintf( TextScale, "%d",
555                                           // (int)(disp_val  * data_scaling() +.5));
556                                           FloatToInt(disp_val * data_scaling()/*+.5*/));
557                         // Draw major ticks and text only if far enough from the edge.
558                         if(( (marker_xs - 10)> scrn_rect.left ) &&
559                            ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
560                             if( huds_both(options) ) {
561                                 // drawOneLine( marker_xs, scrn_rect.top,
562                                 //              marker_xs, marker_ys);
563                                 // drawOneLine( marker_xs, marker_ye,
564                                 //              marker_xs, scrn_rect.top + scrn_rect.bottom);
565                                 glBegin(GL_LINE_STRIP);
566                                 glVertex2f( marker_xs, scrn_rect.top);
567                                 glVertex2f( marker_xs, marker_ye);
568                                 glVertex2f( marker_xs, height);
569                                 glEnd();
570                                 if( !huds_notext(options) ) {
571                                     textString ( marker_xs - 4 * lenstr,
572                                                  marker_ys + 4,
573                                                  TextScale,  GLUT_BITMAP_8_BY_13 );
574                                 }
575                             } else {
576                                 drawOneLine( marker_xs, marker_ys,
577                                              marker_xs, marker_ye );
578                                 if( !huds_notext(options)) {
579                                     if( huds_top(options) )              {
580                                         textString ( marker_xs - 4 * lenstr,
581                                                      height - 10,
582                                                      TextScale, GLUT_BITMAP_8_BY_13 );
583                                     } else  {
584                                         textString( marker_xs - 4 * lenstr,
585                                                     scrn_rect.top,
586                                                     TextScale, GLUT_BITMAP_8_BY_13 );
587                                     }
588                                 }
589                             }
590                         }
591                     }
592                 }
593                 // printf("<****> i = %d\n", i);
594             }
595         }
596     }
597 } //draw