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