]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_tape.cxx
- don't use 10 pt font size for width calculations, when in fact we use
[flightgear.git] / src / Instrumentation / HUD / HUD_tape.cxx
1 // HUD_tape.cxx -- HUD Tape Instrument
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #include "HUD.hxx"
23
24
25 HUD::Tape::Tape(HUD *hud, const SGPropertyNode *n, float x, float y) :
26     Scale(hud, n, x, y),
27     _draw_tick_bottom(n->getBoolValue("tick-bottom", false)),
28     _draw_tick_top(n->getBoolValue("tick-top", false)),
29     _draw_tick_right(n->getBoolValue("tick-right", false)),
30     _draw_tick_left(n->getBoolValue("tick-left", false)),
31     _draw_cap_bottom(n->getBoolValue("cap-bottom", false)),
32     _draw_cap_top(n->getBoolValue("cap-top", false)),
33     _draw_cap_right(n->getBoolValue("cap-right", false)),
34     _draw_cap_left(n->getBoolValue("cap-left", false)),
35     _marker_offset(n->getFloatValue("marker-offset", 0.0)),
36     _pointer(n->getBoolValue("enable-pointer", true)),
37     _zoom(n->getIntValue("zoom"))
38 {
39     _half_width_units = range_to_show() / 2.0;
40
41     const char *s;
42     s = n->getStringValue("pointer-type");
43     _pointer_type = strcmp(s, "moving") ? FIXED : MOVING;    // "fixed", "moving"
44
45     s = n->getStringValue("tick-type");
46     _tick_type = strcmp(s, "circle") ? LINE : CIRCLE;        // "circle", "line"
47
48     s = n->getStringValue("tick-length");                    // "variable", "constant"
49     _tick_length = strcmp(s, "constant") ? VARIABLE : CONSTANT;
50
51     float top;
52     _hud->_font->getBBox("0", _hud->_font_size, 0.0, 0, 0, 0, &top);
53     _0_ht = top / 2.0;  // half 0 height
54 }
55
56
57 void HUD::Tape::draw(void) //  (HUD_scale * pscale)
58 {
59     if (!_input.isValid())
60         return;
61
62     float vmin = 0.0, vmax = 0.0;
63     float marker_xs;
64     float marker_xe;
65     float marker_ys;
66     float marker_ye;
67     float text_x = 0.0, text_y = 0.0;
68     const int BUFSIZE = 80;
69     char buf[BUFSIZE];
70     int oddtype;
71 //    int k; //odd or even values for ticks             // FIXME odd scale
72
73     float cur_value = _input.getFloatValue();
74
75     if (int(floor(_input.max() + 0.5)) & 1)
76         oddtype = 1; //draw ticks at odd values
77     else
78         oddtype = 0; //draw ticks at even values
79
80     float top = _y + _h;
81     float right = _x + _w;
82
83
84     if (_pointer) {
85         if (_pointer_type == MOVING) {
86             vmin = _input.min();
87             vmax = _input.max();
88
89         } else { // FIXED
90             vmin = cur_value - _half_width_units; // width units == needle travel
91             vmax = cur_value + _half_width_units; // or picture unit span.
92             text_x = _center_x;
93             text_y = _center_y;
94         }
95
96     } else {
97         vmin = cur_value - _half_width_units; // width units == needle travel
98         vmax = cur_value + _half_width_units; // or picture unit span.
99         text_x = _center_x;
100         text_y = _center_y;
101     }
102
103
104 ///////////////////////////////////////////////////////////////////////////////
105 // VERTICAL SCALE
106 ///////////////////////////////////////////////////////////////////////////////
107
108     // Draw the basic markings for the scale...
109
110     if (option_vert()) { // Vertical scale
111         // Bottom tick bar
112         if (_draw_tick_bottom)
113             draw_line(_x, _y, right, _y);
114
115         // Top tick bar
116         if (_draw_tick_top)
117             draw_line(_x, top, right, top);
118
119         marker_xs = _x;       // x start
120         marker_xe = right;    // x extent
121         marker_ye = top;
122
123         //    glBegin(GL_LINES);
124
125         // Bottom tick bar
126         //    glVertex2f(marker_xs, _y);
127         //    glVertex2f(marker_xe, _y);
128
129         // Top tick bar
130         //    glVertex2f(marker_xs, marker_ye);
131         //    glVertex2f(marker_xe, marker_ye);
132         //    glEnd();
133
134
135         // We do not use else in the following so that combining the
136         // two options produces a "caged" display with double
137         // carrots. The same is done for horizontal card indicators.
138
139         // begin vertical/left
140         //First draw capping lines and pointers
141         if (option_left()) {    // Calculate x marker offset
142
143             if (_draw_cap_right)
144                 draw_line(marker_xe, _y, marker_xe, marker_ye);
145
146             marker_xs = marker_xe - _w / 3.0;
147
148             // draw_line(marker_xs, _center_y, marker_xe, _center_y + _w / 6);
149             // draw_line(marker_xs, _center_y, marker_xe, _center_y - _w / 6);
150
151             // draw pointer
152             if (_pointer) {
153                 if (_pointer_type == MOVING) {
154                     if (!_zoom) {
155                         //Code for Moving Type Pointer
156                         float ycentre, ypoint, xpoint;
157                         float range, wth;
158
159                         if (_input.min() >= 0.0)
160                             ycentre = _y;
161                         else if (_input.max() + _input.min() == 0.0)
162                             ycentre = _center_y;
163                         else if (oddtype)
164                             ycentre = _y + (1.0 - _input.min()) * _h
165                                     / (_input.max() - _input.min());
166                         else
167                             ycentre = _y + _input.min() * _h
168                                     / (_input.max() - _input.min());
169
170                         range = _h;
171                         wth = _x + _w;
172
173                         if (oddtype)
174                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
175                         else
176                             ypoint = ycentre + (cur_value * range / _val_span);
177
178                         xpoint = wth + _marker_offset;
179                         draw_line(xpoint, ycentre, xpoint, ypoint);
180                         draw_line(xpoint, ypoint, xpoint - _marker_offset, ypoint);
181                         draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint + 5.0);
182                         draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint - 5.0);
183                     } // !_zoom
184
185                 } else {
186                     // default to fixed
187                     fixed(_marker_offset + marker_xe, text_y + _w / 6,
188                             _marker_offset + marker_xs, text_y, _marker_offset + marker_xe,
189                             text_y - _w / 6);
190                 } // end pointer type
191             } // if pointer
192         } // end vertical/left
193
194
195         // begin vertical/right
196         // First draw capping lines and pointers
197         if (option_right()) {
198
199             if (_draw_cap_left)
200                 draw_line(_x, _y, _x, marker_ye);
201
202             marker_xe = _x + _w / 3.0;
203             // Indicator carrot
204             // draw_line(_x, _center_y +  _w / 6, marker_xe, _center_y);
205             // draw_line(_x, _center_y -  _w / 6, marker_xe, _center_y);
206
207             // draw pointer
208             if (_pointer) {
209                 if (_pointer_type == MOVING) {
210                     if (!_zoom) {
211                         // type-fixed & _zoom=1, behaviour to be defined
212                         // Code for Moving Type Pointer
213                         float ycentre, ypoint, xpoint;
214                         float range;
215
216                         if (_input.min() >= 0.0)
217                             ycentre = _y;
218                         else if (_input.max() + _input.min() == 0.0)
219                             ycentre = _center_y;
220                         else if (oddtype)
221                             ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
222                         else
223                             ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
224
225                         range = _h;
226
227                         if (oddtype)
228                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
229                         else
230                             ypoint = ycentre + (cur_value * range / _val_span);
231
232                         xpoint = _x - _marker_offset;
233                         draw_line(xpoint, ycentre, xpoint, ypoint);
234                         draw_line(xpoint, ypoint, xpoint + _marker_offset, ypoint);
235                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint + 5.0);
236                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint - 5.0);
237                     }
238
239                 } else {
240                     // default to fixed
241                     fixed(-_marker_offset + _x, text_y +  _w / 6,
242                             -_marker_offset + marker_xe, text_y, -_marker_offset + _x,
243                             text_y - _w / 6);
244                 }
245             } // if pointer
246         } // end vertical/right
247
248
249         // At this point marker x_start and x_end values are transposed.
250         // To keep this from confusing things they are now swapped.
251         if (option_both())
252             marker_ye = marker_xs, marker_xs = marker_xe, marker_xe = marker_ye;
253
254
255
256         // Work through from bottom to top of scale. Calculating where to put
257         // minor and major ticks.
258
259         // draw scale or tape
260         if (_zoom) {
261             zoomed_scale((int)vmin, (int)vmax);
262         } else {
263
264             int div_ratio;
265             if (_minor_divs != 0.0f)
266                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
267             else
268                 div_ratio = 0, _minor_divs = _major_divs;               // FIXME move that into Scale/Constructor ?
269
270             float vstart = floorf(vmin / _major_divs) * _major_divs;
271             float min_diff = _w / 6.0;    // length difference between major & minor tick
272
273             // FIXME consider oddtype
274             for (int i = 0; ; i++) {
275                 float v = vstart + i * _minor_divs;
276
277                 if (!_modulo && (v < _input.min() || v > _input.max()))
278                     continue;
279
280                 float y = _y + (v - vmin) * factor();
281
282                 if (y < _y + 4)
283                     continue;
284                 if (y > top - 4)
285                     break;
286
287                 if (div_ratio && i % div_ratio) { // minor div
288                     if (option_both()) {
289                         if (_tick_type == LINE) {
290                             if (_tick_length == VARIABLE) {
291                                 draw_line(_x, y, marker_xs, y);
292                                 draw_line(marker_xe, y, right, y);
293                             } else {
294                                 draw_line(_x, y, marker_xs, y);
295                                 draw_line(marker_xe, y, right, y);
296                             }
297
298                         } else { // _tick_type == CIRCLE
299                             draw_bullet(_x, y, 3.0);
300                         }
301
302                         // glBegin(GL_LINES);
303                         // glVertex2f(_x, y);
304                         // glVertex2f(marker_xs,      y);
305                         // glVertex2f(marker_xe,      y);
306                         // glVertex2f(_x + _w,  y);
307                         // glEnd();
308                         // anything other than huds_both
309
310                     } else if (option_left()) {
311                         if (_tick_type == LINE) {
312                             if (_tick_length == VARIABLE) {
313                                 draw_line(marker_xs + min_diff, y, marker_xe, y);
314                             } else {
315                                 draw_line(marker_xs, y, marker_xe, y);
316                             }
317                         } else { // _tick_type == CIRCLE
318                             draw_bullet(marker_xs + 4, y, 3.0);
319                         }
320
321                     } else { // if (option_right())
322                         if (_tick_type == LINE) {
323                             if (_tick_length == VARIABLE) {
324                                 draw_line(marker_xs, y, marker_xe - min_diff, y);
325                             } else {
326                                 draw_line(marker_xs, y, marker_xe, y);
327                             }
328
329                         } else { // _tick_type == CIRCLE
330                             draw_bullet(marker_xe - 4, y, 3.0);
331                         }
332                     } // end huds both
333
334                 } else { // major div
335                     int display_value = int(v);
336                     if (_modulo)
337                         display_value %= _modulo;
338
339                     snprintf(buf, BUFSIZE, "%d", display_value);
340                     float strwd = text_width(buf);
341
342                     if (option_both()) {
343                         // draw_line(_x, y, marker_xs, y);
344                         // draw_line(marker_xs, y, _x + _w, y);
345                         if (_tick_type == LINE) {
346                             glBegin(GL_LINE_STRIP);
347                             glVertex2f(_x, y);
348                             glVertex2f(marker_xs, y);
349                             glVertex2f(right, y);
350                             glEnd();
351
352                         } else { // _tick_type == CIRCLE
353                             draw_bullet(_x, y, 5.0);
354                         }
355
356                         if (!option_notext())
357                             draw_text(marker_xs + 2, y - _0_ht, buf, 0);
358
359                     } else {
360                         if (_tick_type == LINE)
361                             draw_line(marker_xs, y, marker_xe, y);
362                         else // _tick_type == CIRCLE
363                             draw_bullet(marker_xs + 4, y, 5.0);
364
365                         if (!option_notext()) {
366                             if (option_left())
367                                 draw_text(marker_xs - strwd, y - _0_ht, buf, 0);
368                             else
369                                 draw_text(marker_xe + strwd / 2, y - _0_ht, buf, 0);
370                         }
371                     } // End if huds-both
372                 }
373             }
374         } // end of zoom
375
376
377 ///////////////////////////////////////////////////////////////////////////////
378 // HORIZONTAL SCALE
379 ///////////////////////////////////////////////////////////////////////////////
380
381
382     } else {
383         // left tick bar
384         if (_draw_tick_left)
385             draw_line(_x, _y, _x, top);
386
387         // right tick bar
388         if (_draw_tick_right)
389             draw_line(right, _y, right, top);
390
391         marker_ys = _y;    // Starting point for
392         marker_ye = top;           // tick y location calcs
393         marker_xe = right;
394         marker_xs = _x + ((cur_value - vmin) * factor());
395
396         //    glBegin(GL_LINES);
397         // left tick bar
398         //    glVertex2f(_x, _y);
399         //    glVertex2f(_x, marker_ye);
400
401         // right tick bar
402         //    glVertex2f(marker_xe, _y);
403         //    glVertex2f(marker_xe, marker_ye);
404         //    glEnd();
405
406         if (option_top()) {
407             if (_draw_cap_bottom)
408                 draw_line(_x, _y, right, _y);
409
410             // Tick point adjust
411             marker_ye  = _y + _h / 2;
412             // Bottom arrow
413             // draw_line(_center_x, marker_ye, _center_x - _h / 4, _y);
414             // draw_line(_center_x, marker_ye, _center_x + _h / 4, _y);
415             // draw pointer
416             if (_pointer) {
417                 if (_pointer_type == MOVING) {
418                     if (!_zoom) {
419                         //Code for Moving Type Pointer
420
421                         float xcentre = _center_x;
422                         float range = _w;
423                         float xpoint = xcentre + (cur_value * range / _val_span);
424                         float ypoint = _y - _marker_offset;
425                         draw_line(xcentre, ypoint, xpoint, ypoint);
426                         draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
427                         draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
428                         draw_line(xpoint, ypoint + _marker_offset, xpoint - 5.0, ypoint + 5.0);
429                     }
430
431                 } else {
432                     //default to fixed
433                     fixed(marker_xs - _h / 4, _y, marker_xs,
434                             marker_ye, marker_xs + _h / 4, _y);
435                 }
436             }
437         } // End Horizontal scale/top
438
439         if (option_bottom()) {
440             if (_draw_cap_top)
441                 draw_line(_x, top, right, top);
442
443             // Tick point adjust
444             marker_ys = top - _h / 2;
445             // Top arrow
446             // draw_line(_center_x + _h / 4, _y + _h, _center_x, marker_ys);
447             // draw_line(_center_x - _h / 4, _y + _h, _center_x , marker_ys);
448
449             // draw pointer
450             if (_pointer) {
451                 if (_pointer_type == MOVING) {
452                     if (!_zoom) {
453                         //Code for Moving Type Pointer
454
455                         float xcentre = _center_x;
456                         float range = _w;
457                         float hgt = _y + _h;
458                         float xpoint = xcentre + (cur_value * range / _val_span);
459                         float ypoint = hgt + _marker_offset;
460                         draw_line(xcentre, ypoint, xpoint, ypoint);
461                         draw_line(xpoint, ypoint, xpoint, ypoint - _marker_offset);
462                         draw_line(xpoint, ypoint - _marker_offset, xpoint + 5.0, ypoint - 5.0);
463                         draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
464                     }
465                 } else {
466                     fixed(marker_xs + _h / 4, top, marker_xs, marker_ys,
467                             marker_xs - _h / 4, top);
468                 }
469             }
470         } //end horizontal scale bottom
471
472
473         if (_zoom) {
474             zoomed_scale((int)vmin,(int)vmax);
475         } else {
476             int div_ratio;                                      // FIXME abstract that out of hor/vert
477             if (_minor_divs != 0.0f)
478                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
479             else
480                 div_ratio = 0, _minor_divs = _major_divs;                       // FIXME move that into Scale/Constructor ?
481
482             float vstart = floorf(vmin / _major_divs) * _major_divs;
483             float min_diff = _h / 6.0;    // length difference between major & minor tick
484
485             // FIXME consider oddtype
486             for (int i = 0; ; i++) {
487                 float v = vstart + i * _minor_divs;
488
489                 if (!_modulo && (v < _input.min() || v > _input.max()))
490                     continue;
491
492                 float x = _x + (v - vmin) * factor();
493
494                 if (x < _x + 4)
495                     continue;
496                 if (x > right - 4)
497                     break;
498
499                 if (div_ratio && i % div_ratio) { // minor div
500                     if (option_both()) {
501                         if (_tick_length == VARIABLE) {
502                             draw_line(x, _y, x, marker_ys - 4);
503                             draw_line(x, marker_ye + 4, x, top);
504                         } else {
505                             draw_line(x, _y, x, marker_ys);
506                             draw_line(x, marker_ye, x, top);
507                         }
508                         // glBegin(GL_LINES);
509                         // glVertex2f(x, _y);
510                         // glVertex2f(x, marker_ys - 4);
511                         // glVertex2f(x, marker_ye + 4);
512                         // glVertex2f(x, _y + _h);
513                         // glEnd();
514
515                     } else {
516                         if (option_top()) {
517                             // draw minor ticks
518                             if (_tick_length == VARIABLE)
519                                 draw_line(x, marker_ys, x, marker_ye - min_diff);
520                             else
521                                 draw_line(x, marker_ys, x, marker_ye);
522
523                         } else if (_tick_length == VARIABLE) {
524                             draw_line(x, marker_ys + 4, x, marker_ye);
525                         } else {
526                             draw_line(x, marker_ys, x, marker_ye);
527                         }
528                     }
529
530                 } else { // major divs
531                     int display_value = int(v);
532                     if (_modulo)
533                         display_value %= _modulo;
534
535                     snprintf(buf, BUFSIZE, "%d", display_value);
536                     float strwd = text_width(buf);
537
538                     // Draw major ticks and text only if far enough from the edge.                      // FIXME
539                     if (x < _x + 10 || x + 10 > _x + _w)
540                         continue;
541
542                     if (option_both()) {
543                         // draw_line(x, _y,
544                         //              x, marker_ys);
545                         // draw_line(x, marker_ye,
546                         //              x, _y + _h);
547                         glBegin(GL_LINE_STRIP);
548                         glVertex2f(x, _y);
549                         glVertex2f(x, marker_ye);
550                         glVertex2f(x, top);
551                         glEnd();
552
553                         if (!option_notext())
554                             draw_text(x - strwd / 2.0, marker_ys + 4, buf, 0);
555
556                     } else {
557                         draw_line(x, marker_ys, x, marker_ye);
558
559                         if (!option_notext()) {
560                             if (option_top())
561                                 draw_text(x - strwd / 2.0, top - 10, buf, 0);
562                             else
563                                 draw_text(x - strwd / 2.0, _y, buf, 0);
564                         }
565                     }
566                 }
567             } // end for
568         } // end zoom
569     } // end horizontal/vertical scale
570 }
571
572
573
574 void HUD::Tape::fixed(float x1, float y1, float x2, float y2, float x3, float y3)
575 {
576     glBegin(GL_LINE_STRIP);
577     glVertex2f(x1, y1);
578     glVertex2f(x2, y2);
579     glVertex2f(x3, y3);
580     glEnd();
581 }
582
583
584 void HUD::Tape::zoomed_scale(int first, int last)
585 {
586     const int BUFSIZE = 80;
587     char buf[BUFSIZE];
588     int data[80];
589
590     float x, y, w, h, bottom;
591     float cur_value = _input.getFloatValue();
592     int a = 0;
593
594     while (first <= last) {
595         if ((first % (int)_major_divs) == 0) {
596             data[a] = first;
597             a++;
598         }
599         first++;
600     }
601     int centre = a / 2;
602
603     if (option_vert()) {
604         x = _x;
605         y = _y;
606         w = _x + _w;
607         h = _y + _h;
608         bottom = _h;
609
610         float xstart, yfirst, ycentre, ysecond;
611
612         float hgt = bottom * 20.0 / 100.0;  // 60% of height should be zoomed
613         yfirst = _center_y - hgt;
614         ycentre = _center_y;
615         ysecond = _center_y + hgt;
616         float range = hgt * 2;
617
618         int i;
619         float factor = range / 10.0;
620
621         float hgt1 = bottom * 30.0 / 100.0;
622         int  incrs = int((_val_span - _major_divs * 2.0) / _major_divs);
623         int  incr = incrs / 2;
624         float factors = hgt1 / incr;
625
626         // begin
627         //this is for moving type pointer
628         static float ycent, ypoint, xpoint;                                     // FIXME really static?
629         static float wth;
630
631         ycent = _center_y;
632         wth = _x + _w;
633
634         if (cur_value <= data[centre + 1])
635             if (cur_value > data[centre]) {
636                 ypoint = ycent + ((cur_value - data[centre]) * hgt / _major_divs);
637             }
638
639         if (cur_value >= data[centre - 1])
640             if (cur_value <= data[centre]) {
641                 ypoint = ycent - ((data[centre] - cur_value) * hgt / _major_divs);
642             }
643
644         if (cur_value < data[centre - 1])
645             if (cur_value >= _input.min()) {
646                 float diff  = _input.min() - data[centre - 1];
647                 float diff1 = cur_value - data[centre - 1];
648                 float val = (diff1 * hgt1) / diff;
649
650                 ypoint = ycent - hgt - val;
651             }
652
653         if (cur_value > data[centre + 1])
654             if (cur_value <= _input.max()) {
655                 float diff  = _input.max() - data[centre + 1];
656                 float diff1 = cur_value - data[centre + 1];
657                 float val = (diff1 * hgt1) / diff;
658
659                 ypoint = ycent + hgt + val;
660             }
661
662         if (option_left()) {
663             xstart = w;
664
665             draw_line(xstart, ycentre, xstart - 5.0, ycentre); //centre tick
666
667             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes not sense at all
668
669             if (!option_notext())
670                 draw_text(x, ycentre, buf, 0);
671
672             for (i = 1; i < 5; i++) {
673                 yfirst += factor;
674                 ycentre += factor;
675                 draw_bullet(xstart - 2.5, yfirst, 3.0);
676                 draw_bullet(xstart - 2.5, ycentre, 3.0);
677             }
678
679             yfirst = _center_y - hgt;
680
681             for (i = 0; i <= incr; i++) {
682                 draw_line(xstart, yfirst, xstart - 5.0, yfirst);
683                 draw_line(xstart, ysecond, xstart - 5.0, ysecond);
684
685                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor()));  // was data_scaling() ... makes no sense at all
686
687                 if (!option_notext())
688                     draw_text(x, yfirst, buf, 0);
689
690                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
691
692                 if (!option_notext())
693                     draw_text(x, ysecond, buf, 0);
694
695                 yfirst -= factors;
696                 ysecond += factors;
697
698             }
699
700             //to draw moving type pointer for left option
701             //begin
702             xpoint = wth + 10.0;
703
704             if (_pointer_type == MOVING) {
705                 draw_line(xpoint, ycent, xpoint, ypoint);
706                 draw_line(xpoint, ypoint, xpoint - 10.0, ypoint);
707                 draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint + 5.0);
708                 draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint - 5.0);
709             }
710             //end
711
712         } else {
713             //option_right
714             xstart = (x + w) / 2;
715
716             draw_line(xstart, ycentre, xstart + 5.0, ycentre); //centre tick
717
718             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
719
720             if (!option_notext())
721                 draw_text(w, ycentre, buf, 0);
722
723             for (i = 1; i < 5; i++) {
724                 yfirst += factor;
725                 ycentre += factor;
726                 draw_bullet(xstart + 2.5, yfirst, 3.0);
727                 draw_bullet(xstart + 2.5, ycentre, 3.0);
728             }
729
730             yfirst = _center_y - hgt;
731
732             for (i = 0; i <= incr; i++) {
733                 draw_line(xstart, yfirst, xstart + 5.0, yfirst);
734                 draw_line(xstart, ysecond, xstart + 5.0, ysecond);
735
736                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
737
738                 if (!option_notext())
739                     draw_text(w, yfirst, buf, 0);
740
741                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor()));
742
743                 if (!option_notext())
744                     draw_text(w, ysecond, buf, 0);
745
746                 yfirst -= factors;
747                 ysecond += factors;
748
749             }
750
751             // to draw moving type pointer for right option
752             //begin
753             xpoint = _x;
754
755             if (_pointer_type == MOVING) {
756                 draw_line(xpoint, ycent, xpoint, ypoint);
757                 draw_line(xpoint, ypoint, xpoint + 10.0, ypoint);
758                 draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint + 5.0);
759                 draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint - 5.0);
760             }
761             //end
762         }//end option_right /left
763         //end of vertical scale
764
765     } else {
766         //horizontal scale
767         x = _x;
768         y = _y;
769         w = _x + _w;
770         h = _y + _h;
771         bottom = _w;
772
773         float ystart, xfirst, xcentre, xsecond;
774
775         float hgt = bottom * 20.0 / 100.0;  // 60% of height should be zoomed
776         xfirst = _center_x - hgt;
777         xcentre = _center_x;
778         xsecond = _center_x + hgt;
779         float range = hgt * 2;
780
781         int i;
782         float factor = range / 10.0;
783
784         float hgt1 = bottom * 30.0 / 100.0;
785         int  incrs = int((_val_span - _major_divs * 2.0) / _major_divs);
786         int  incr = incrs / 2;
787         float factors = hgt1 / incr;
788
789
790         //Code for Moving Type Pointer
791         //begin
792         static float xcent, xpoint, ypoint;                             // FIXME really static?
793
794         xcent = _center_x;
795
796         if (cur_value <= data[centre + 1])
797             if (cur_value > data[centre]) {
798                 xpoint = xcent + ((cur_value - data[centre]) * hgt / _major_divs);
799             }
800
801         if (cur_value >= data[centre - 1])
802             if (cur_value <= data[centre]) {
803                 xpoint = xcent - ((data[centre] - cur_value) * hgt / _major_divs);
804             }
805
806         if (cur_value < data[centre - 1])
807             if (cur_value >= _input.min()) {
808                 float diff = _input.min() - data[centre - 1];
809                 float diff1 = cur_value - data[centre - 1];
810                 float val = (diff1 * hgt1) / diff;
811
812                 xpoint = xcent - hgt - val;
813             }
814
815
816         if (cur_value > data[centre + 1])
817             if (cur_value <= _input.max()) {
818                 float diff = _input.max() - data[centre + 1];
819                 float diff1 = cur_value - data[centre + 1];
820                 float val = (diff1 * hgt1) / diff;
821
822                 xpoint = xcent + hgt + val;
823             }
824
825         //end
826         if (option_top()) {
827             ystart = h;
828             draw_line(xcentre, ystart, xcentre, ystart - 5.0); //centre tick
829
830             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor()));  // was data_scaling() ... makes no sense at all
831
832             if (!option_notext())
833                 draw_text(xcentre - 10.0, y, buf, 0);
834
835             for (i = 1; i < 5; i++) {
836                 xfirst += factor;
837                 xcentre += factor;
838                 draw_bullet(xfirst, ystart - 2.5, 3.0);
839                 draw_bullet(xcentre, ystart - 2.5, 3.0);
840             }
841
842             xfirst = _center_x - hgt;
843
844             for (i = 0; i <= incr; i++) {
845                 draw_line(xfirst, ystart, xfirst,  ystart - 5.0);
846                 draw_line(xsecond, ystart, xsecond, ystart - 5.0);
847
848                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
849
850                 if (!option_notext())
851                     draw_text(xfirst - 10.0, y, buf, 0);
852
853                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
854
855                 if (!option_notext())
856                     draw_text(xsecond - 10.0, y, buf, 0);
857
858
859                 xfirst -= factors;
860                 xsecond += factors;
861             }
862             //this is for moving pointer for top option
863             //begin
864
865             ypoint = _y + _h + 10.0;
866
867             if (_pointer_type == MOVING) {
868                 draw_line(xcent, ypoint, xpoint, ypoint);
869                 draw_line(xpoint, ypoint, xpoint, ypoint - 10.0);
870                 draw_line(xpoint, ypoint - 10.0, xpoint + 5.0, ypoint - 5.0);
871                 draw_line(xpoint, ypoint - 10.0, xpoint - 5.0, ypoint - 5.0);
872             }
873             //end of top option
874
875         } else {
876             //else option_bottom
877             ystart = (y + h) / 2;
878
879             //draw_line(xstart, yfirst,  xstart - 5.0, yfirst);
880             draw_line(xcentre, ystart, xcentre, ystart + 5.0); //centre tick
881
882             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
883
884             if (!option_notext())
885                 draw_text(xcentre - 10.0, h, buf, 0);
886
887             for (i = 1; i < 5; i++) {
888                 xfirst += factor;
889                 xcentre += factor;
890                 draw_bullet(xfirst, ystart + 2.5, 3.0);
891                 draw_bullet(xcentre, ystart + 2.5, 3.0);
892             }
893
894             xfirst = _center_x - hgt;
895
896             for (i = 0; i <= incr; i++) {
897                 draw_line(xfirst, ystart, xfirst, ystart + 5.0);
898                 draw_line(xsecond, ystart, xsecond, ystart + 5.0);
899
900                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
901
902                 if (!option_notext())
903                     draw_text(xfirst - 10.0, h, buf, 0);
904
905                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
906
907                 if (!option_notext())
908                     draw_text(xsecond - 10.0, h, buf, 0);
909
910                 xfirst -= factors;
911                 xsecond   += factors;
912             }
913             //this is for movimg pointer for bottom option
914             //begin
915
916             ypoint = _y - 10.0;
917             if (_pointer_type == MOVING) {
918                 draw_line(xcent, ypoint, xpoint, ypoint);
919                 draw_line(xpoint, ypoint, xpoint, ypoint + 10.0);
920                 draw_line(xpoint, ypoint + 10.0, xpoint + 5.0, ypoint + 5.0);
921                 draw_line(xpoint, ypoint + 10.0, xpoint - 5.0, ypoint + 5.0);
922             }
923         }//end hud_top or hud_bottom
924     }  //end of horizontal/vertical scales
925 }//end draw
926
927