]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_tape.cxx
- more <tape> fixes
[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
52
53 void HUD::Tape::draw(void) //  (HUD_scale * pscale)
54 {
55     if (!_input.isValid())
56         return;
57
58     float vmin = 0.0, vmax = 0.0;
59     float marker_xs;
60     float marker_xe;
61     float marker_ys;
62     float marker_ye;
63     float text_x = 0.0, text_y = 0.0;
64     const int BUFSIZE = 80;
65     char buf[BUFSIZE];
66     int oddtype;
67 //    int k; //odd or even values for ticks             // FIXME odd scale
68
69     Point mid_scr = get_centroid();
70     float cur_value = _input.getFloatValue();
71
72     if (int(floor(_input.max() + 0.5)) & 1)
73         oddtype = 1; //draw ticks at odd values
74     else
75         oddtype = 0; //draw ticks at even values
76
77     float top = _y + _h;
78     float right = _x + _w;
79
80
81     if (_pointer) {
82         if (_pointer_type == MOVING) {
83             vmin = _input.min();
84             vmax = _input.max();
85
86         } else { // FIXED
87             vmin = cur_value - _half_width_units; // width units == needle travel
88             vmax = cur_value + _half_width_units; // or picture unit span.
89             text_x = mid_scr.x;
90             text_y = mid_scr.y;
91         }
92
93     } else {
94         vmin = cur_value - _half_width_units; // width units == needle travel
95         vmax = cur_value + _half_width_units; // or picture unit span.
96         text_x = mid_scr.x;
97         text_y = mid_scr.y;
98     }
99
100
101 ///////////////////////////////////////////////////////////////////////////////
102 // VERTICAL SCALE
103 ///////////////////////////////////////////////////////////////////////////////
104
105     // Draw the basic markings for the scale...
106
107     if (option_vert()) { // Vertical scale
108         // Bottom tick bar
109         if (_draw_tick_bottom)
110             draw_line(_x, _y, right, _y);
111
112         // Top tick bar
113         if (_draw_tick_top)
114             draw_line(_x, top, right, top);
115
116         marker_xs = _x;       // x start
117         marker_xe = right;    // x extent
118         marker_ye = top;
119
120         //    glBegin(GL_LINES);
121
122         // Bottom tick bar
123         //    glVertex2f(marker_xs, _y);
124         //    glVertex2f(marker_xe, _y);
125
126         // Top tick bar
127         //    glVertex2f(marker_xs, marker_ye);
128         //    glVertex2f(marker_xe, marker_ye);
129         //    glEnd();
130
131
132         // We do not use else in the following so that combining the
133         // two options produces a "caged" display with double
134         // carrots. The same is done for horizontal card indicators.
135
136         // begin vertical/left
137         //First draw capping lines and pointers
138         if (option_left()) {    // Calculate x marker offset
139
140             if (_draw_cap_right)
141                 draw_line(marker_xe, _y, marker_xe, marker_ye);
142
143             marker_xs = marker_xe - _w / 3.0;
144
145             // draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y + _w / 6);
146             // draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y - _w / 6);
147
148             // draw pointer
149             if (_pointer) {
150                 if (_pointer_type == MOVING) {
151                     if (!_zoom) {
152                         //Code for Moving Type Pointer
153                         float ycentre, ypoint, xpoint;
154                         float range, wth;
155
156                         if (_input.min() >= 0.0)
157                             ycentre = _y;
158                         else if (_input.max() + _input.min() == 0.0)
159                             ycentre = mid_scr.y;
160                         else if (oddtype)
161                             ycentre = _y + (1.0 - _input.min()) * _h
162                                     / (_input.max() - _input.min());
163                         else
164                             ycentre = _y + _input.min() * _h
165                                     / (_input.max() - _input.min());
166
167                         range = _h;
168                         wth = _x + _w;
169
170                         if (oddtype)
171                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
172                         else
173                             ypoint = ycentre + (cur_value * range / _val_span);
174
175                         xpoint = wth + _marker_offset;
176                         draw_line(xpoint, ycentre, xpoint, ypoint);
177                         draw_line(xpoint, ypoint, xpoint - _marker_offset, ypoint);
178                         draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint + 5.0);
179                         draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint - 5.0);
180                     } // !_zoom
181
182                 } else {
183                     // default to fixed
184                     fixed(_marker_offset + marker_xe, text_y + _w / 6,
185                             _marker_offset + marker_xs, text_y, _marker_offset + marker_xe,
186                             text_y - _w / 6);
187                 } // end pointer type
188             } // if pointer
189         } // end vertical/left
190
191
192         // begin vertical/right
193         // First draw capping lines and pointers
194         if (option_right()) {
195
196             if (_draw_cap_left)
197                 draw_line(_x, _y, _x, marker_ye);
198
199             marker_xe = _x + _w / 3.0;
200             // Indicator carrot
201             // draw_line(_x, mid_scr.y +  _w / 6, marker_xe, mid_scr.y);
202             // draw_line(_x, mid_scr.y -  _w / 6, marker_xe, mid_scr.y);
203
204             // draw pointer
205             if (_pointer) {
206                 if (_pointer_type == MOVING) {
207                     if (!_zoom) {
208                         // type-fixed & _zoom=1, behaviour to be defined
209                         // Code for Moving Type Pointer
210                         float ycentre, ypoint, xpoint;
211                         float range;
212
213                         if (_input.min() >= 0.0)
214                             ycentre = _y;
215                         else if (_input.max() + _input.min() == 0.0)
216                             ycentre = mid_scr.y;
217                         else if (oddtype)
218                             ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
219                         else
220                             ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
221
222                         range = _h;
223
224                         if (oddtype)
225                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
226                         else
227                             ypoint = ycentre + (cur_value * range / _val_span);
228
229                         xpoint = _x - _marker_offset;
230                         draw_line(xpoint, ycentre, xpoint, ypoint);
231                         draw_line(xpoint, ypoint, xpoint + _marker_offset, ypoint);
232                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint + 5.0);
233                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint - 5.0);
234                     }
235
236                 } else {
237                     // default to fixed
238                     fixed(-_marker_offset + _x, text_y +  _w / 6,
239                             -_marker_offset + marker_xe, text_y, -_marker_offset + _x,
240                             text_y - _w / 6);
241                 }
242             } // if pointer
243         } // end vertical/right
244
245
246         // At this point marker x_start and x_end values are transposed.
247         // To keep this from confusing things they are now swapped.
248         if (option_both())
249             marker_ye = marker_xs, marker_xs = marker_xe, marker_xe = marker_ye;
250
251
252
253         // Work through from bottom to top of scale. Calculating where to put
254         // minor and major ticks.
255
256         // draw scale or tape
257         if (_zoom) {
258             zoomed_scale((int)vmin, (int)vmax);
259         } else {
260
261             int div_ratio;
262             if (_minor_divs != 0.0f)
263                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
264             else
265                 div_ratio = 0, _minor_divs = _major_divs;               // FIXME move that into Scale/Constructor ?
266
267             float vstart = floorf(vmin / _major_divs) * _major_divs;
268             float min_diff = _w / 6.0;    // length difference between major & minor tick
269
270             // FIXME consider oddtype
271             for (int i = 0; ; i++) {
272                 float v = vstart + i * _minor_divs;
273
274                 if (!_modulo && (v < _input.min() || v > _input.max()))
275                     continue;
276
277                 float y = _y + (v - vmin) * factor();
278
279                 if (y < _y + 4)
280                     continue;
281                 if (y > top - 4)
282                     break;
283
284                 if (div_ratio && i % div_ratio) { // minor div
285                     if (option_both()) {
286                         if (_tick_type == LINE) {
287                             if (_tick_length == VARIABLE) {
288                                 draw_line(_x, y, marker_xs, y);
289                                 draw_line(marker_xe, y, right, y);
290                             } else {
291                                 draw_line(_x, y, marker_xs, y);
292                                 draw_line(marker_xe, y, right, y);
293                             }
294
295                         } else { // _tick_type == CIRCLE
296                             draw_bullet(_x, y, 3.0);
297                         }
298
299                         // glBegin(GL_LINES);
300                         // glVertex2f(_x, y);
301                         // glVertex2f(marker_xs,      y);
302                         // glVertex2f(marker_xe,      y);
303                         // glVertex2f(_x + _w,  y);
304                         // glEnd();
305                         // anything other than huds_both
306
307                     } else if (option_left()) {
308                         if (_tick_type == LINE) {
309                             if (_tick_length == VARIABLE) {
310                                 draw_line(marker_xs + min_diff, y, marker_xe, y);
311                             } else {
312                                 draw_line(marker_xs, y, marker_xe, y);
313                             }
314                         } else { // _tick_type == CIRCLE
315                             draw_bullet(marker_xs + 4, y, 3.0);
316                         }
317
318                     } else { // if (option_right())
319                         if (_tick_type == LINE) {
320                             if (_tick_length == VARIABLE) {
321                                 draw_line(marker_xs, y, marker_xe - min_diff, y);
322                             } else {
323                                 draw_line(marker_xs, y, marker_xe, y);
324                             }
325
326                         } else { // _tick_type == CIRCLE
327                             draw_bullet(marker_xe - 4, y, 3.0);
328                         }
329                     } // end huds both
330
331                 } else { // major div
332                     int display_value = int(v);
333                     if (_modulo)
334                         display_value %= _modulo;
335
336                     snprintf(buf, BUFSIZE, "%d", display_value);
337                     float strwd = text_width(buf);
338                     float strht = _hud->_font_size;
339
340                     if (option_both()) {
341                         // draw_line(_x, y, marker_xs, y);
342                         // draw_line(marker_xs, y, _x + _w, y);
343                         if (_tick_type == LINE) {
344                             glBegin(GL_LINE_STRIP);
345                             glVertex2f(_x, y);
346                             glVertex2f(marker_xs, y);
347                             glVertex2f(right, y);
348                             glEnd();
349
350                         } else { // _tick_type == CIRCLE
351                             draw_bullet(_x, y, 5.0);
352                         }
353
354                         if (!option_notext())
355                             draw_text(marker_xs + 2, y, buf, 0);
356
357                     } else {
358                         if (_tick_type == LINE)
359                             draw_line(marker_xs, y, marker_xe, y);
360                         else // _tick_type == CIRCLE
361                             draw_bullet(marker_xs + 4, y, 5.0);
362
363                         if (!option_notext()) {
364                             if (option_left())
365                                 draw_text(marker_xs - strwd, y - 4, buf, 0);
366                             else
367                                 draw_text(marker_xe + strwd / 2, y - 4, buf, 0);
368                         }
369                     } // End if huds-both
370                 }
371             }
372         } // end of zoom
373
374
375 ///////////////////////////////////////////////////////////////////////////////
376 // HORIZONTAL SCALE
377 ///////////////////////////////////////////////////////////////////////////////
378
379
380     } else {
381         // left tick bar
382         if (_draw_tick_left)
383             draw_line(_x, _y, _x, top);
384
385         // right tick bar
386         if (_draw_tick_right)
387             draw_line(right, _y, right, top);
388
389         marker_ys = _y;    // Starting point for
390         marker_ye = top;           // tick y location calcs
391         marker_xe = right;
392         marker_xs = _x + ((cur_value - vmin) * factor());
393
394         //    glBegin(GL_LINES);
395         // left tick bar
396         //    glVertex2f(_x, _y);
397         //    glVertex2f(_x, marker_ye);
398
399         // right tick bar
400         //    glVertex2f(marker_xe, _y);
401         //    glVertex2f(marker_xe, marker_ye);
402         //    glEnd();
403
404         if (option_top()) {
405             if (_draw_cap_bottom)
406                 draw_line(_x, _y, right, _y);
407
408             // Tick point adjust
409             marker_ye  = _y + _h / 2;
410             // Bottom arrow
411             // draw_line(mid_scr.x, marker_ye, mid_scr.x - _h / 4, _y);
412             // draw_line(mid_scr.x, marker_ye, mid_scr.x + _h / 4, _y);
413             // draw pointer
414             if (_pointer) {
415                 if (_pointer_type == MOVING) {
416                     if (!_zoom) {
417                         //Code for Moving Type Pointer
418
419                         float xcentre = mid_scr.x;
420                         float range = _w;
421                         float xpoint = xcentre + (cur_value * range / _val_span);
422                         float ypoint = _y - _marker_offset;
423                         draw_line(xcentre, ypoint, xpoint, ypoint);
424                         draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
425                         draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
426                         draw_line(xpoint, ypoint + _marker_offset, xpoint - 5.0, ypoint + 5.0);
427                     }
428
429                 } else {
430                     //default to fixed
431                     fixed(marker_xs - _h / 4, _y, marker_xs,
432                             marker_ye, marker_xs + _h / 4, _y);
433                 }
434             }
435         } // End Horizontal scale/top
436
437         if (option_bottom()) {
438             if (_draw_cap_top)
439                 draw_line(_x, top, right, top);
440
441             // Tick point adjust
442             marker_ys = top - _h / 2;
443             // Top arrow
444             // draw_line(mid_scr.x + _h / 4, _y + _h, mid_scr.x, marker_ys);
445             // draw_line(mid_scr.x - _h / 4, _y + _h, mid_scr.x , marker_ys);
446
447             // draw pointer
448             if (_pointer) {
449                 if (_pointer_type == MOVING) {
450                     if (!_zoom) {
451                         //Code for Moving Type Pointer
452
453                         float xcentre = mid_scr.x ;
454                         float range = _w;
455                         float hgt = _y + _h;
456                         float xpoint = xcentre + (cur_value * range / _val_span);
457                         float ypoint = hgt + _marker_offset;
458                         draw_line(xcentre, ypoint, xpoint, ypoint);
459                         draw_line(xpoint, ypoint, xpoint, ypoint - _marker_offset);
460                         draw_line(xpoint, ypoint - _marker_offset, xpoint + 5.0, ypoint - 5.0);
461                         draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
462                     }
463                 } else {
464                     fixed(marker_xs + _h / 4, top, marker_xs, marker_ys,
465                             marker_xs - _h / 4, top);
466                 }
467             }
468         } //end horizontal scale bottom
469
470
471         if (_zoom) {
472             zoomed_scale((int)vmin,(int)vmax);
473         } else {
474             int div_ratio;                                      // FIXME abstract that out of hor/vert
475             if (_minor_divs != 0.0f)
476                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
477             else
478                 div_ratio = 0, _minor_divs = _major_divs;                       // FIXME move that into Scale/Constructor ?
479
480             float vstart = floorf(vmin / _major_divs) * _major_divs;
481             float min_diff = _h / 6.0;    // length difference between major & minor tick
482
483             // FIXME consider oddtype
484             for (int i = 0; ; i++) {
485                 float v = vstart + i * _minor_divs;
486
487                 if (!_modulo && (v < _input.min() || v > _input.max()))
488                     continue;
489
490                 float x = _x + (v - vmin) * factor();
491
492                 if (x < _x + 4)
493                     continue;
494                 if (x > right - 4)
495                     break;
496
497                 if (div_ratio && i % div_ratio) { // minor div
498                     if (option_both()) {
499                         if (_tick_length == VARIABLE) {
500                             draw_line(x, _y, x, marker_ys - 4);
501                             draw_line(x, marker_ye + 4, x, top);
502                         } else {
503                             draw_line(x, _y, x, marker_ys);
504                             draw_line(x, marker_ye, x, top);
505                         }
506                         // glBegin(GL_LINES);
507                         // glVertex2f(x, _y);
508                         // glVertex2f(x, marker_ys - 4);
509                         // glVertex2f(x, marker_ye + 4);
510                         // glVertex2f(x, _y + _h);
511                         // glEnd();
512
513                     } else {
514                         if (option_top()) {
515                             // draw minor ticks
516                             if (_tick_length == VARIABLE)
517                                 draw_line(x, marker_ys, x, marker_ye - min_diff);
518                             else
519                                 draw_line(x, marker_ys, x, marker_ye);
520
521                         } else if (_tick_length == VARIABLE) {
522                             draw_line(x, marker_ys + 4, x, marker_ye);
523                         } else {
524                             draw_line(x, marker_ys, x, marker_ye);
525                         }
526                     }
527
528                 } else { // major divs
529                     int display_value = int(v);
530                     if (_modulo)
531                         display_value %= _modulo;
532
533                     snprintf(buf, BUFSIZE, "%d", display_value);
534                     float strwd = text_width(buf);
535                     float strht = _hud->_font_size;
536
537                     // Draw major ticks and text only if far enough from the edge.                      // FIXME
538                     if (x < _x + 10 || x + 10 > _x + _w)
539                         continue;
540
541                     if (option_both()) {
542                         // draw_line(x, _y,
543                         //              x, marker_ys);
544                         // draw_line(x, marker_ye,
545                         //              x, _y + _h);
546                         glBegin(GL_LINE_STRIP);
547                         glVertex2f(x, _y);
548                         glVertex2f(x, marker_ye);
549                         glVertex2f(x, top);
550                         glEnd();
551
552                         if (!option_notext())
553                             draw_text(x - strwd / 2.0, marker_ys + 4, buf, 0);
554
555                     } else {
556                         draw_line(x, marker_ys, x, marker_ye);
557
558                         if (!option_notext()) {
559                             if (option_top())
560                                 draw_text(x - strwd / 2.0, top - 10, buf, 0);
561                             else
562                                 draw_text(x - strwd / 2.0, _y, buf, 0);
563                         }
564                     }
565                 }
566             } // end for
567         } // end zoom
568     } // end horizontal/vertical scale
569 }
570
571
572
573 void HUD::Tape::fixed(float x1, float y1, float x2, float y2, float x3, float y3)
574 {
575     glBegin(GL_LINE_STRIP);
576     glVertex2f(x1, y1);
577     glVertex2f(x2, y2);
578     glVertex2f(x3, y3);
579     glEnd();
580 }
581
582
583 void HUD::Tape::zoomed_scale(int first, int last)
584 {
585     Point mid_scr = get_centroid();
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 = mid_scr.y - hgt;
614         ycentre = mid_scr.y;
615         ysecond = mid_scr.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 = mid_scr.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 = mid_scr.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 = mid_scr.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 = mid_scr.x - hgt;
777         xcentre = mid_scr.x;
778         xsecond = mid_scr.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 = mid_scr.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 = mid_scr.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 = mid_scr.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