]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_gaug.cxx
Update from JSBSim
[flightgear.git] / src / Cockpit / hud_gaug.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 gauge_instr class member definitions ==============
12
13 gauge_instr ::
14 gauge_instr( int          x,
15              int          y,
16              UINT         width,
17              UINT         height,
18              FLTFNPTR     load_fn,
19              UINT         options,
20              float       disp_scale,
21              float       maxValue,
22              float       minValue,
23              UINT         major_divs,
24              UINT         minor_divs,
25              int          dp_showing,
26              UINT         modulus,
27              bool         working) :
28     instr_scale( x, y, width, height,
29                  load_fn, options,
30                  (maxValue - minValue), // Always shows span?
31                  maxValue, minValue,
32                  disp_scale,
33                  major_divs, minor_divs,
34                  modulus, dp_showing,
35                  working)
36 {
37     //  UINT options = get_options();
38     //  huds_vert    = options & HUDS_VERT;
39     //  huds_left    = options & HUDS_LEFT;
40     //  huds_right   = options & HUDS_RIGHT;
41     //  huds_both    = (options & HUDS_BOTH) == HUDS_BOTH;
42     //  huds_noticks = options & HUDS_NOTICKS;
43     //  huds_notext  = options & HUDS_NOTEXT;
44     //  huds_top     = options & HUDS_TOP;
45     //  huds_bottom  = options & HUDS_BOTTOM;
46 }
47
48 gauge_instr ::
49 ~gauge_instr()
50 {
51 }
52
53 gauge_instr ::
54 gauge_instr( const gauge_instr & image):
55     instr_scale( (instr_scale &) image)
56 {
57     //  UINT options = get_options();
58     //  huds_vert = options & HUDS_VERT;
59     //  huds_left = options & HUDS_LEFT;
60     //  huds_right = options & HUDS_RIGHT;
61     //  huds_both = (options & HUDS_BOTH) == HUDS_BOTH;
62     //  huds_noticks = options & HUDS_NOTICKS;
63     //  huds_notext = options & HUDS_NOTEXT;
64     //  huds_top = options & HUDS_TOP;
65     //  huds_bottom =  options & HUDS_BOTTOM;
66 }
67
68 gauge_instr & gauge_instr ::
69 operator = (const gauge_instr & rhs )
70 {
71     if( !(this == &rhs)) {
72         instr_scale::operator = (rhs);
73     }
74     return *this;
75 }
76
77 // As implemented, draw only correctly draws a horizontal or vertical
78 // scale. It should contain a variation that permits clock type displays.
79 // Now is supports "tickless" displays such as control surface indicators.
80 // This routine should be worked over before using. Current value would be
81 // fetched and not used if not commented out. Clearly that is intollerable.
82
83 void gauge_instr :: draw (void)
84 {
85     int marker_xs, marker_xe;
86     int marker_ys, marker_ye;
87     int text_x, text_y;
88     int width, height, bottom_4;
89     int lenstr;
90     int i;
91     char TextScale[80];
92     bool condition;
93     int disp_val = 0;
94     float vmin       = min_val();
95     float vmax       = max_val();
96     POINT mid_scr    = get_centroid();
97     float cur_value  = get_value();
98     RECT  scrn_rect  = get_location();
99     UINT options     = get_options();
100
101     width = scrn_rect.left + scrn_rect.right;
102     height = scrn_rect.top  + scrn_rect.bottom,
103         bottom_4 = scrn_rect.bottom / 4;
104     // Draw the basic markings for the scale...
105
106     if( huds_vert(options) ) { // Vertical scale
107         drawOneLine( scrn_rect.left,     // Bottom tick bar
108                      scrn_rect.top,
109                      width,
110                      scrn_rect.top);
111
112         drawOneLine( scrn_rect.left,    // Top tick bar
113                      height,
114                      width,
115                      height );
116
117         marker_xs = scrn_rect.left;
118         marker_xe = width;
119
120         if( huds_left(options) ) {     // Read left, so line down right side
121             drawOneLine( width,
122                          scrn_rect.top,
123                          width,
124                          height);
125           
126             marker_xs  = marker_xe - scrn_rect.right / 3;   // Adjust tick xs
127         }
128         
129         if( huds_right(options) ) {     // Read  right, so down left sides
130             drawOneLine( scrn_rect.left,
131                          scrn_rect.top,
132                          scrn_rect.left,
133                          height);
134           
135             marker_xe = scrn_rect.left + scrn_rect.right / 3;     // Adjust tick xe
136         }
137
138         // At this point marker x_start and x_end values are transposed.
139         // To keep this from confusing things they are now interchanged.
140         if( huds_both(options) ) {
141             marker_ye = marker_xs;
142             marker_xs = marker_xe;
143             marker_xe = marker_ye;
144         }
145
146         // Work through from bottom to top of scale. Calculating where to put
147         // minor and major ticks.
148
149         if( !huds_noticks(options)) {    // If not no ticks...:)
150             // Calculate x marker offsets
151             int last = (int)vmax + 1; //FloatToInt(vmax)+1;
152             i = (int)vmin; //FloatToInt(vmin);
153             for(; i <last ; i++ )      {
154                 //      for( i = (int)vmin; i <= (int)vmax; i++ ) {
155
156                 // Calculate the location of this tick
157                 marker_ys = scrn_rect.top + FloatToInt((i - vmin) * factor()/* +.5f*/);
158
159                 // We compute marker_ys even though we don't know if we will use
160                 // either major or minor divisions. Simpler.
161
162                 if( div_min()) {                  // Minor tick marks
163                     if( !(i%(int)div_min()) ) {
164                         if( huds_left(options) && huds_right(options) ) {
165                             drawOneLine( scrn_rect.left, marker_ys,
166                                          marker_xs - 3, marker_ys );
167                             drawOneLine( marker_xe + 3, marker_ys,
168                                          width, marker_ys );
169                         }
170                         else {
171                             if( huds_left(options) ) {
172                                 drawOneLine( marker_xs + 3, marker_ys, marker_xe, marker_ys );
173                             }
174                             else {
175                                 drawOneLine( marker_xs, marker_ys, marker_xe - 3, marker_ys );
176                             }
177                         }
178                     }
179                 }
180
181                 // Now we work on the major divisions. Since these are also labeled
182                 // and no labels are drawn otherwise, we label inside this if
183                 // statement.
184
185                 if( div_max()) {                  // Major tick mark
186                     if( !(i%(int)div_max()) )            {
187                         if( huds_left(options) && huds_right(options) ) {
188                             drawOneLine( scrn_rect.left, marker_ys,
189                                          marker_xs, marker_ys );
190                             drawOneLine( marker_xe, marker_ys,
191                                          width, marker_ys );
192                         }
193                         else {
194                             drawOneLine( marker_xs, marker_ys, marker_xe, marker_ys );
195                         }
196
197                         if( !huds_notext(options) ) {
198                             disp_val = i;
199                             sprintf( TextScale, "%d",
200                                      FloatToInt(disp_val * data_scaling()/*+.5*/ ));
201
202                             lenstr = getStringWidth( TextScale );
203                                                 
204                             if( huds_left(options) && huds_right(options) ) {
205                                 text_x = mid_scr.x -  lenstr/2 ;
206                             }
207                             else {
208                                 if( huds_left(options) )              {
209                                     text_x = marker_xs - lenstr;
210                                 }
211                                 else {
212                                     text_x = marker_xe - lenstr;
213                                 }
214                             }
215                             // Now we know where to put the text.
216                             text_y = marker_ys;
217                             textString( text_x, text_y, TextScale, GLUT_BITMAP_8_BY_13,0 ); //suma
218                         }
219                     }
220                 }  //
221             }  //
222         }  //
223         // Now that the scale is drawn, we draw in the pointer(s). Since labels
224         // have been drawn, text_x and text_y may be recycled. This is used
225         // with the marker start stops to produce a pointer for each side reading
226
227         text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
228         //    text_x = marker_xs - scrn_rect.left;
229
230         if( huds_right(options) ) {
231             glBegin(GL_LINE_STRIP);
232             glVertex2f( scrn_rect.left, text_y + 5);
233             glVertex2f( marker_xe,      text_y);
234             glVertex2f( scrn_rect.left, text_y - 5);
235             glEnd();
236         }
237         if( huds_left(options) ) {
238             glBegin(GL_LINE_STRIP);
239             glVertex2f( width,      text_y + 5);
240             glVertex2f( marker_xs,  text_y);
241             glVertex2f( width,      text_y - 5);
242             glEnd();
243         }
244     }  // End if VERTICAL SCALE TYPE
245     else {                                // Horizontal scale by default
246         drawOneLine( scrn_rect.left,     // left tick bar
247                      scrn_rect.top,
248                      scrn_rect.left,
249                      height);
250
251         drawOneLine( width,    // right tick bar
252                      scrn_rect.top,
253                      width,
254                      height );
255
256         marker_ys = scrn_rect.top;                       // Starting point for
257         marker_ye = height;                              // tick y location calcs
258         marker_xs = scrn_rect.left + FloatToInt((cur_value - vmin) * factor() /*+ .5f*/);
259
260         if( huds_top(options) ) {
261             drawOneLine( scrn_rect.left,
262                          scrn_rect.top,
263                          width,
264                          scrn_rect.top);                    // Bottom box line
265           
266             marker_ye  = scrn_rect.top + scrn_rect.bottom / 2;   // Tick point adjust
267             // Bottom arrow
268             glBegin(GL_LINE_STRIP);
269             glVertex2f( marker_xs - bottom_4, scrn_rect.top);
270             glVertex2f( marker_xs, marker_ye);
271             glVertex2f( marker_xs + bottom_4, scrn_rect.top);
272             glEnd();
273         }
274         if( huds_bottom(options) ) {
275             // Top box line
276             drawOneLine( scrn_rect.left, height, width, height);
277             // Tick point adjust
278             marker_ys = height - scrn_rect.bottom  / 2;
279
280             // Top arrow
281             glBegin(GL_LINE_STRIP);
282             glVertex2f( marker_xs + bottom_4, height);
283             glVertex2f( marker_xs, marker_ys );
284             glVertex2f( marker_xs - bottom_4, height);
285             glEnd();
286         }
287
288         
289         int last = (int)vmax + 1; //FloatToInt(vmax)+1;
290         i = (int)vmin; //FloatToInt(vmin);
291         for( ; i <last ; i++ )      {
292             condition = true;
293             if( !modulo()) {
294                 if( i < min_val()) {
295                     condition = false;
296                 }
297             }
298             if( condition )        {
299                 marker_xs = scrn_rect.left + FloatToInt((i - vmin) * factor()/* +.5f*/);
300                 //        marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
301                 if( div_min()){
302                     if( !(i%(int)div_min()) ) {                 
303                         // draw in ticks only if they aren't too close to the edge.
304                         if((( marker_xs + 5) > scrn_rect.left ) ||
305                            (( marker_xs - 5 )< (width))){
306
307                             if( huds_both(options) ) {
308                                 drawOneLine( marker_xs, scrn_rect.top,
309                                              marker_xs, marker_ys - 4);
310                                 drawOneLine( marker_xs, marker_ye + 4,
311                                              marker_xs, height);
312                             }
313                             else {
314                                 if( huds_top(options) ) {
315                                     drawOneLine( marker_xs, marker_ys,
316                                                  marker_xs, marker_ye - 4);
317                                 }
318                                 else {
319                                     drawOneLine( marker_xs, marker_ys + 4,
320                                                  marker_xs, marker_ye);
321                                 }
322                             }
323                         }
324                     }
325                 }
326                 if( div_max()) {
327                     if( !(i%(int)div_max()) ) {                 
328                         if(modulo()) {
329                             if( disp_val < 0) {
330                                 while( disp_val < 0 ) {
331                                     disp_val += modulo();
332                                 }       
333                             }
334                             disp_val = i % (int)modulo();
335                         } else {
336                             disp_val = i;
337                         }
338                         sprintf( TextScale, "%d",
339                                  FloatToInt(disp_val  * data_scaling()/* +.5*/ ));
340                         lenstr = getStringWidth( TextScale);
341                                                 
342                         // Draw major ticks and text only if far enough from the edge.
343                         if(( (marker_xs - 10)> scrn_rect.left ) &&
344                            ( (marker_xs + 10) < width )){
345                             if( huds_both(options) ) {
346                                 drawOneLine( marker_xs, scrn_rect.top,
347                                              marker_xs, marker_ys);
348                                 drawOneLine( marker_xs, marker_ye,
349                                              marker_xs, height);
350
351                                 if( !huds_notext(options) ) {
352                                     textString ( marker_xs - lenstr, marker_ys + 4,
353                                                  TextScale,  GLUT_BITMAP_8_BY_13 ,0); //suma
354                                 }
355                             }
356                             else {
357                                 drawOneLine( marker_xs, marker_ys,
358                                              marker_xs, marker_ye );
359                                 
360                                 if( !huds_notext(options) ) {
361                                     if( huds_top(options) )              {
362                                         textString ( marker_xs - lenstr,
363                                                      height - 10,
364                                                      TextScale, GLUT_BITMAP_8_BY_13,0 ); //suma
365                                     }
366                                     else  {
367                                         textString( marker_xs - lenstr, scrn_rect.top,
368                                                     TextScale, GLUT_BITMAP_8_BY_13,0 );  //suma
369                                     }            
370                                 }
371                             }
372                         }
373                     }
374                 }
375             }
376         }
377     }
378 }
379
380