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