]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_tape.cxx
- move HUDText constructor/methods to HUD.cxx
[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)
278                     if (v < _input.min())
279                         continue;
280                     else if (v > _input.max())
281                         break;
282
283                 float y = _y + (v - vmin) * factor();
284
285                 if (y < _y + 4)
286                     continue;
287                 if (y > top - 4)
288                     break;
289
290                 if (div_ratio && i % div_ratio) { // minor div
291                     if (option_both()) {
292                         if (_tick_type == LINE) {
293                             if (_tick_length == VARIABLE) {
294                                 draw_line(_x, y, marker_xs, y);
295                                 draw_line(marker_xe, y, right, y);
296                             } else {
297                                 draw_line(_x, y, marker_xs, y);
298                                 draw_line(marker_xe, y, right, y);
299                             }
300
301                         } else { // _tick_type == CIRCLE
302                             draw_bullet(_x, y, 3.0);
303                         }
304
305                         // glBegin(GL_LINES);
306                         // glVertex2f(_x, y);
307                         // glVertex2f(marker_xs,      y);
308                         // glVertex2f(marker_xe,      y);
309                         // glVertex2f(_x + _w,  y);
310                         // glEnd();
311                         // anything other than huds_both
312
313                     } else if (option_left()) {
314                         if (_tick_type == LINE) {
315                             if (_tick_length == VARIABLE) {
316                                 draw_line(marker_xs + min_diff, y, marker_xe, y);
317                             } else {
318                                 draw_line(marker_xs, y, marker_xe, y);
319                             }
320                         } else { // _tick_type == CIRCLE
321                             draw_bullet(marker_xs + 4, y, 3.0);
322                         }
323
324                     } else { // if (option_right())
325                         if (_tick_type == LINE) {
326                             if (_tick_length == VARIABLE) {
327                                 draw_line(marker_xs, y, marker_xe - min_diff, y);
328                             } else {
329                                 draw_line(marker_xs, y, marker_xe, y);
330                             }
331
332                         } else { // _tick_type == CIRCLE
333                             draw_bullet(marker_xe - 4, y, 3.0);
334                         }
335                     } // end huds both
336
337                 } else { // major div
338                     int display_value = int(v);
339                     if (_modulo)
340                         display_value %= _modulo;
341
342                     snprintf(buf, BUFSIZE, "%d", display_value);
343                     float strwd = text_width(buf);
344
345                     if (option_both()) {
346                         // draw_line(_x, y, marker_xs, y);
347                         // draw_line(marker_xs, y, _x + _w, y);
348                         if (_tick_type == LINE) {
349                             glBegin(GL_LINE_STRIP);
350                             glVertex2f(_x, y);
351                             glVertex2f(marker_xs, y);
352                             glVertex2f(right, y);
353                             glEnd();
354
355                         } else { // _tick_type == CIRCLE
356                             draw_bullet(_x, y, 5.0);
357                         }
358
359                         if (!option_notext())
360                             draw_text(marker_xs + 2, y - _0_ht, buf, 0);
361
362                     } else {
363                         if (_tick_type == LINE)
364                             draw_line(marker_xs, y, marker_xe, y);
365                         else // _tick_type == CIRCLE
366                             draw_bullet(marker_xs + 4, y, 5.0);
367
368                         if (!option_notext()) {
369                             if (option_left())
370                                 draw_text(marker_xs - strwd, y - _0_ht, buf, 0);
371                             else
372                                 draw_text(marker_xe + strwd / 2, y - _0_ht, buf, 0);
373                         }
374                     } // End if huds-both
375                 }
376             }
377         } // end of zoom
378
379
380 ///////////////////////////////////////////////////////////////////////////////
381 // HORIZONTAL SCALE
382 ///////////////////////////////////////////////////////////////////////////////
383
384
385     } else {
386         // left tick bar
387         if (_draw_tick_left)
388             draw_line(_x, _y, _x, top);
389
390         // right tick bar
391         if (_draw_tick_right)
392             draw_line(right, _y, right, top);
393
394         marker_ys = _y;    // Starting point for
395         marker_ye = top;           // tick y location calcs
396         marker_xe = right;
397         marker_xs = _x + ((cur_value - vmin) * factor());
398
399         //    glBegin(GL_LINES);
400         // left tick bar
401         //    glVertex2f(_x, _y);
402         //    glVertex2f(_x, marker_ye);
403
404         // right tick bar
405         //    glVertex2f(marker_xe, _y);
406         //    glVertex2f(marker_xe, marker_ye);
407         //    glEnd();
408
409         if (option_top()) {
410             if (_draw_cap_bottom)
411                 draw_line(_x, _y, right, _y);
412
413             // Tick point adjust
414             marker_ye  = _y + _h / 2;
415             // Bottom arrow
416             // draw_line(_center_x, marker_ye, _center_x - _h / 4, _y);
417             // draw_line(_center_x, marker_ye, _center_x + _h / 4, _y);
418             // draw pointer
419             if (_pointer) {
420                 if (_pointer_type == MOVING) {
421                     if (!_zoom) {
422                         //Code for Moving Type Pointer
423
424                         float xcentre = _center_x;
425                         float range = _w;
426                         float xpoint = xcentre + (cur_value * range / _val_span);
427                         float ypoint = _y - _marker_offset;
428                         draw_line(xcentre, ypoint, xpoint, ypoint);
429                         draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
430                         draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
431                         draw_line(xpoint, ypoint + _marker_offset, xpoint - 5.0, ypoint + 5.0);
432                     }
433
434                 } else {
435                     //default to fixed
436                     fixed(marker_xs - _h / 4, _y, marker_xs,
437                             marker_ye, marker_xs + _h / 4, _y);
438                 }
439             }
440         } // End Horizontal scale/top
441
442         if (option_bottom()) {
443             if (_draw_cap_top)
444                 draw_line(_x, top, right, top);
445
446             // Tick point adjust
447             marker_ys = top - _h / 2;
448             // Top arrow
449             // draw_line(_center_x + _h / 4, _y + _h, _center_x, marker_ys);
450             // draw_line(_center_x - _h / 4, _y + _h, _center_x , marker_ys);
451
452             // draw pointer
453             if (_pointer) {
454                 if (_pointer_type == MOVING) {
455                     if (!_zoom) {
456                         //Code for Moving Type Pointer
457
458                         float xcentre = _center_x;
459                         float range = _w;
460                         float hgt = _y + _h;
461                         float xpoint = xcentre + (cur_value * range / _val_span);
462                         float ypoint = hgt + _marker_offset;
463                         draw_line(xcentre, ypoint, xpoint, ypoint);
464                         draw_line(xpoint, ypoint, xpoint, ypoint - _marker_offset);
465                         draw_line(xpoint, ypoint - _marker_offset, xpoint + 5.0, ypoint - 5.0);
466                         draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
467                     }
468                 } else {
469                     fixed(marker_xs + _h / 4, top, marker_xs, marker_ys,
470                             marker_xs - _h / 4, top);
471                 }
472             }
473         } //end horizontal scale bottom
474
475
476         if (_zoom) {
477             zoomed_scale((int)vmin,(int)vmax);
478         } else {
479             int div_ratio;                                      // FIXME abstract that out of hor/vert
480             if (_minor_divs != 0.0f)
481                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
482             else
483                 div_ratio = 0, _minor_divs = _major_divs;                       // FIXME move that into Scale/Constructor ?
484
485             float vstart = floorf(vmin / _major_divs) * _major_divs;
486             float min_diff = _h / 6.0;    // length difference between major & minor tick
487
488             // FIXME consider oddtype
489             for (int i = 0; ; i++) {
490                 float v = vstart + i * _minor_divs;
491
492                 if (!_modulo)
493                     if (v < _input.min())
494                         continue;
495                     else if (v > _input.max())
496                         break;
497
498                 float x = _x + (v - vmin) * factor();
499
500                 if (x < _x + 4)
501                     continue;
502                 if (x > right - 4)
503                     break;
504
505                 if (div_ratio && i % div_ratio) { // minor div
506                     if (option_both()) {
507                         if (_tick_length == VARIABLE) {
508                             draw_line(x, _y, x, marker_ys - 4);
509                             draw_line(x, marker_ye + 4, x, top);
510                         } else {
511                             draw_line(x, _y, x, marker_ys);
512                             draw_line(x, marker_ye, x, top);
513                         }
514                         // glBegin(GL_LINES);
515                         // glVertex2f(x, _y);
516                         // glVertex2f(x, marker_ys - 4);
517                         // glVertex2f(x, marker_ye + 4);
518                         // glVertex2f(x, _y + _h);
519                         // glEnd();
520
521                     } else {
522                         if (option_top()) {
523                             // draw minor ticks
524                             if (_tick_length == VARIABLE)
525                                 draw_line(x, marker_ys, x, marker_ye - min_diff);
526                             else
527                                 draw_line(x, marker_ys, x, marker_ye);
528
529                         } else if (_tick_length == VARIABLE) {
530                             draw_line(x, marker_ys + 4, x, marker_ye);
531                         } else {
532                             draw_line(x, marker_ys, x, marker_ye);
533                         }
534                     }
535
536                 } else { // major divs
537                     int display_value = int(v);
538                     if (_modulo)
539                         display_value %= _modulo;
540
541                     snprintf(buf, BUFSIZE, "%d", display_value);
542                     float strwd = text_width(buf);
543
544                     // Draw major ticks and text only if far enough from the edge.                      // FIXME
545                     if (x < _x + 10 || x + 10 > _x + _w)
546                         continue;
547
548                     if (option_both()) {
549                         // draw_line(x, _y,
550                         //              x, marker_ys);
551                         // draw_line(x, marker_ye,
552                         //              x, _y + _h);
553                         glBegin(GL_LINE_STRIP);
554                         glVertex2f(x, _y);
555                         glVertex2f(x, marker_ye);
556                         glVertex2f(x, top);
557                         glEnd();
558
559                         if (!option_notext())
560                             draw_text(x - strwd / 2.0, marker_ys + 4, buf, 0);
561
562                     } else {
563                         draw_line(x, marker_ys, x, marker_ye);
564
565                         if (!option_notext()) {
566                             if (option_top())
567                                 draw_text(x - strwd / 2.0, top - 10, buf, 0);
568                             else
569                                 draw_text(x - strwd / 2.0, _y, buf, 0);
570                         }
571                     }
572                 }
573             } // end for
574         } // end zoom
575     } // end horizontal/vertical scale
576 }
577
578
579
580 void HUD::Tape::fixed(float x1, float y1, float x2, float y2, float x3, float y3)
581 {
582     glBegin(GL_LINE_STRIP);
583     glVertex2f(x1, y1);
584     glVertex2f(x2, y2);
585     glVertex2f(x3, y3);
586     glEnd();
587 }
588
589
590 void HUD::Tape::zoomed_scale(int first, int last)
591 {
592     const int BUFSIZE = 80;
593     char buf[BUFSIZE];
594     int data[80];
595
596     float x, y, w, h, bottom;
597     float cur_value = _input.getFloatValue();
598     int a = 0;
599
600     while (first <= last) {
601         if ((first % (int)_major_divs) == 0) {
602             data[a] = first;
603             a++;
604         }
605         first++;
606     }
607     int centre = a / 2;
608
609     if (option_vert()) {
610         x = _x;
611         y = _y;
612         w = _x + _w;
613         h = _y + _h;
614         bottom = _h;
615
616         float xstart, yfirst, ycentre, ysecond;
617
618         float hgt = bottom * 20.0 / 100.0;  // 60% of height should be zoomed
619         yfirst = _center_y - hgt;
620         ycentre = _center_y;
621         ysecond = _center_y + hgt;
622         float range = hgt * 2;
623
624         int i;
625         float factor = range / 10.0;
626
627         float hgt1 = bottom * 30.0 / 100.0;
628         int  incrs = int((_val_span - _major_divs * 2.0) / _major_divs);
629         int  incr = incrs / 2;
630         float factors = hgt1 / incr;
631
632         // begin
633         //this is for moving type pointer
634         static float ycent, ypoint, xpoint;                                     // FIXME really static?
635         static float wth;
636
637         ycent = _center_y;
638         wth = _x + _w;
639
640         if (cur_value <= data[centre + 1])
641             if (cur_value > data[centre]) {
642                 ypoint = ycent + ((cur_value - data[centre]) * hgt / _major_divs);
643             }
644
645         if (cur_value >= data[centre - 1])
646             if (cur_value <= data[centre]) {
647                 ypoint = ycent - ((data[centre] - cur_value) * hgt / _major_divs);
648             }
649
650         if (cur_value < data[centre - 1])
651             if (cur_value >= _input.min()) {
652                 float diff  = _input.min() - data[centre - 1];
653                 float diff1 = cur_value - data[centre - 1];
654                 float val = (diff1 * hgt1) / diff;
655
656                 ypoint = ycent - hgt - val;
657             }
658
659         if (cur_value > data[centre + 1])
660             if (cur_value <= _input.max()) {
661                 float diff  = _input.max() - data[centre + 1];
662                 float diff1 = cur_value - data[centre + 1];
663                 float val = (diff1 * hgt1) / diff;
664
665                 ypoint = ycent + hgt + val;
666             }
667
668         if (option_left()) {
669             xstart = w;
670
671             draw_line(xstart, ycentre, xstart - 5.0, ycentre); //centre tick
672
673             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes not sense at all
674
675             if (!option_notext())
676                 draw_text(x, ycentre, buf, 0);
677
678             for (i = 1; i < 5; i++) {
679                 yfirst += factor;
680                 ycentre += factor;
681                 draw_bullet(xstart - 2.5, yfirst, 3.0);
682                 draw_bullet(xstart - 2.5, ycentre, 3.0);
683             }
684
685             yfirst = _center_y - hgt;
686
687             for (i = 0; i <= incr; i++) {
688                 draw_line(xstart, yfirst, xstart - 5.0, yfirst);
689                 draw_line(xstart, ysecond, xstart - 5.0, ysecond);
690
691                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor()));  // was data_scaling() ... makes no sense at all
692
693                 if (!option_notext())
694                     draw_text(x, yfirst, buf, 0);
695
696                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
697
698                 if (!option_notext())
699                     draw_text(x, ysecond, buf, 0);
700
701                 yfirst -= factors;
702                 ysecond += factors;
703
704             }
705
706             //to draw moving type pointer for left option
707             //begin
708             xpoint = wth + 10.0;
709
710             if (_pointer_type == MOVING) {
711                 draw_line(xpoint, ycent, xpoint, ypoint);
712                 draw_line(xpoint, ypoint, xpoint - 10.0, ypoint);
713                 draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint + 5.0);
714                 draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint - 5.0);
715             }
716             //end
717
718         } else {
719             //option_right
720             xstart = (x + w) / 2;
721
722             draw_line(xstart, ycentre, xstart + 5.0, ycentre); //centre tick
723
724             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
725
726             if (!option_notext())
727                 draw_text(w, ycentre, buf, 0);
728
729             for (i = 1; i < 5; i++) {
730                 yfirst += factor;
731                 ycentre += factor;
732                 draw_bullet(xstart + 2.5, yfirst, 3.0);
733                 draw_bullet(xstart + 2.5, ycentre, 3.0);
734             }
735
736             yfirst = _center_y - hgt;
737
738             for (i = 0; i <= incr; i++) {
739                 draw_line(xstart, yfirst, xstart + 5.0, yfirst);
740                 draw_line(xstart, ysecond, xstart + 5.0, ysecond);
741
742                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
743
744                 if (!option_notext())
745                     draw_text(w, yfirst, buf, 0);
746
747                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor()));
748
749                 if (!option_notext())
750                     draw_text(w, ysecond, buf, 0);
751
752                 yfirst -= factors;
753                 ysecond += factors;
754
755             }
756
757             // to draw moving type pointer for right option
758             //begin
759             xpoint = _x;
760
761             if (_pointer_type == MOVING) {
762                 draw_line(xpoint, ycent, xpoint, ypoint);
763                 draw_line(xpoint, ypoint, xpoint + 10.0, ypoint);
764                 draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint + 5.0);
765                 draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint - 5.0);
766             }
767             //end
768         }//end option_right /left
769         //end of vertical scale
770
771     } else {
772         //horizontal scale
773         x = _x;
774         y = _y;
775         w = _x + _w;
776         h = _y + _h;
777         bottom = _w;
778
779         float ystart, xfirst, xcentre, xsecond;
780
781         float hgt = bottom * 20.0 / 100.0;  // 60% of height should be zoomed
782         xfirst = _center_x - hgt;
783         xcentre = _center_x;
784         xsecond = _center_x + hgt;
785         float range = hgt * 2;
786
787         int i;
788         float factor = range / 10.0;
789
790         float hgt1 = bottom * 30.0 / 100.0;
791         int  incrs = int((_val_span - _major_divs * 2.0) / _major_divs);
792         int  incr = incrs / 2;
793         float factors = hgt1 / incr;
794
795
796         //Code for Moving Type Pointer
797         //begin
798         static float xcent, xpoint, ypoint;                             // FIXME really static?
799
800         xcent = _center_x;
801
802         if (cur_value <= data[centre + 1])
803             if (cur_value > data[centre]) {
804                 xpoint = xcent + ((cur_value - data[centre]) * hgt / _major_divs);
805             }
806
807         if (cur_value >= data[centre - 1])
808             if (cur_value <= data[centre]) {
809                 xpoint = xcent - ((data[centre] - cur_value) * hgt / _major_divs);
810             }
811
812         if (cur_value < data[centre - 1])
813             if (cur_value >= _input.min()) {
814                 float diff = _input.min() - data[centre - 1];
815                 float diff1 = cur_value - data[centre - 1];
816                 float val = (diff1 * hgt1) / diff;
817
818                 xpoint = xcent - hgt - val;
819             }
820
821
822         if (cur_value > data[centre + 1])
823             if (cur_value <= _input.max()) {
824                 float diff = _input.max() - data[centre + 1];
825                 float diff1 = cur_value - data[centre + 1];
826                 float val = (diff1 * hgt1) / diff;
827
828                 xpoint = xcent + hgt + val;
829             }
830
831         //end
832         if (option_top()) {
833             ystart = h;
834             draw_line(xcentre, ystart, xcentre, ystart - 5.0); //centre tick
835
836             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor()));  // was data_scaling() ... makes no sense at all
837
838             if (!option_notext())
839                 draw_text(xcentre - 10.0, y, buf, 0);
840
841             for (i = 1; i < 5; i++) {
842                 xfirst += factor;
843                 xcentre += factor;
844                 draw_bullet(xfirst, ystart - 2.5, 3.0);
845                 draw_bullet(xcentre, ystart - 2.5, 3.0);
846             }
847
848             xfirst = _center_x - hgt;
849
850             for (i = 0; i <= incr; i++) {
851                 draw_line(xfirst, ystart, xfirst,  ystart - 5.0);
852                 draw_line(xsecond, ystart, xsecond, ystart - 5.0);
853
854                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
855
856                 if (!option_notext())
857                     draw_text(xfirst - 10.0, y, buf, 0);
858
859                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
860
861                 if (!option_notext())
862                     draw_text(xsecond - 10.0, y, buf, 0);
863
864
865                 xfirst -= factors;
866                 xsecond += factors;
867             }
868             //this is for moving pointer for top option
869             //begin
870
871             ypoint = _y + _h + 10.0;
872
873             if (_pointer_type == MOVING) {
874                 draw_line(xcent, ypoint, xpoint, ypoint);
875                 draw_line(xpoint, ypoint, xpoint, ypoint - 10.0);
876                 draw_line(xpoint, ypoint - 10.0, xpoint + 5.0, ypoint - 5.0);
877                 draw_line(xpoint, ypoint - 10.0, xpoint - 5.0, ypoint - 5.0);
878             }
879             //end of top option
880
881         } else {
882             //else option_bottom
883             ystart = (y + h) / 2;
884
885             //draw_line(xstart, yfirst,  xstart - 5.0, yfirst);
886             draw_line(xcentre, ystart, xcentre, ystart + 5.0); //centre tick
887
888             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
889
890             if (!option_notext())
891                 draw_text(xcentre - 10.0, h, buf, 0);
892
893             for (i = 1; i < 5; i++) {
894                 xfirst += factor;
895                 xcentre += factor;
896                 draw_bullet(xfirst, ystart + 2.5, 3.0);
897                 draw_bullet(xcentre, ystart + 2.5, 3.0);
898             }
899
900             xfirst = _center_x - hgt;
901
902             for (i = 0; i <= incr; i++) {
903                 draw_line(xfirst, ystart, xfirst, ystart + 5.0);
904                 draw_line(xsecond, ystart, xsecond, ystart + 5.0);
905
906                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
907
908                 if (!option_notext())
909                     draw_text(xfirst - 10.0, h, buf, 0);
910
911                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
912
913                 if (!option_notext())
914                     draw_text(xsecond - 10.0, h, buf, 0);
915
916                 xfirst -= factors;
917                 xsecond   += factors;
918             }
919             //this is for movimg pointer for bottom option
920             //begin
921
922             ypoint = _y - 10.0;
923             if (_pointer_type == MOVING) {
924                 draw_line(xcent, ypoint, xpoint, ypoint);
925                 draw_line(xpoint, ypoint, xpoint, ypoint + 10.0);
926                 draw_line(xpoint, ypoint + 10.0, xpoint + 5.0, ypoint + 5.0);
927                 draw_line(xpoint, ypoint + 10.0, xpoint - 5.0, ypoint + 5.0);
928             }
929         }//end hud_top or hud_bottom
930     }  //end of horizontal/vertical scales
931 }//end draw
932
933