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