]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lon.cxx
Update from JSBSim
[flightgear.git] / src / Cockpit / hud_lon.cxx
1
2 #include "hud.hxx"
3
4
5 #ifdef USE_HUD_TextList
6 #define textString( x , y, text, font,digit )  TextString( text, x , y,digit ) //suma
7 #else
8 #define textString( x , y, text, font,digit )  puDrawString ( guiFnt, text, x, y ); //suma
9 #endif
10
11 //======================= Top of instr_label class =========================
12 lon_label ::
13          lon_label( int           x,
14                       int           y,
15                       UINT          width,
16                       UINT          height,
17                       FLTFNPTR      data_source,
18 //                      DBLFNPTR      data_source,                                      
19                       const char   *label_format,
20                       const char   *pre_label_string,
21                       const char   *post_label_string,
22                       float        scale_data,
23 //                      double        scale_data,                                       
24                       UINT          options,
25                       fgLabelJust   justification,
26                       int           font_size,
27                       int           blinking,
28                       bool          working,
29                                           int                   digit): //suma
30                            instr_item( x, y, width, height,
31                                        data_source, scale_data,options, working,digit ), //suma
32                            pformat  ( label_format      ),
33                            pre_str  ( pre_label_string  ),
34                            post_str ( post_label_string ),
35                            justify  ( justification     ),
36                            fontSize ( font_size         ),
37                            blink    ( blinking          )
38 {
39   if( pre_str != NULL) {
40     if( post_str != NULL ) {
41       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
42       }
43     else {
44       sprintf( format_buffer, "%s%s",   pre_str, pformat );
45       }
46     }
47   else {
48     if( post_str != NULL ) {
49       sprintf( format_buffer, "%s%s",   pformat, post_str );
50       }
51     } // else do nothing if both pre and post strings are nulls. Interesting.
52
53 }
54
55 // I put this in to make it easy to construct a class member using the current
56 // C code.
57
58
59 lon_label :: ~lon_label()
60 {
61 }
62
63 // Copy constructor
64 lon_label :: lon_label( const lon_label & image) :
65                               instr_item((const instr_item &)image),
66                               pformat    ( image.pformat    ),
67                               pre_str  ( image.pre_str  ),
68                               post_str ( image.post_str ),
69                               blink    ( image.blink    )
70 {
71   if( pre_str != NULL) {
72     if( post_str != NULL ) {
73       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
74       }
75     else {
76       sprintf( format_buffer, "%s%s",   pre_str, pformat );
77       }
78     }
79   else {
80     if( post_str != NULL ) {
81       sprintf( format_buffer, "%s%s",   pformat, post_str );
82       }
83     } // else do nothing if both pre and post strings are nulls. Interesting.
84
85 }
86
87 lon_label & lon_label ::operator = (const lon_label & rhs )
88 {
89   if( !(this == &rhs)) {
90     instr_item::operator = (rhs);
91     pformat      = rhs.pformat;
92     fontSize   = rhs.fontSize;
93     blink      = rhs.blink;
94     justify    = rhs.justify;
95     pre_str    = rhs.pre_str;
96     post_str   = rhs.post_str;
97     strcpy(format_buffer,rhs.format_buffer);    
98     }
99   return *this;
100 }
101
102 //
103 // draw                    Draws a label anywhere in the HUD
104 //
105 //
106 void lon_label ::
107 draw( void )       // Required method in base class
108 {
109 //  char format_buffer[80];
110   char label_buffer[80];
111   int posincr;
112   int lenstr;
113   RECT  scrn_rect = get_location();
114   float lon = get_value();
115 //  double lon = get_value();  
116   if( data_available() ) {
117 //      char *lonstring = coord_format_lon(lon);
118     lenstr = sprintf( label_buffer, format_buffer, coord_format_lon(lon) );
119     }
120   else {
121     lenstr = sprintf( label_buffer, format_buffer );
122     }
123     
124 #ifdef DEBUGHUD
125   fgPrintf( SG_COCKPIT, SG_DEBUG,  format_buffer );
126   fgPrintf( SG_COCKPIT, SG_DEBUG,  "\n" );
127   fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
128   fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
129 #endif
130         
131         lenstr = getStringWidth(label_buffer);
132                                                 
133   if( justify == RIGHT_JUST ) {
134           posincr = scrn_rect.right - lenstr;
135   }else if( justify == CENTER_JUST ) {
136           posincr = get_span() - (lenstr/2);
137   }  else {
138       //  justify == LEFT_JUST
139       posincr = 0;
140   }
141   
142   if( fontSize == SMALL ) {
143     textString( scrn_rect.left + posincr, scrn_rect.top,
144                 label_buffer, GLUT_BITMAP_8_BY_13, get_digits()); //suma
145     }
146   else  {
147     if( fontSize == LARGE ) {
148       textString( scrn_rect.left + posincr, scrn_rect.top,
149                   label_buffer, GLUT_BITMAP_9_BY_15, get_digits()); //suma
150       }
151     }
152 }
153