]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
a20f024459164af3462f439d7c2b0243acac70d1
[flightgear.git] / src / Cockpit / hud_labl.cxx
1
2 #include "hud.hxx"
3
4
5 #ifdef USE_HUD_TextList
6 #define textString( x , y, text, digit )  TextString( text, x , y,digit ) //suma
7 #else
8 #define textString( x , y, text, digit )  puDrawString ( guiFnt, text, x, y ); //suma
9 #endif
10
11 //======================= Top of instr_label class =========================
12 instr_label ::
13          instr_label( int           x,
14                       int           y,
15                       UINT          width,
16                       UINT          height,
17                       FLTFNPTR      data_source,
18                       const char   *label_format,
19                       const char   *pre_label_string,
20                       const char   *post_label_string,
21                       float        scale_data,
22                       UINT          options,
23                       fgLabelJust   justification,
24                       int           font_size,
25                       int           blinking,
26                                       bool                      latitude,
27                                       bool                      longitude,
28                                           bool                  label_box,//hud
29                       bool          working,
30                                           int                   digit):  //suma
31                            instr_item( x, y, width, height,
32                                        data_source,scale_data,options, working, digit), //suma
33                            pformat  ( label_format      ),
34                            pre_str  ( pre_label_string  ),
35                            post_str ( post_label_string ),
36                            justify  ( justification     ),
37                            fontSize ( font_size         ),
38                            blink    ( blinking          ),
39                                                    lat          ( latitude                      ),
40                                                    lon          ( longitude                     ),
41                                                    lbox         ( label_box                     ) //hud
42
43 {
44   if( pre_str != NULL) {
45     if( post_str != NULL ) {
46       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
47       }
48     else {
49       sprintf( format_buffer, "%s%s",   pre_str, pformat );
50       }
51     }
52   else {
53     if( post_str != NULL ) {
54       sprintf( format_buffer, "%s%s",   pformat, post_str );
55       }
56     } // else do nothing if both pre and post strings are nulls. Interesting.
57
58 }
59
60 // I put this in to make it easy to construct a class member using the current
61 // C code.
62
63
64 instr_label :: ~instr_label()
65 {
66 }
67
68 // Copy constructor
69 instr_label :: instr_label( const instr_label & image) :
70                               instr_item((const instr_item &)image),
71                               pformat    ( image.pformat    ),
72                               pre_str  ( image.pre_str  ),
73                               post_str ( image.post_str ),
74                               blink    ( image.blink    ),
75                                                           lat      ( image.lat          ),
76                                                           lon      ( image.lon          ),      
77                                                           lbox     (image.lbox          ) //hud
78
79 {
80   if( pre_str != NULL) {
81     if( post_str != NULL ) {
82       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
83       }
84     else {
85       sprintf( format_buffer, "%s%s",   pre_str, pformat );
86       }
87     }
88   else {
89     if( post_str != NULL ) {
90       sprintf( format_buffer, "%s%s",   pformat, post_str );
91       }
92     } // else do nothing if both pre and post strings are nulls. Interesting.
93
94 }
95
96
97 //
98 // draw                    Draws a label anywhere in the HUD
99 //
100 //
101 void instr_label ::
102 draw( void )       // Required method in base class
103 {
104 //  char format_buffer[80];
105   char label_buffer[80];
106   int posincr;
107   int lenstr;
108   RECT  scrn_rect = get_location();
109
110   if( data_available() ) {
111         if(lat)
112                 sprintf( label_buffer, format_buffer, coord_format_lat(get_value()) );
113         else
114         if(lon)    
115                 sprintf( label_buffer, format_buffer, coord_format_lon(get_value()) );
116         else
117         {       
118                 if(lbox)//hud
119                         {// Box for label
120                                 float x = scrn_rect.left;
121                                 float y = scrn_rect.top;
122                                 float w = scrn_rect.right;
123                         float h = HUD_TextSize;
124
125                                 glPushMatrix();
126                                 glLoadIdentity();
127                                 glBegin(GL_LINES);
128                                         glVertex2f( x - 2.0,  y - 2.0);
129                                         glVertex2f( x + w + 2.0, y - 2.0);
130                                         glVertex2f( x + w + 2.0, y + h + 2.0);
131                                         glVertex2f( x - 2.0,  y + h + 2.0);
132                                 glEnd();
133                         glEnable(GL_LINE_STIPPLE);
134                                 glLineStipple( 1, 0xAAAA );
135                                 glBegin(GL_LINES);
136                                         glVertex2f( x + w + 2.0, y - 2.0);
137                                         glVertex2f( x + w + 2.0, y + h + 2.0);
138                                         glVertex2f( x - 2.0,  y + h + 2.0);
139                                         glVertex2f( x - 2.0,  y - 2.0);
140                                 glEnd();
141                         glDisable(GL_LINE_STIPPLE);
142                                 glPopMatrix();
143                         }//hud
144                 sprintf( label_buffer, format_buffer, get_value()*data_scaling() );
145         }
146   }
147   else {
148 //    sprintf( label_buffer, format_buffer );
149   }
150   
151   lenstr = getStringWidth( label_buffer );
152                                                 
153     
154 #ifdef DEBUGHUD
155   fgPrintf( SG_COCKPIT, SG_DEBUG,  format_buffer );
156   fgPrintf( SG_COCKPIT, SG_DEBUG,  "\n" );
157   fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
158   fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
159 #endif
160   lenstr = strlen( label_buffer );
161
162   if( justify == RIGHT_JUST ) {
163           posincr = scrn_rect.right - lenstr;
164   }else if( justify == CENTER_JUST ) {
165           posincr = get_span() - (lenstr/2); //  -lenstr*4;
166   }  else {
167       //  justify == LEFT_JUST
168       posincr = 0;  // 0;
169   }
170   
171   if( fontSize == HUD_FONT_SMALL ) {
172     textString( scrn_rect.left + posincr, scrn_rect.top,
173                 label_buffer, get_digits()); //suma
174     }
175   else  {
176     if( fontSize == HUD_FONT_LARGE ) {
177       textString( scrn_rect.left + posincr, scrn_rect.top,
178                   label_buffer, get_digits()); //suma
179       }
180     }
181 }
182