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