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