]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_card.cxx
- adjusted for no-value constructor for FGPanel
[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
153     if(type=="guage") {
154
155         vmin   = min_val();
156         vmax   = max_val();
157         text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
158         text_x = marker_xs;
159     } else {
160         if(type=="tape") {
161                 
162             vmin   = cur_value - half_width_units; // width units == needle travel
163             vmax   = cur_value + half_width_units; // or picture unit span.
164             text_x = mid_scr.x;
165             text_y = mid_scr.y;
166         }
167     }
168   
169     // Draw the basic markings for the scale...
170   
171     if( huds_vert(options) ) { // Vertical scale
172         if (draw_tick_bottom) {
173             drawOneLine( scrn_rect.left,     // Bottom tick bar
174                          scrn_rect.top,
175                          width,
176                          scrn_rect.top);
177         } // endif draw_tick_bottom
178         if (draw_tick_top) {
179             drawOneLine( scrn_rect.left,    // Top tick bar
180                          height,
181                          width,
182                          height );
183         } // endif draw_tick_top
184       
185         marker_xs = scrn_rect.left;  // x start
186         marker_xe = width;  // x extent
187         marker_ye = height;
188
189         //    glBegin(GL_LINES);
190       
191         // Bottom tick bar
192         //    glVertex2f( marker_xs, scrn_rect.top);
193         //    glVertex2f( marker_xe, scrn_rect.top);
194
195                   // Top tick bar
196         //    glVertex2f( marker_xs, marker_ye);
197         //    glVertex2f( marker_xe, marker_ye );
198         //    glEnd();
199
200
201         // We do not use else in the following so that combining the
202         // two options produces a "caged" display with double
203         // carrots. The same is done for horizontal card indicators.
204
205         if( huds_left(options) ) {    // Calculate x marker offset
206                         
207             if (draw_cap_right) {
208                           
209                 drawOneLine( marker_xe, scrn_rect.top,
210                              marker_xe, marker_ye); // Cap right side
211             } //endif cap_right
212
213             marker_xs  = marker_xe - scrn_rect.right / 3;   // Adjust tick xs
214
215             // drawOneLine( marker_xs, mid_scr.y,
216             //              marker_xe, mid_scr.y + scrn_rect.right / 6);
217             // drawOneLine( marker_xs, mid_scr.y,
218             //              marker_xe, mid_scr.y - scrn_rect.right / 6);
219
220             // draw pointer
221             if(pointer) {
222                 if(pointer_type=="fixed")       {
223                     glBegin(GL_LINE_STRIP);
224                     glVertex2f( marker_offset+marker_xe, text_y + scrn_rect.right / 6);
225                     glVertex2f( marker_offset+marker_xs, text_y);
226                     glVertex2f( marker_offset+marker_xe, text_y - scrn_rect.right / 6);
227                     glEnd();
228                 } else {
229                     if(pointer_type=="moving")  {
230                         //Code for Moving Type Pointer to be included.
231                     }
232                 }
233             }
234         }
235                 
236         if( huds_right(options) ) {  // We'll default this for now.
237             if (draw_cap_left) {
238                 drawOneLine( scrn_rect.left, scrn_rect.top,
239                              scrn_rect.left, marker_ye );  // Cap left side
240             } //endif cap_left
241
242             marker_xe = scrn_rect.left + scrn_rect.right / 3;     // Adjust tick xe
243             // Indicator carrot
244             // drawOneLine( scrn_rect.left, mid_scr.y +  scrn_rect.right / 6,
245             //              marker_xe, mid_scr.y );
246             // drawOneLine( scrn_rect.left, mid_scr.y -  scrn_rect.right / 6,
247             //              marker_xe, mid_scr.y);
248                         
249             // draw pointer
250             if(pointer) {
251                 if(pointer_type=="fixed")       {
252                     glBegin(GL_LINE_STRIP);
253                     glVertex2f( -marker_offset+scrn_rect.left, text_y +  scrn_rect.right / 6);
254                     glVertex2f( -marker_offset+marker_xe, text_y );
255                     glVertex2f( -marker_offset+scrn_rect.left, text_y -  scrn_rect.right / 6);
256                     glEnd();
257                 }
258                 else {
259                     if(pointer_type=="moving")  {
260                         // Code for Moving Type Pointer to be included.
261                     }
262                 }
263             }
264         }
265
266         // At this point marker x_start and x_end values are transposed.
267         // To keep this from confusing things they are now interchanged.
268         if(huds_both(options)) {
269             marker_ye = marker_xs;
270             marker_xs = marker_xe;
271             marker_xe = marker_ye;
272         }
273
274         // Work through from bottom to top of scale. Calculating where to put
275         // minor and major ticks.
276
277         // draw scale or tape
278         //  last = FloatToInt(vmax)+1;
279         //  i = FloatToInt(vmin);
280         last = (int)vmax + 1;
281         i = (int)vmin;
282         for( ; i <last ; i++ ) {
283             condition = true;
284             if( !modulo()) {
285                 if( i < min_val()) {
286                     condition = false;
287                 }
288             }
289
290             if( condition ) {  // Show a tick if necessary
291                 // Calculate the location of this tick
292                 marker_ys = scrn_rect.top + FloatToInt(((i - vmin) * factor()/*+.5f*/));
293                 // marker_ys = scrn_rect.top + (int)((i - vmin) * factor() + .5);
294                 // Block calculation artifact from drawing ticks below min coordinate.
295                 // Calculation here accounts for text height.
296
297                 if(( marker_ys < (scrn_rect.top + 4)) |
298                    ( marker_ys > (height - 4)))
299                 {
300                     // Magic numbers!!!
301                     continue;
302                 }
303                 if( div_min()) {
304                     // if( (i%div_min()) == 0) {
305                     if( !(i%(int)div_min())) {            
306                         if((( marker_ys - 5) > scrn_rect.top ) &&
307                            (( marker_ys + 5) < (height))){
308                             if( huds_both(options) ) {
309                                 drawOneLine( scrn_rect.left, marker_ys,
310                                              marker_xs,      marker_ys );
311                                 drawOneLine( marker_xe,      marker_ys,
312                                              width,  marker_ys );
313                                 // glBegin(GL_LINES);
314                                 // glVertex2f( scrn_rect.left, marker_ys );
315                                 // glVertex2f( marker_xs,      marker_ys );
316                                 // glVertex2f( marker_xe,      marker_ys);
317                                 // glVertex2f( scrn_rect.left + scrn_rect.right,  marker_ys );
318                                 // glEnd();
319                             } else {
320                                 if( huds_left(options) ) {
321                                     drawOneLine( marker_xs + 4, marker_ys,
322                                                  marker_xe,     marker_ys );
323                                 } else {
324                                     drawOneLine( marker_xs,     marker_ys,
325                                                  marker_xe - 4, marker_ys );
326                                 }
327                             }
328                         }
329                     }
330                 }
331
332                 if( div_max() ) {
333                     if( !(i%(int)div_max()) ) {
334                         if(modulo()) {
335                             if( disp_val < 0) {
336                                 while(disp_val < 0)
337                                     disp_val += modulo();
338                             // } else {
339                             //   disp_val = i % (int)modulo();
340                             }
341                             disp_val = i % (int) modulo(); // ?????????
342                         } else {
343                             disp_val = i;
344                         }
345
346                         lenstr = sprintf( TextScale, "%d",
347                                           FloatToInt(disp_val * data_scaling()/*+.5*/));
348                         // (int)(disp_val  * data_scaling() +.5));
349                         if(( (marker_ys - 8 ) > scrn_rect.top ) &&
350                            ( (marker_ys + 8) < (height))){
351                             if( huds_both(options) ) {
352                                 // drawOneLine( scrn_rect.left, marker_ys,
353                                 //              marker_xs,      marker_ys);
354                                 // drawOneLine( marker_xs, marker_ys,
355                                 //              scrn_rect.left + scrn_rect.right,
356                                 //              marker_ys);
357                                 glBegin(GL_LINE_STRIP);
358                                 glVertex2f( scrn_rect.left, marker_ys );
359                                 glVertex2f( marker_xs, marker_ys);
360                                 glVertex2f( width, marker_ys);
361                                 glEnd();
362                                 if( !huds_notext(options)) {
363                                     textString ( marker_xs + 2,  marker_ys,
364                                                  TextScale,  GLUT_BITMAP_8_BY_13 );
365                                 }
366                             } else {
367                                 drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
368                                 if( !huds_notext(options) ) {
369                                     if( huds_left(options) )              {
370                                         textString( marker_xs -  8 * lenstr - 2,
371                                                     marker_ys - 4,
372                                                     TextScale, GLUT_BITMAP_8_BY_13 );
373                                     } else  {
374                                         textString( marker_xe + 3 * lenstr,
375                                                     marker_ys - 4,
376                                                     TextScale, GLUT_BITMAP_8_BY_13 );
377                                     }
378                                 }
379                             }
380                         } // Else read oriented right
381                     } // End if modulo division by major interval is zero
382                 }  // End if major interval divisor non-zero
383             } // End if condition
384         } // End for range of i from vmin to vmax
385     }  // End if VERTICAL SCALE TYPE
386     else {                                // Horizontal scale by default
387         // left tick bar
388         if (draw_tick_left) {
389             drawOneLine( scrn_rect.left, scrn_rect.top,
390                          scrn_rect.left, height);
391         } // endif draw_tick_left
392         // right tick bar
393         if (draw_tick_right) {
394             drawOneLine( width, scrn_rect.top,
395                          width,
396                          height );
397         } // endif draw_tick_right
398       
399         marker_ys = scrn_rect.top;           // Starting point for
400         marker_ye = height;                  // tick y location calcs
401         marker_xe = width;
402         marker_xs = scrn_rect.left + FloatToInt((cur_value - vmin) * factor() /*+ .5f*/);
403                   
404
405         //    glBegin(GL_LINES);
406                   // left tick bar
407         //    glVertex2f( scrn_rect.left, scrn_rect.top);
408         //    glVertex2f( scrn_rect.left, marker_ye);
409
410                   // right tick bar
411         //    glVertex2f( marker_xe, scrn_rect.top);
412         //    glVertex2f( marker_xe, marker_ye );
413         //    glEnd();
414
415         if( huds_top(options) ) {
416             if (draw_cap_bottom) {
417                 // Bottom box line
418                 drawOneLine( scrn_rect.left,
419                              scrn_rect.top,
420                              width,
421                              scrn_rect.top);
422             } //endif cap_bottom
423
424             // Tick point adjust
425             marker_ye  = scrn_rect.top + scrn_rect.bottom / 2;
426             // Bottom arrow
427             // drawOneLine( mid_scr.x, marker_ye,
428             //              mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
429             // drawOneLine( mid_scr.x, marker_ye,
430             //              mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
431             // draw pointer
432             if(pointer) {
433                 if(pointer_type=="fixed")       {
434                     glBegin(GL_LINE_STRIP);
435                     glVertex2f( marker_xs - scrn_rect.bottom / 4, scrn_rect.top);
436                     glVertex2f( marker_xs, marker_ye);
437                     glVertex2f( marker_xs + scrn_rect.bottom / 4, scrn_rect.top);
438                     glEnd();
439                 } else {
440                     if(pointer_type=="moving")  {
441                         // Code for Moving type Pointer to be included.
442                     }
443                 }
444             }
445         }
446
447         if( huds_bottom(options) ) {
448             // Top box line
449             if (draw_cap_top) {
450                 drawOneLine( scrn_rect.left, height,
451                              width, height);
452             } //endif cap_top
453
454             // Tick point adjust
455             marker_ys = height - scrn_rect.bottom  / 2;
456             // Top arrow
457             //      drawOneLine( mid_scr.x + scrn_rect.bottom / 4,
458             //                   scrn_rect.top + scrn_rect.bottom,
459             //                   mid_scr.x, marker_ys );
460             //      drawOneLine( mid_scr.x - scrn_rect.bottom / 4,
461             //                   scrn_rect.top + scrn_rect.bottom,
462             //                   mid_scr.x , marker_ys );
463             
464             // draw pointer
465             if(pointer) {
466                 if(pointer_type=="fixed")       {
467                     glBegin(GL_LINE_STRIP);
468                     glVertex2f( marker_xs + scrn_rect.bottom / 4, height);
469                     glVertex2f( marker_xs, marker_ys );
470                     glVertex2f( marker_xs - scrn_rect.bottom / 4, height);
471                     glEnd();
472                 } else {
473                     if(pointer_type=="moving")  {
474                         // Code for Moving Type Pointer to be included.
475                     }
476                 }
477             }//if pointer
478
479         }
480
481         //    if(( options & HUDS_BOTTOM) == HUDS_BOTTOM ) {
482         //      marker_xe = marker_ys;
483         //      marker_ys = marker_ye;
484         //      marker_ye = marker_xe;
485         //      }
486
487                 // printf("vmin = %d  vmax = %d\n", (int)vmin, (int)vmax);
488
489         //  last = FloatToInt(vmax)+1;
490         //  i    = FloatToInt(vmin);
491         last = (int)vmax + 1;
492         i = (int)vmin;
493         for(; i <last ; i++ ) {
494             // for( i = (int)vmin; i <= (int)vmax; i++ )     {
495             // printf("<*> i = %d\n", i);
496             condition = true;
497             if( !modulo()) {
498                 if( i < min_val()) {
499                     condition = false;
500                 }
501             }
502             // printf("<**> i = %d\n", i);
503             if( condition )        {
504                 // marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
505                 marker_xs = scrn_rect.left + FloatToInt(((i - vmin) * factor()/*+ .5f*/));
506                 if( div_min()){
507                     //          if( (i%(int)div_min()) == 0 ) {
508                     if( !(i%(int)div_min() )) {           
509                         // draw in ticks only if they aren't too close to the edge.
510                         if((( marker_xs - 5) > scrn_rect.left ) &&
511                            (( marker_xs + 5 )< (scrn_rect.left + scrn_rect.right))){
512                             
513                             if( huds_both(options) ) {
514                                 drawOneLine( marker_xs, scrn_rect.top,
515                                              marker_xs, marker_ys - 4);
516                                 drawOneLine( marker_xs, marker_ye + 4,
517                                              marker_xs, height);
518                                 // glBegin(GL_LINES);
519                                 // glVertex2f( marker_xs, scrn_rect.top);
520                                 // glVertex2f( marker_xs, marker_ys - 4);
521                                 // glVertex2f( marker_xs, marker_ye + 4);
522                                 // glVertex2f( marker_xs, scrn_rect.top + scrn_rect.bottom);
523                                 // glEnd();
524                             } else {
525                                 if( huds_top(options)) {
526                                     // draw minor ticks
527                                     drawOneLine( marker_xs, marker_ys,
528                                                  marker_xs, marker_ye - 4);
529                                 } else {
530                                     drawOneLine( marker_xs, marker_ys + 4,
531                                                  marker_xs, marker_ye);
532                                 }
533                             }
534                         }
535                     }
536                 }
537                 // printf("<***> i = %d\n", i);
538                 if( div_max()) {
539                     // printf("i = %d\n", i);
540                     //          if( (i%(int)div_max())==0 ) {
541                     if( !(i%(int)div_max()) ) {           
542                         if(modulo()) {
543                             if( disp_val < 0) {
544                                 while(disp_val<0)
545                                     disp_val += modulo();
546                             }
547                             disp_val = i % (int) modulo(); // ?????????
548                         } else {
549                             disp_val = i;
550                         }
551                         // printf("disp_val = %d\n", disp_val);
552                         // printf("%d\n", (int)(disp_val  * (double)data_scaling() + 0.5));
553                         lenstr = sprintf( TextScale, "%d",
554                                           // (int)(disp_val  * data_scaling() +.5));
555                                           FloatToInt(disp_val * data_scaling()/*+.5*/));
556                         // Draw major ticks and text only if far enough from the edge.
557                         if(( (marker_xs - 10)> scrn_rect.left ) &&
558                            ( (marker_xs + 10) < (scrn_rect.left + scrn_rect.right))){
559                             if( huds_both(options) ) {
560                                 // drawOneLine( marker_xs, scrn_rect.top,
561                                 //              marker_xs, marker_ys);
562                                 // drawOneLine( marker_xs, marker_ye,
563                                 //              marker_xs, scrn_rect.top + scrn_rect.bottom);
564                                 glBegin(GL_LINE_STRIP);
565                                 glVertex2f( marker_xs, scrn_rect.top);
566                                 glVertex2f( marker_xs, marker_ye);
567                                 glVertex2f( marker_xs, height);
568                                 glEnd();
569                                 if( !huds_notext(options) ) {
570                                     textString ( marker_xs - 4 * lenstr,
571                                                  marker_ys + 4,
572                                                  TextScale,  GLUT_BITMAP_8_BY_13 );
573                                 }
574                             } else {
575                                 drawOneLine( marker_xs, marker_ys,
576                                              marker_xs, marker_ye );
577                                 if( !huds_notext(options)) {
578                                     if( huds_top(options) )              {
579                                         textString ( marker_xs - 4 * lenstr,
580                                                      height - 10,
581                                                      TextScale, GLUT_BITMAP_8_BY_13 );
582                                     } else  {
583                                         textString( marker_xs - 4 * lenstr,
584                                                     scrn_rect.top,
585                                                     TextScale, GLUT_BITMAP_8_BY_13 );
586                                     }
587                                 }
588                             }
589                         }
590                     }
591                 }
592                 // printf("<****> i = %d\n", i);
593             }
594         }
595     }
596 } //draw